Move Module
This tutorial covers building, publishing and interacting with my own Move modules.
Step 0: clone initia-tutorials
In this tutorial we will use read_write
module of initia-tutorials
repository.
git clone git@github.com:initia-labs/initia-tutorials.git
Step 1: Build a module
Before building a module, module owner address must be modified to your own address. Open ./initia-tutorials/move/read_write/Move.toml
and modify your_address
. your_address
must be a hex address.
How to get HEX address
> initiad keys parse [addr]
bytes: F64D24B10B0CE93CD428DF3AB9228ADB18B93CFE
human: init
[package]
name = "read_write"
version = "0.0.0"
[dependencies]
InitiaStdlib = { git = "https://github.com/initia-labs/initiavm.git", subdir = "crates/../precompile/modules/initia_stdlib", rev = "main" }
[addresses]
std = "0x1"
your_address = "{insert your hex address here}"
And build module with the CLI or builder.js
> initiad move build --path ./initia-tutorials/move/read_write
Step 2: Publish a module
Let's publish read_write.mv
module create in the previous step.
>initiad move deploy \
--path ./initia-tutorials/move/read_write \
--upgrade-policy COMPATIBLE \
--from test-account \
--gas auto --gas-adjustment 1.5 \
--gas-prices 0.15uinit \
--node [rpc-url]:[rpc-port] \
--chain-id [chain-id]
About upgrade policy
ARBITRARY
Whether unconditional code upgrade with no compatibility check is allowed. This publication mode should only be used for modules which aren't shared with user others. The developer is responsible for not breaking memory layout of any resources he already stored on chain.
COMPATIBLE
Whether a compatibility check should be performed for upgrades. The check only passes if a new module has (a) the same public functions (b) for existing resources, no layout change.
IMMUTABLE
Whether the modules in the package are immutable and cannot be upgraded.
Step 3: Interact with published module
Let's interact with the published module.
> initiad query move view [addr] read_write read \
--node [rpc-url]:[rpc-port]
data: '"initial content"'
> initiad tx move execute [addr] read_write write \
--args "string:new_string" \
--from [key-name] \
--gas auto --gas-adjustment 1.5 --gas-prices 0.15uinit \
--node [rpc-url]:[rpc-port] --chain-id [chain-id]
> initiad query move view [addr] read_write read \
--node [rpc-url]:[rpc-port]
data: '"new_string"'
Last updated