In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to run custom move modules in Libra. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Brief introduction
Because both Libra and Move are in the process of continuous development, at the time of publication of this article, custom Move modules cannot be released on testnet, but only in the local environment. Let's take a look at how to run a custom Move program on the local network.
Create Move modules
Here, we create a very simple module called MyModule.
The module has a single process called id, which is a constant process of manipulating coin. It enters the LibraCoin.T resource and returns it to the caller. The Move IR code for this module is provided below and saved in a file called my_module.mvir.
Module MyModule {import 0x0.LibraCoin; / / The identity function for coins: takes a LibraCoin.T as input and hands it back public id (c: LibraCoin.T): LibraCoin.T {return move (c);}} start the local network
Starting the local network is easy and requires the libra_swarm package under the libra repository. The startup command is as follows:
$cd libra$ cargo run-p libra_swarm-s
The above command creates a Libra blockchain of the local network (the generation node's creation transaction, initial key and bootstrap configuration) and starts a local authentication node.
Finally, it starts a Libra cli client, as follows:
Usage: Use the following commands:account | aAccount operationsquery | qQuery operationstransfer | transferb | t | tb | | [gas_unit_price_in_micro_libras (default=0)] [max_gas_amount_in_micro_libras (default 100000)] Suffix 'b' is for blocking.Transfer coins (in libra) from account to another.devLocal Move developmenthelp | hPrints this helpquit | Qothers exit this clientPlease, input commands:libra%
Then we can interact with libra from the command line.
Create an account and send test coins
In the previous article, we also talked about how to create an account. Here are the commands:
Libra% account create > > Creating/retrieving next account from walletCreated/retrieved account # 0 address 810abcc08dbed34ea15d7eb261b8001da6a62d72acdbf87714dd243a175f9b62libra% account mintb 0100 > > Minting coinswaiting.... transaction is storedfinished minting!
We created 100 coins for account 0.
Compile Move Module
We have saved the edited Move module program as my_module.mvir above, and we need to compile it:
Libra% dev compile 0 module
0 means that the module will be published under the 0 account.
Module indicates that you are compiling a Move module program. If you are compiling the transaction script, replace it with script.
After successfully compiling the module, you will see the following message in the output containing the path to compile the bytecode file generated by my_module.mvir.
Successfully compiled a program at / var/folders/tq/8gxrrmhx16376zxd5r4h9hhn_x1zq3/T/.tmpigAZCx publishes compiled Module
Use dev publish to publish the compiled Module from the previous step:
Libra% dev publish 0 / var/folders/tq/8gxrrmhx16376zxd5r4h9hhn_x1zq3/T/.tmpigAZCxwaiting .transaction is stored!no events emitted.Successfully published module
After the successful execution of the dev publish command, the bytecode of MyModule will be published under the sender's account. To use the procedures and types declared in MyModule, other transaction scripts and modules can import them using import. MyModule.
Subsequent modules released below must not be named MyModule. Each account can have at most one module with a given name. An attempt to distribute a second module named MyModule will cause the transaction to fail.
Create a deal script
We write the following transaction script and save it as custom_script.mvir.
Import 0x0.LibraAccountShield import 0x0.LibraCoinopportunity import {{sender}} .MyModule; main (amount: U64) {let coin: LibraCoin.T; coin = LibraAccount.withdraw_from_sender (move (amount)); / / calls the id procedure defined in our custom module LibraAccount.deposit (get_txn_sender (), MyModule.id (move (coin); return;}
This script simply calls the id procedure of MyModule.
In this script, {{sender}} is automatically replaced with the sender account address when the script is executed. Alternatively, you can import the fully qualified address:
Import 0x810abcc08dbed34ea15d7eb261b8001da6a62d72acdbf87714dd243a175f9b62.MyModule; compile script
Also use dev compile to compile:
Libra% dev compile 0 script
The results are as follows:
Successfully compiled a program at / var/folders/tq/8gxrrmhx16376zxd5r4h9hhn_x1zq3/T/.tmpDZhL21 execute script
Use the dev execute command to execute the script.
Libra% dev execute 0 / var/folders/tq/8gxrrmhx16376zxd5r4h9hhn_x1zq3/T/.tmpDZhL21 10waiting .transaction is stored!Successfully finished execution
0 is the sender's account index.
/ var/folders/tq/8gxrrmhx16376zxd5r4h9hhn_x1zq3/T/.tmpDZhL21 is the compiled script address above.
10 is the number of coins to be called.
Such a custom Move module is completed and successfully called.
This is the end of this article on "how to run custom move modules in Libra". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.