MoveVM

Overview

Initia's MoveVM serves as an innovative bridge, seamlessly integrating the Move Runtime with the CosmosSDK. This integration is achieved through a method inspired by CosmWasm's WasmVM, facilitating a connection between the MoveVM runtime, developed in Rust, and the Cosmos chain, implemented in Go. This approach extends beyond mere connectivity; it harmonizes the token standards within the platform by adapting the CosmosSDK's bank module to exclusively utilize the Move coin standard. Furthermore, to ensure Move users can fully leverage Cosmos' native staking capabilities, a Liquid Staking Module has been introduced. This feature allows for the utilization of Cosmos Staking features within the Move ecosystem. Additionally, Initia supports various CosmosSDK messages within Move, enhancing the functionality and interoperability of applications built on this platform.

Supported Cosmos Messages

Module
Msg

Staking

delegate

Distribution

fund_community_pool

IBC

transfer

IBC

nft_transfer

IBC

pay_fee

OPinit

initiate_token_bridge

Interact with CLI

This tutorial walks you through the process of interacting with the command-line interface (CLI) for initiad and minitiad, demonstrating how to build a Move module, deploy a Move package, and execute entry and view functions on the Initia network.

Building Move

The initia CLI can be used to build a Move package. To build a Move package, managed_coin for example, use the command below.

$ initiad move build --path ./move/managed_coin --dev

Unit Test

To run a unit test locally, use the following command.

$ initiad move test --path ./move/managed_coin --dev

This is an example response:

INCLUDING DEPENDENCY InitiaStdlib
INCLUDING DEPENDENCY MoveNursery
INCLUDING DEPENDENCY MoveStdlib
BUILDING basic_coin
Running Move unit tests
[ PASS    ] 0x2::managed_coin::test_create_and_mint
Test result: OK. Total tests: 1; passed: 1; failed: 0

Test Coverage

To generate a test coverage report, run the following command.

$ initiad move test --path ./move/managed_coin --dev --coverage

The output contains the result for each test case followed by a basic coverage summary:

INCLUDING DEPENDENCY InitiaStdlib
INCLUDING DEPENDENCY MoveNursery
INCLUDING DEPENDENCY MoveStdlib
BUILDING basic_coin
Running Move unit tests
[ PASS    ] 0x2::managed_coin::test_create_and_mint
Test result: OK. Total tests: 1; passed: 1; failed: 0
+-------------------------+
| Move Coverage Summary   |
+-------------------------+
Module 0000000000000000000000000000000000000000000000000000000000000002::managed_coin
>>> % Module coverage: 100.00
+-------------------------+
| % Move Coverage: 100.00  |
+-------------------------+
Please use `initiad move coverage -h` for more detailed source or bytecode test coverage of this package

Deploying a Move Package

To deploy a Move package to the network, follow these steps:

  1. Create an Account:

    • Use initiad keys add acc0 to create a new account.

    • Parse the created account address: initiad keys parse $(initiad keys show acc0 --address).

    • Update your_address in ./move/managed_coin/Move.toml to the 0x address of the created account.

    • Obtain tokens from the Initia faucet: https://faucet.initia.tech/.

    • A Full tutorial on creating an account can be found here.

  2. Deploy the Package: Run the deployment command, replacing placeholders with actual values:

$ initiad move deploy \
    --path ./move/managed_coin \
    --from acc0 \
    --gas-prices 0.15uinit \
    --gas auto \
    --gas-adjustment 1.4 \
    --node ${RPC_ADDR} \
    --chain-id ${CHAIN_ID}

Executing a View Function

For example, to retrieve and query coin metadata and balance:

  1. Retrieve Metadata Address

initiad q move execute 0x1 coin metadata \
    --args "address:$(initiad keys show acc0 --address) string:BASIC" \
    --node ${RPC_URL}
# record METADATA=0x~~~
  1. Query Minted Coin Balance

initiad q move execute 0x1 coin balance \
    --args "address:$(initiad keys show node0 --address) address:${METADATA}" \
    --node ${RPC_URL}

Executing an Entry Function

For example, to mint managed_coin to the acc0 account, execute the following command, replacing ${RPC_URL} and ${CHAIN_ID} with your specific values:

$ initiad tx move execute \
    $(initiad keys show acc0 --address) managed_coin mint_to \
    --args "u64:100 address:$(initiad keys show acc0 --address)" \
    --from acc0 \
    --gas auto \
    --gas-adjustment 1.4 \
    --gas-prices 0.15uinit \
    --node ${RPC_URL} \
    --chain-id ${CHAIN_ID}

Conclusion

This tutorial offers a concise overview of essential operations you can perform using the Initia CLI tools, providing a solid foundation for developing and deploying smart contracts and applications on the Initia network.

To learn examples of Move Modules, please visit the Move Module tutorials we have provided.

Last updated

Logo

© 2024 Initia Foundation, All rights reserved.