Skip to main content

Module 0x2::sui

Coin is the token used to pay for gas in Sui. It has 9 decimals, and the smallest unit (10^-9) is called "mist".

use 0x2::balance;
use 0x2::coin;
use 0x2::tx_context;

Struct SUI

Name of the coin

struct SUI has drop
Click to open
Fields
dummy_field: bool

Constants

Sender is not @0x0 the system address.

const ENotSystemAddress: u64 = 1;

const EAlreadyMinted: u64 = 0;

The amount of Mist per Sui token based on the fact that mist is 10^-9 of a Sui token

const MIST_PER_SUI: u64 = 1000000000;

The total supply of Sui denominated in Mist (10 Billion * 10^9)

const TOTAL_SUPPLY_MIST: u64 = 10000000000000000000;

The total supply of Sui denominated in whole Sui tokens (10 Billion)

const TOTAL_SUPPLY_SUI: u64 = 10000000000;

Function new

Register the SUI Coin to acquire its Supply. This should be called only once during genesis creation.

fun new(ctx: &mut tx_context::TxContext): balance::Balance<sui::SUI>
Click to open
Implementation
fun new(ctx: &mut TxContext): Balance<SUI> {
    assert!(ctx.sender() == @0x0, ENotSystemAddress);
    assert!(ctx.epoch() == 0, EAlreadyMinted);

    let (treasury, metadata) = coin::create_currency(
        SUI {},
        9,
        b"SUI",
        b"Sui",
        // TODO: add appropriate description and logo url
        b"",
        option::none(),
        ctx,
    );
    transfer::public_freeze_object(metadata);
    let mut supply = treasury.treasury_into_supply();
    let total_sui = supply.increase_supply(TOTAL_SUPPLY_MIST);
    supply.destroy_supply();
    total_sui
}

Function transfer

public entry fun transfer(c: coin::Coin<sui::SUI>, recipient: address)
Click to open
Implementation
public entry fun transfer(c: coin::Coin<SUI>, recipient: address) {
    transfer::public_transfer(c, recipient)
}