Deploying Move Modules

Overview

This tutorial will guide you through the process of building, publishing, and interacting with your own Move modules on the Initia blockchain. Specifically, we'll work with the read_write module from the initia-tutorials repository. Here's how to get started:

Tutorial

Step 1: Clone initia-tutorials

First, clone the initia-tutorials repository, which contains the read_write module we'll be using.

git clone git@github.com:initia-labs/initia-tutorials.git

Step 2: Build a Module

Before building the module, you need to update the module owner's address to your own address in the Move.toml configuration file located in ./initia-tutorials/move/read_write.

How to Get Your HEX Address:

Use the following command to parse your Initia address into bytes format, which is your HEX address.

> initiad keys parse [addr]

example output:

bytes: F64D24B10B0CE93CD428DF3AB9228ADB18B93CFE
human: init

Now, modify the Move.toml file to include your HEX address:

[package]
name = "read_write"
version = "0.0.0"

[dependencies]
InitiaStdlib = { git = "https://github.com/initia-labs/movevm.git", subdir = "precompile/modules/initia_stdlib", rev = "main" }

[addresses]
std =  "0x1"
your_address = "{insert your hex address here}"

Build the module using either CLI or builder.js:

> initiad move build --path ./initia-tutorials/move/read_write

Step 3: Publish a Module

After building your module, the next step is to publish it to the Initia blockchain.

>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 the upgrade policy:

PolicyDescription

COMPATIBLE

Performs a compatibility check during upgrades, ensuring no public function changes or resource layout modifications.

IMMUTABLE

Marks the modules as immutable, preventing any future upgrades.

Step 4: Interact with Your Published Module

After publishing, you can interact with your module through various Move scripts or direct calls from client applications.

> 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

Logo

© 2024 Initia Foundation, All rights reserved.