Your First Fungible Asset
Your First Fungible Asset
This tutorial introduces how you can compile, deploy, and mint your own fungible asset (FA), named FACoin. The Fungible Asset Standard provides built-in support for minting, transferring, burning, and tracking account balances, so is useful for representing fungible assets.
We will use Endless CLI to create, mint, burn and transfer coins in our Typescript demo code.
At a high level, the Fungible Asset Standard works through two main Objects:
A
MetadataObject to store information about the fungible asset.FungibleStoresfor each account that has the fungible asset to track their current account balance.
Sending a fungible asset to someone will cause:
create
FungibleStoreon Receiver account ifFungibleStorenot existsupdate the balances for both accounts accordingly.
Step 1: Pick an SDK
Install your preferred SDK from the below list:
TypeScript SDK
Step 2: Install the CLI
Install the precompiled binary for the Endless CLI.
Step 3: Run the example
Clone the endless-ts-sdk repo and build it:
Navigate to the Typescript examples directory:
Install the necessary dependencies:
Step 4: Fungible Asset Move
Run your_fungible_asset
You should see an output demonstrating how the fungible assets are created and transferred that looks like this:
Understanding the fa_coin.move Example Contract
The full contract for FACoin.move can be found here.
Let’s go step by step through how this contract is written.
Move.toml
The Move.toml file allows Move to import dependencies, determine which addresses to use, and includes metadata about the contract.
Regardless of which features you add to your fungible asset, your Move.toml will likely have similar fields to this at a minimum. In this case, we have the primary contract address FACoin that needs specifying at deploy time (indicated by leaving the value as “_”). It also includes the GitHub dependency to import the Fungible Asset standard from “EndlessFramework”.
Move.toml
Imports
The FACoin module uses several important modules:
fungible_assetcontains the logic for granting permission to mint, transfer, burn, and create your FungibleAsset.objectallows for creating Endless Objects.primary_fungible_storecontains the logic to track account balances for the new Fungible Asset.
FACoin.move
These imports are defined in the Move.toml file as GitHub dependencies.
init_module
This function is called when the module is initially published in order to set up the proper permissions and Objects. For FACoin, this is used to initialize the asset’s MetaData Object (which contains things like the asset’s name and symbol), as well as getting the relevant ref’s for how our fungible asset will be used.
The ManagedFungibleAsset standard helps keep track of which permissions this Module is allowed to use.
fa_coin.move
View Functions
When creating your own fungible asset, it can be helpful to add view functions for any data that is needed later on. In this case, we wanted to see the name of the asset in order to report which asset was being traded in our example scenario.
fa_coin.move
Entry Functions
Every fungible asset has a similar interface (mint, transfer, burn, freeze, unfreeze, deposit, and withdraw). Here’s an example of a minimal mint function, which mints and transfers the funds to the proper recipient:
fa_coin.move
Step 5: Fungible Asset CLI
Run the TypeScript your_fungible_asset_cli example:
The application will complete, printing:
Step 6: endless coin CLI in depth
endless coin CLI in depthStep 6.1: Coin CLI
Endless cli provide command to manage User customized fungible assets, including Create, Mint, Burn and Transfer, etc.
Step 6.2: Understanding the management primitives of FACoin
The creator of FACoin have several managing primitives:
Creating: Creating the Coin ("FACoin" metadata object).
Minting: Minting new coins.
Burning: Deleting coins.
Freezing/Unfreezing: Disabling/Enabling the owner of an account to withdraw from or deposit to their primary fungible store of FACoin.
Transfer: Withdraw from owned account and deposit to another acount.
Step 6.3: Creating "FACoin" metadata object
FACoin has below attributes:
name: FACoin
symbol: FA
decimal: 8
max_supply: unlimited, ie. U128_MAX
icon_url: none
project_url: none
Once we create FACoin, we need to fetch FACoin's metadata address for the next coin management operations.
cause Alice never create any fungible asset before, so query 1st coin data will be FACoin metadata address
Step 6.3.1: mint coins
Minting coins requires MintRef that was produced during initialization, only Coin Creator(ie. Alice) has authority to mint coins.
Step 6.3.2: Query balance of FACoin
endless-ts-sdk provide function viewCoinBalance for user to query balance of coins, providing Coin Metadata address and account address.
Step 6.3.3: Transferring coins
endless-ts-sdk provide function transferFungibleAsset for user to build transaction of transfering coins from coinholder to another account.
Endless Token module provides all functions related with customized Token, you could build your customized move contract and write Typescripts code to interact with your move contract, fullfill token management as above.
Supporting documentation
Endless CLI
Fungible Asset
TypeScript SDK
Last updated