Fungible token standard
The fungible-token standard provides a NEP-141 token core that a NEAR contract can embed and expose through its own public interface. It coordinates balances, total supply, account registration, token metadata, transfer callbacks, refund resolution, and indexer events while leaving token issuance and application-specific behavior to the host contract.
Token core
The token core is the common interface for moving tokens and reading token state. A contract exposes the FungibleTokenCore methods through its own contract type and stores a FungibleToken value as the token state (see near-contract-standards/…/core.rs• L82-131 and near-contract-standards/…/core_impl.rs• L28-38).
Transfer operations
ft_transfer moves a positive amount from the predecessor account to a registered receiver. Both accounts must be registered, the sender and receiver must differ, and the call must carry exactly 1 yoctoNEAR. ft_balance_of returns zero for an unknown account, while transfer methods treat an unknown account as an error. Amounts use U128, which represents token values as decimal strings at the contract boundary (see near-contract-standards/…/core.rs• L84-94, near-contract-standards/…/core.rs• L127-131, and near-contract-standards/…/core_impl.rs• L121-163).
ft_total_supply reports the supply tracked by the token. The shared balance operations keep account balances and total supply within u128; a balance or supply overflow causes the call to fail rather than produce an invalid token state (see near-contract-standards/…/core_impl.rs• L68-92).
References: near-contract-standards/…/core.rs• L82-131 near-contract-standards/…/core_impl.rs• L59-92 near-contract-standards/…/core_impl.rs• L121-163
Transfer-call flow
ft_transfer_call first moves the tokens to the receiver contract. It then passes the sender, amount, and caller message to ft_on_transfer. A private resolver completes the operation by returning the unused part to the sender. This design lets a receiver use only the amount needed for an action without requiring a separate refund transaction.
The following flow shows how a transfer call moves through the token contract, receiver, and resolver.
sequenceDiagram
participant S as Sender
participant T as Token contract
participant R as Receiver contract
S->>T: ft_transfer_call(receiver, amount, msg)
T->>T: Move amount to receiver
T->>R: ft_on_transfer(sender, amount, msg)
R-->>T: Unused amount
T->>T: Resolve refund or burn
T-->>S: Return used amount
The receiver call receives the remaining gas. If it fails or returns an invalid value, the resolver treats the full amount as unused. The resolver also limits the reported unused amount to the transferred amount. If the sender account was removed while the call was in flight, the available refund is taken from the receiver and the rest is burned from total supply (see near-contract-standards/…/core_impl.rs• L129-154, near-contract-standards/…/core_impl.rs• L165-233, and near-contract-standards/…/receiver.rs• L4-29).
References: near-contract-standards/…/core.rs• L96-125 near-contract-standards/…/core_impl.rs• L129-154 near-contract-standards/…/core_impl.rs• L165-233
Receiver callback contract
FungibleTokenReceiver is the callback interface for contracts that accept transfer calls. Its ft_on_transfer method returns the amount it did not use. A receiver can return zero when it accepts all tokens, return a partial amount when it uses only part of the transfer, or return the full amount when the requested action cannot proceed (see near-contract-standards/…/receiver.rs• L5-29).
The msg value is application data. The token standard passes it through but does not define its meaning. The receiver therefore owns the rules for decoding the message and deciding which tokens are accepted.
References: near-contract-standards/…/receiver.rs• L4-29 near-contract-standards/…/core_impl.rs• L138-152
Resolution rules
FungibleTokenResolver is the callback interface that finalizes a transfer call. The token contract normally exposes ft_resolve_transfer as a private method so that only the chained promise can invoke it. It returns the amount that remains used after any refund (see near-contract-standards/…/resolver.rs• L40-47).
The resolver protects the token balance when the receiver behaves badly or the sender disappears. It accepts only a valid unused amount no greater than the original transfer, refunds no more than the receiver still holds, and burns the refundable remainder when the sender is no longer registered (see near-contract-standards/…/core_impl.rs• L177-232).
References: near-contract-standards/…/resolver.rs• L3-47 near-contract-standards/…/core_impl.rs• L165-243
Account storage
The standard uses NEP-145 storage management to make each token account pay for the state needed to hold its balance. A contract that exposes StorageManagement can delegate registration, storage balance queries, and account removal to the embedded token (see near-contract-standards/…/storage_impl.rs• L50-115 and storage-management-and-upgrades).
Registration lifecycle
An account must register before it can hold or send tokens. storage_deposit creates the account at the required minimum storage balance and refunds any excess deposit. A repeat deposit does not change the account and refunds the deposit to the caller.
The standard sets the minimum and maximum storage balances to the same value. As a result, a registered account has no withdrawable storage surplus. storage_withdraw can confirm the account balance when no amount is requested, but it rejects a positive withdrawal (see near-contract-standards/…/storage_impl.rs• L38-47 and near-contract-standards/…/storage_impl.rs• L50-110).
References: near-contract-standards/…/storage_impl.rs• L50-78 near-contract-standards/…/storage_impl.rs• L80-110
Account removal
storage_unregister removes the predecessor's account and returns its storage deposit. Without force, removal fails when the account still has tokens. With force, the account is removed even when it has a balance, and that balance is deducted from total supply. The method requires exactly 1 yoctoNEAR and returns whether an account was removed (see near-contract-standards/…/storage_impl.rs• L8-35 and near-contract-standards/…/storage_impl.rs• L103-110).
References: near-contract-standards/…/storage_impl.rs• L5-47 near-contract-standards/…/storage_impl.rs• L50-115 near-contract-standards/…/mod.rs• L78-119
Token metadata
The metadata interface describes how wallets and other clients identify and display a token. A host contract stores and returns FungibleTokenMetadata through ft_metadata; the token core does not manage this metadata itself (see near-contract-standards/…/metadata.rs• L6-21).
Metadata fields
The metadata model contains the standard version, token name, symbol, icon, an optional external reference, an optional hash for that reference, and the number of display decimals. The spec value must be ft-1.0.0. A reference and its hash must be supplied together, and the hash must be 32 bytes when present (see near-contract-standards/…/metadata.rs• L4-16 and near-contract-standards/…/metadata.rs• L23-30).
References: near-contract-standards/…/metadata.rs• L4-30
Token events
The event module produces NEP-141 version 1.0.0 JSON logs for indexers. Each event is emitted as an EVENT_JSON: log entry with a standard name, event name, and data array (see near-contract-standards/…/events.rs• L1-14 and near-contract-standards/…/event.rs• L22-29).
Event types
The standard supplies three event types. Each type supports one event or a batch of events, and each token amount is represented as a decimal string in the JSON output.
| Event | Meaning | Main data |
|---|---|---|
ft_mint | New tokens enter an owner's balance. | owner_id, amount, optional memo |
ft_transfer | Tokens move between owners. | old_owner_id, new_owner_id, amount, optional memo |
ft_burn | Tokens leave an owner's balance and supply. | owner_id, amount, optional memo |
Normal transfers emit ft_transfer. The host contract must emit mint and application-specific burn events when it changes supply through its own extension logic. The built-in transfer resolver emits a refund transfer, or a burn event for the part that cannot be refunded after sender removal (see near-contract-standards/…/core_impl.rs• L94-112 and near-contract-standards/…/core_impl.rs• L197-228).
References: near-contract-standards/…/events.rs• L21-123 near-contract-standards/…/core_impl.rs• L94-112 near-contract-standards/…/core_impl.rs• L197-228
Extension points
The standard separates the reusable token state from the public contract that owns it. A host contract can expose the core, storage, metadata, and resolver interfaces as needed, then add product rules such as mint authorization, burn actions, account-close hooks, enumeration, or another token feature around them.
Contract integration
The main integration path is to implement the FungibleTokenCore and FungibleTokenResolver traits on the host contract and delegate to its embedded FungibleToken. The host contract can also implement StorageManagement and its own metadata provider. The generated external-contract interfaces support type-safe calls to contracts that implement these standards (see near-contract-standards/…/mod.rs• L9-25).
The deprecated impl_fungible_token_core! and impl_fungible_token_storage! macros show the same delegation model and allow hooks for burned tokens or closed accounts. New integrations should implement the traits directly, as the macro deprecation notes require (see near-contract-standards/…/macros.rs• L1-14 and near-contract-standards/…/macros.rs• L64-80).
References: near-contract-standards/…/mod.rs• L9-25 near-contract-standards/…/macros.rs• L1-14 near-contract-standards/…/macros.rs• L64-80
Supply and account hooks
The embedded token exposes internal balance operations for the host contract's controlled supply logic. The host contract is responsible for deciding who may create or destroy tokens and for emitting matching mint or burn events. It can also use the account-close result to update related application state.
References: near-contract-standards/…/core_impl.rs• L40-119 near-contract-standards/…/macros.rs• L7-61 near-contract-standards/…/macros.rs• L73-114
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the transfer-call promise chain must stay aligned with the receiver return contract and the resolver's refund and burn rules.
- Changes to account registration or storage sizing must stay aligned with the storage balance returned by
storage_balance_boundsand with the deposit refunded on account removal. - Changes to supply-changing host hooks must update both the tracked total supply and the matching NEP-141 mint or burn event.
- Changes to metadata validation must preserve the link between
referenceandreference_hashand the metadata version expected by clients. - Changes to the public traits must preserve the generated cross-contract interfaces used by token callers and receiver contracts.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Transfer or transfer call targets an unregistered account. | The token operation fails. | Register both accounts through storage management before transfer. |
| Transfer call omits or changes the required 1 yoctoNEAR deposit. | The operation fails before tokens move. | Require exactly 1 yoctoNEAR on token transfer calls. |
| Receiver callback fails or returns invalid data. | The resolver treats the full amount as unused and attempts a refund. | Keep receiver responses as valid U128 values within the transferred amount. |
| Sender account is removed before transfer resolution. | Refundable tokens are burned when they cannot return to the sender. | Avoid removing accounts with in-flight transfer calls. |
Account is unregistered with a positive balance without force. | Account removal fails. | Transfer or burn the balance before normal removal, or use force only when the burn is intended. |
Metadata has only one of reference or reference_hash, or a hash with the wrong length. | Metadata validation fails. | Supply both fields together and use a 32-byte hash. |
Key files
| File | Why to read it |
|---|---|
| near-contract-standards/…/core.rs | Defines the public token operations and their caller-facing contracts. |
| near-contract-standards/…/core_impl.rs | Shows the balance, supply, transfer-call, and resolution behavior supplied by the standard. |
| near-contract-standards/…/receiver.rs | Defines the receiver callback and its unused-token return rule. |
| near-contract-standards/…/resolver.rs | Defines the private transfer-resolution boundary. |
| near-contract-standards/…/storage_impl.rs | Explains account registration, storage deposits, and account removal. |
| near-contract-standards/…/metadata.rs | Defines the token metadata shape and validation rules. |
| near-contract-standards/…/events.rs | Defines NEP-141 mint, transfer, and burn event data. |
| near-contract-standards/…/macros.rs | Shows legacy delegation patterns and available account or burn hooks. |
contract-standards | Places the fungible-token standard within the broader contract-standard set. |
non-fungible-token-standard | Provides the related NFT standard for comparison. |
storage-management-and-upgrades | Covers the shared storage-management and upgrade concerns. |