Before starting, ensure you have set up your development environment, created an account, and funded it with testnet tokens. Follow the Setting Up Your Development Environment guide if you haven’t completed these prerequisites.
Overview
In this tutorial, you’ll learn to:- Create a new Move project and module structure
- Compile Move source code into bytecode
- Deploy your module to the blockchain
- Interact with your deployed module through transactions and queries
This guide supports both Initia L1 and Move rollup development. Code examples are provided for CLI tools and InitiaJS SDK to accommodate different development preferences.
What You’ll Build
You’ll create a simple message storage module with two functions:save_message
: Store a string message in the user’s accountview_message
: Retrieve the stored message from an account
1
Set Up Environment Variables
Configure your development environment with the necessary network parameters.
Network Parameters Reference
Variable | Description |
---|---|
RPC_URL | The RPC endpoint for blockchain interaction and transaction broadcasting |
CHAIN_ID | Unique identifier for the specific blockchain network you’re targeting |
GAS_PRICES | Transaction fee rates in {amount}{denomination} format |
Find network-specific values in our Networks Documentation for Initia L1, or the Initia Registry for Move rollups.
2
Create Your Project Structure
Start by creating a new directory and initializing it as a Move project.
Create Project Directory
Initialize Move Package
Initialize your directory as a Move package, which creates the necessary project structure.Understanding the Project Structure
Your project now contains these essential components:Move.toml - Package Manifest
Move.toml - Package Manifest
The
Move.toml
file serves as your package’s configuration center, containing:- Package metadata: name, version, and description
- Dependencies: external packages your project requires
- Address mappings: logical names mapped to blockchain addresses
- Build settings: compilation options and flags
sources/ - Source Code Directory
sources/ - Source Code Directory
The
sources
directory is where you’ll write your Move smart contracts:- Contains all
.move
source files - Organizes your module implementations
- Houses the core business logic of your application
3
Write Your Move Module
Create your first Move module with message storage functionality.
Declares a module named
Defines a
Entry functions can be called directly via transactions. The
View functions are read-only operations marked with
Create the Module File
Create a new file calledhello_world.move
in the sources
directory:hello_world.move
Understanding the Code
Module Declaration
Module Declaration
hello_world
under the hello
address namespace. This establishes the module’s identity on the blockchain.Resource Structure
Resource Structure
Message
resource with the key
ability, allowing it to be stored in account storage. Resources are Move’s way of representing owned data.Entry Function
Entry Function
&signer
parameter represents the transaction sender’s authority.View Function
View Function
#[view]
. The acquires
clause indicates this function accesses the Message
resource.4
Configure and Compile Your Module
Set up your module’s deployment address and compile the source code.Expected output:Successful compilation output:
Get Your Deployment Address
First, retrieve your account’s hexadecimal address for the Move.toml configuration:Configure Move.toml
Update yourMove.toml
file with the deployment address and dependencies:Move.toml
Address Configuration
Ensure you add the “0x” prefix to your address and replace the example address with your actual deployment address. This determines where your module will be deployed on the blockchain.
Compile Your Module
Build your Move module into deployable bytecode:Verify Build Output
After compilation, you’ll find a newbuild/
directory containing:- Compiled bytecode modules
- Dependency information
- Build artifacts and metadata
5
Deploy Your Module
Deploy your compiled module to the blockchain network.
Understanding Deployment Options
Upgrade Policies
Upgrade Policies
The
--upgrade-policy
flag controls future module updates:COMPATIBLE
: Allows backward-compatible upgrades that don’t break existing functionalityIMMUTABLE
: Prevents any future modifications to the deployed module
Gas Configuration
Gas Configuration
Gas settings control transaction costs:
--gas auto
: Automatically estimates required gas--gas-adjustment 1.5
: Adds 50% buffer to gas estimate--gas-prices
: Sets the price per unit of gas
Successful Deployment
Once deployed successfully, your module will be stored at the address specified in your
Move.toml
file and can be interacted with by any user on the network.6
Interact with Your Deployed Module
Test your module by executing transactions and querying stored data.
Execute Transactions
Call your module’ssave_message
function to store data on-chain:Query Stored Data
Retrieve the message you just saved using theview_message
function:Expected Results
If both operations succeed, your query should return:Success! You’ve successfully created, deployed, and interacted with your first Move module. The message is now permanently stored on the blockchain and can be retrieved by anyone.