Fixed Supply
A fixed-supply coin has a predetermined total supply that cannot increase after creation. No additional tokens can ever be minted because the minting capability (TreasuryCap) is locked or destroyed during initialization. Fixed supply is common for governance tokens, utility tokens, and any asset where scarcity is a design requirement.
This pattern involves 3 steps during the module's init function:
- Create the currency: Call
coin::create_currencywith a One-Time Witness to create theTreasuryCapandCoinMetadata. Thecreate_currencyfunction takes parameters for the coin's decimals, symbol, name, description, and icon URL. - Mint the total supply: Call
coin::mintwith theTreasuryCapto create all tokens at once. The amount is specified in the smallest unit (base units). For example, if your coin has 9 decimals, a supply of10_000_000_000_000_000_000represents 10 billion coins. - Lock the
TreasuryCap: Store theTreasuryCapas a dynamic object field on a permanent object. This prevents anyone from callingcoin::mintagain because theTreasuryCapis no longer directly accessible. You can also freeze or destroy theTreasuryCapdepending on your requirements.
I2/fixed_supply/sources/silver.move. You probably need to run `pnpm prebuild` and restart the site.Why lock the TreasuryCap
The TreasuryCap is the capability that authorizes minting and burning. If you transfer it to the deployer's address instead of locking it, anyone who gains access to that address (through key compromise or social engineering) can mint unlimited tokens. Locking the TreasuryCap as a dynamic object field makes it inaccessible to any function call, including coin::mint (Security Best Practices).
Why burn the UpgradeCap
To further ensure the package cannot be modified, burn the UpgradeCap rather than transferring it. If the UpgradeCap remains accessible, a future upgrade could add a function that extracts the locked TreasuryCap from its dynamic field and mints additional tokens. Burning the UpgradeCap makes the package immutable and the fixed supply permanent (Security Best Practices).
Burning the UpgradeCap is irreversible. You cannot fix bugs or add features to the package after burning it. Only burn the UpgradeCap when you are confident the package is production-ready.
Deploy and verify
To deploy a fixed-supply coin:
- Build the package:
$ sui move build - Publish to the network:
$ sui client publish - Verify the total supply by querying the
CoinMetadataobject returned in the publish transaction. Thesupplyfield should match your intended total.