SUI Coin Deployment
Introduction
This tutorial shows how to deploy your own coin.
Please refer to here to get started.
Create Template
Create a simple example contract code written in Move.
You can create a sample contract my_coin
by selecting the template option
and clicking the Create Template
button.
Source Code
Note that init
function is executed only once during deployment.
module coin_sample::mycoin {
use std::option;
use sui::coin::{Self, Coin, TreasuryCap};
use sui::transfer;
use sui::tx_context::{Self, TxContext};
struct MYCOIN has drop {}
fun init(witness: MYCOIN, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<MYCOIN>(
witness,
2, // decimals
b"MC", // symbol
b"MYCOIN", // name
b"my coin", // description
option::none(),
ctx
);
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury_cap, tx_context::sender(ctx))
}
public entry fun mint(
treasury_cap: &mut TreasuryCap<MYCOIN>, amount:u64, recipient: address, ctx: &mut TxContext
) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx)
}
public entry fun burn(treasury_cap: &mut TreasuryCap<MYCOIN>, coin: Coin<MYCOIN>) {
coin::burn(treasury_cap, coin);
}
}
[package]
name = "CoinSample"
version = "0.0.1"
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir="crates/sui-framework/packages/sui-framework/", rev = "testnet" }
[addresses]
coin_sample = "0x0"
Compile The Source Code
Select the project you want to compile. For now, let's choose sui/my_coin
and click Compile
button.
Deployment
If the compilation succeed, you can see mv file mycoin.mv
.
Click the Deploy
button.
and you can see wallet popup. Let's click Send
button.
Check Out Deployed Contract
After deployment, you can see mycoin module and functions.
Calling Contract Functions
Select
mint
function. First parameter is TreasuryCap object id. You can get the object id in the terminal log which shows for above deployment transaction result. Second parameter is the amount of the minting coin. Third parameter is the receiver of the minting coin. For now, set the receiver to your account address.After mint transaction, check if MYCOIN was minted in SUI Explorer.
Try more...
- Call
burn
function and check it out in SUI Explorer. - Read about One Time Witness (OTW).
Reference
https://examples.sui.io/basics/one-time-witness.html https://github.com/MystenLabs/sui/tree/main/sui_programmability/examples/fungible_tokens