Aptos Coin
Coin provides a standard, typesafe framework for simple, fungible tokens or coins.
Structures
A coin is defined in Move as:
A Coin uses the CoinType
to support re-usability of the Coin framework for distinct Coins. For example, Coin<A>
and Coin<B>
are two distinct coins.
Coin also supports a resource for storing coins in global store:
Coin information or metadata is stored in global store under the coin creators account:
Creating a new CoinType
A coin creator can publish to an on-chain account a new module that defines a struct to represent a new CoinType
. The coin creator will then call coin:initialize<CoinType>
from that account to register this as a valid coin, and in return receive back structs that enable calling the functions to burn and mint coins and freeze CoinStore
s. These will need to be stored in global storage by the creator to manage the use of the coin.
The first three of the above (
name
,symbol
,decimals
) are purely metadata and have no impact for on-chain applications. Some applications may use decimal to equate a single Coin from fractional coin.Monitoring supply (
monitor_supply
) helps track total coins in supply. However, due to the way the parallel executor works, turning on this option will prevent any parallel execution of mint and burn. If the coin will be regularly minted or burned, consider disablingmonitor_supply
.
Minting Coins
If the creator or manager would like to mint coins, they must retrieve a reference to their MintCapability
, which was produced in the initialize
, and call:
This will produce a new Coin struct containing a value as dictated by the amount
. If supply is tracked, then it will also be adjusted.
Burning Coins
If the creator or manager would like to burn coins, they must retrieve a reference to their BurnCapability
, which was produced in the initialize
, and call:
The creator or manager can also burn coins from a CoinStore
:
Freezing Accounts
If the creator or manager would like to freeze a CoinStore
on a specific account, they must retrieve a reference to their FreezeCapability
, which was produced in initialize
, and call:
Merging Coins
Two coins of the same type can be merged into a single Coin struct that represents the accumulated value of the two coins independently by calling:
Extracting Coins
A Coin can have value deducted to create another Coin by calling:
Withdrawing Coins from CoinStore
A holder of a CoinStore
can extract a Coin of a specified value by calling:
Depositing Coins into CoinStore
Any entity can deposit coins into an account’s CoinStore
by calling:
Transferring Coins
A holder of a CoinStore
can directly transfer coins from their account to another account’s CoinStore
by calling:
Events
Last updated