Skip to main content
Wanting to use Fungible Tokens (FT) in your dApp? Here you will find all the information you need to get started creating your own tokens, registering users, querying balances, transferring tokens, and integrating them into your smart contracts. The WebApp examples use the local useNearWallet hook from the Hello NEAR provider setup.

Creating a New Token

Use the existing global FT contract to create a token. Reuse its deployed code and configure the owner, initial supply, and metadata through initialization arguments.

Global Contracts

You can deploy a new Fungible Token using our global FT contract - a pre-deployed standard FT contract that you can reuse. Global contracts are deployed once and can be reused by any account without incurring high storage costs.
Deploying by hash creates an immutable contract that never changes. Deploying by account ID creates an updatable contract that changes when the referenced account’s contract is updated. Choose based on whether you want your FT contract to be updatable or permanent.

Creating a Token with a Factory

You can also create a Fungible Token by interacting with a factory contract, to which you provide the owner, initial supply, and token metadata. The factory will automatically deploy and initialize a canonical FT contract. Both factories expose get_required and create_token, and both methods take { args } on either network. The token account is the symbol in lowercase, e.g. TTTEST becomes tttest.token.primitives.near, so pick a symbol that has not been taken yet.
Creating a token takes two steps: call get_required to quote the storage deposit (which depends on the metadata size, including the required icon), then call create_token attaching that amount. total_supply is a string in the smallest token units: multiply the number of whole tokens by 10^decimals.
Learn more about setting up the NEAR provider in your application

Querying Metadata

You can query the FT’s metadata by calling the ft_metadata.

Learn more about setting up the NEAR provider in your application

Checking Balance

To know how many coins a user has you will need to query the method ft_balance_of.
Remember about fungible token precision. You may need this value to show a response of balance requests in an understandable-to-user way in your app. How to get precision value (decimals) you may find here.

Learn more about setting up the NEAR provider in your application

Registering a User

In order for a user to own and transfer tokens they need to first register in the contract. This is done by calling storage_deposit and attaching 0.00125Ⓝ. By calling this storage_deposit the user can register themselves or register other users.
Learn more about setting up the NEAR provider in your application
You can make sure a user is registered by calling storage_balance_of.
After a user calls the storage_deposit the FT will appear in their Wallets.

Transferring Tokens

To send FT to another account you will use the ft_transfer method, indicating the receiver and the amount of FT you want to send.
Learn more about setting up the NEAR provider in your application

Attaching FTs to a Call

Natively, only NEAR tokens (Ⓝ) can be attached to a function calls. However, the FT standard enables to attach fungible tokens in a call by using the FT-contract as intermediary. This means that, instead of you attaching tokens directly to the call, you ask the FT-contract to do both a transfer and a function call in your name. Let’s assume that you need to deposit FTs on Rhea Finance.

Learn more about setting up the NEAR provider in your application
How it works:
  1. You call ft_transfer_call in the FT contract passing: the receiver, a message, and the amount.
  2. The FT contract transfers the amount to the receiver.
  3. The FT contract calls receiver.ft_on_transfer(sender, msg, amount)
  4. The FT contract handles errors in the ft_resolve_transfer callback.
  5. The FT contract returns you how much of the attached amount was actually used.

Handling Deposits

If you want your contract to handle deposit in FTs you have to implement the ft_on_transfer method. When executed, such method will know:
  • Which FT was transferred, since it is the predecessor account.
  • Who is sending the FT, since it is a parameter
  • How many FT were transferred, since it is a parameter
  • If there are any parameters encoded as a message
The ft_on_transfer must return how many FT tokens have to be refunded, so the FT contract gives them back to the sender. Here is an example from our auctions tutorial where we implement ft_on_transfer to handle bids in FTs:
lib.rs
Note: The near_contract_standards::fungible_token::receiver module exposes a FungibleTokenReceiver trait that you could implement on your contract

Burn Tokens

While the FT standard does not define a burn method, you can simply transfer tokens to an account that no one controls, such as 0000000000000000000000000000000000000000000000000000000000000000 (64 zeros).
Learn more about setting up the NEAR provider in your application

Additional Application Behavior

Use the global FT contract by default. Only if your application truly requires behavior it does not provide, use near-contract-standards or near-sdk-contract-tools for the token implementation. Keep balances, transfers, storage management, and transfer resolution in these libraries; do not implement the FT standard by hand.

Additional Resources

  1. NEP-141 standard
  2. NEP-148 standard
  3. FT Event Standards
  4. FT reference implementation
  5. FT with Contract Tools - library-provided token functionality when a global contract cannot meet the application’s needs.