4. Create your own Move coin

This tutorial covers how to make my own coin and mint them using 0x1::managed_coin module, and how to interact with the Move module.

Step 1: Initialize Coin

Call 0x1::managed_coin::initialize function and start creating a new coin on Initia.

public entry fun initialize(
    account: &signer,
    maximum_supply: Option<u128>,
    name: String,
    symbol: String,
    decimals: u8,
    icon_uri: String,
    project_uri: String,
)

TIP: On the entry function, signer is included in msg sender and is omitted on msg args.

> initiad tx move execute 0x1 managed_coin initialize \
  --args "option<u128>:null string:my_coin string:MYCOIN u8:6 string: string:" \
  --from [key-name] \
  --gas auto --gas-adjustment 1.5 --gas-prices 0.15uinit \
  --node [rpc-url]:[rpc-port] --chain-id [chain-id]

Step 2: Mint Coin

Call 0x1::managed_coin::mint function and mint the tokens create on Step 1.

public entry fun mint(
    account: &signer,
    dst_addr: address,
    metadata: Object<Metadata>,
    amount: u64,
)

What is metadata?

Metadata is the coins unique identity. To be more specific, it is an object or an address where 0x1::fungible_asset::Metadata is saved. Fungible asset is using named object to generate deterministic address which is the form of sha3_256(creator+symbol+0xFE).

How do I get metadata?

A view function 0x1::coin::metadata can be used to get metadata of a coin. You can also get the metadata by using sha3_256(creator+symbol+0xFE).

> initiad query move view 0x1 coin metadata \
    --args "address:[addr] string:MYCOIN" \
    --node [rpc-url]:[rpc-port]

data: '"0x2d81ce0b6708fccc77a537d3d1abac8c9f1f674f4f76390e3e78a89a52d4aacb"'

Now that we know the metadata address, let's mint coins.

> initiad tx move execute 0x1 managed_coin mint \
  --args "address:[addr] object:0x2d81ce0b6708fccc77a537d3d1abac8c9f1f674f4f76390e3e78a89a52d4aacb u64:100000000" \
  --from [key-name] \
  --gas auto --gas-adjustment 1.5 --gas-prices 0.15uinit \
  --node [rpc-url]:[rpc-port] --chain-id [chain-id]

Check the minted coins by querying the balances.

initiad query bank balances [addr] \
    --node [rpc-url]:[rpc-port]
balances:
- amount: "100000000"
  denom: move/2d81ce0b6708fccc77a537d3d1abac8c9f1f674f4f76390e3e78a89a52d4aacb
- amount: "99482105"
  denom: uinit
pagination:
  next_key: null
  total: "0"

TIP: If creator is 0x1, cosmos denom is equal to the symbol. If not, cosmos denom is equal to move/{metadata_address}

Last updated