Skip to main content

Overview

Basics

Token reuses the TreasuryCap defined in the sui::coin module and therefore has the same initialization process. The coin::create_currency method guarantees the uniqueness of the TreasuryCap and forces the creation of a CoinMetadata object.

Minting and burning are performed using the Coin-like methods. Both require the TreasuryCap:

  • token::mint - mint a Token
  • token::burn - burn a Token

See Create a Coin guide for more details on how to create a Coin.

Public Actions

Token has a set of public and protected actions which can be used to manage the token. Public actions are available to everyone and don't require any authorization. They have similar APIs to Coin's but operate on the Token type:

  • token::keep - send a Token to the transaction sender
  • token::join - join two Tokens
  • token::split - split a Token into two, specify the amount to split
  • token::zero - create an empty (zero balance) Token
  • token::destroy_zero - destroy a Token with zero balance

See Coin Token Comparison for Coin and Token methods comparison.

Protected Actions

Protected actions are ones that issue an ActionRequest - a hot-potato struct which must be resolved for the transaction to succeed. There're 3 main ways to resolve an ActionRequest, most common of which is via the TokenPolicy.

  • token::transfer - transfer a Token to a specified address
  • token::to_coin - convert a Token to a Coin
  • token::from_coin - convert a Coin to a Token
  • token::spend - spend a Token on a specified address

The methods above are included in the base implementation, however it is possible to create ActionRequest`s for custom actions.

Token Policy & Rules

Protected actions are disabled by default and can be enabled in a TokenPolicy. Additionally, the token owner can set custom restrictions called Rules which must be satisfied for a specific action to succeed.