An introductory Sui Move module that defines a simple Hero object and two entry functions to create and transfer it. Several TODOs are left in the code for learning purposes.
- Module:
module_2::hero - Structs:
- Hero: key object to be completed with fields like
id,name,power, andimage_url.
- Hero: key object to be completed with fields like
- Entry functions:
create_hero(name: String, image_url: String, power: u64, ctx: &mut TxContext)— create aHeroand transfer it to the sender.transfer_hero(hero: Hero, to: address)— transfer aHeroto another address.
From the repository root:
sui move build
sui move testFrom the repository root, publish just this package:
sui client publish Save the returned packageId for subsequent calls.
Replace placeholders like <PACKAGE_ID>, <HERO_ID>, and <RECIPIENT_ADDRESS> with real values.
- Create a hero
sui client call \
--package <PACKAGE_ID> \
--module hero \
--function create_hero \
--args "Arthur" "https://example.com/arthur.png" 9000 \
--gas-budget 100000000- Transfer a hero
sui client call \
--package <PACKAGE_ID> \
--module hero \
--function transfer_hero \
--args <HERO_ID> <RECIPIENT_ADDRESS> \
--gas-budget 50000000- Hero:
- Add
id: UID,name: String,power: u64,image_url: String. - In
create_hero, construct theHerousingobject::new(ctx)for theid. - Transfer to sender using
transfer::transfer(hero, ctx.sender()).
- Add
- transfer_hero:
- Use
transfer::public_transfer(hero, to).
- Use
- Make sure Sui CLI is configured and you have gas on the selected network.
- If you see type or module import errors, ensure you’re on a recent Sui CLI.