What you’ll build
You’ll create a simple smart contract that manages magical swords - demonstrating core Move concepts like:- Defining structs with abilities
- Working with objects and UIDs
- Implementing module initializers
- Creating and transferring objects
- Writing unit tests
Create a new Move package
Initialize the package
Create a
Move.toml manifest file:Move.toml
For local development, you can use a local path:
Write your first Move module
Create a filesources/sword.move:
sources/sword.move
Build your package
Build the package
Compile your Move code:If successful, you’ll see:The compiled bytecode is saved in the
build/ directory.Test your package
Add tests to verify your code works correctly. Create tests in the same file:sources/sword.move
Deploy your package
Publish the package
Deploy your package to the IOTA blockchain:The output includes:
- Package ID: Your published package’s unique identifier
- Transaction digest: The transaction hash
- Gas cost: Amount of gas consumed
- Created objects: Objects created during deployment
Interact with your deployed package
Now you can call functions from your published package:Understanding the deployment
When you publish a package:- Module initializer runs: The
initfunction executes automatically - Objects are created: The
Forgeobject is created and transferred to you - Package is immutable: Once published, the code cannot be changed
- Address is assigned: Your package gets a permanent on-chain address
Next steps
Testing and debugging
Learn advanced testing techniques and debugging strategies
IOTA Move framework
Explore the built-in IOTA framework modules
Common issues
Build fails with “Unable to resolve packages”
Check yourMove.toml dependencies. Ensure:
- Git URLs are correct
- Local paths exist
- Network connection is available
”Insufficient gas” error
Increase the gas budget:Module init function errors
Theinit function must:
- Be named exactly
init - Have
funvisibility (notpublic fun) - Take
&mut TxContextor&TxContextas the last parameter