Fungible tokens

Intro

Fungible tokens are digital assets that are interchangeable - one token can replace another one without any consiquences. These tokens are commonly used to represent in-game resources such as gold, crystals, or coins.

Fungible tokens Explained

Fungible tokens operate as a list of records on the blockchain, where each record maps a blockchain address to its balance of the token. When a transfer occurs, the balance of the sender decreases, and the balance of the recipient increases accordingly.

Create Fungible token

Creating a fungible token involves creating a new list of records on the blockchain to represent the token balances. In a game context, where various resources like gold, gems, wood, or steel are fungible, separate tokens are created for each resource.

Mint Fungible tokens

Minting a Fungible token is increasing the balance of a blockchain address. If the initial address balance is 1000 tokens and the game admin mints 75 tokens - the final address' balance would be 1075 tokens.

Withdraw Fungible tokens

When the game processes a withdrawal requested by a player, the player' blockchain address becomes the owner of the tokens. At the same time the same amount of in-game resources shall be deleted from the in-game account of the player.

TODO add diagram

On the diagram above the game preliminary minted the tokens. Another strategy that the game can employ is to mint tokens directly to the player' address.

Transfer Fungible tokens

When the first player Alice transfers fungible tokens, she sends a blockchain transaction, which decreases balance of Alice and increases balance of Bob. From this point on, the player Bob becomes the new owner of transferred fungible tokens and can freely transfer them to other blockchain addresses.

This transfer is facilitated by the decentralized infrastructure and doesn't require any support / action from the game.

TODO add diagram

Deposit Fungible tokens

When the player transfers the fungible tokens back to the game (makes a deposit) the game becomes the owner of the tokens and issues a deposit of the in-game resources to the player's in-game account.

TODO add diagram

After the successful deposit the tokens are not bound to the player. Later the game can send these tokens to another player on withdrawal of the same in-game resource. Or the game can burn the tokens and mint them again when needed.

Burn Fungible tokens

The AppAgent admins can burn previously created fungible tokens. By doing this balance of an address will be decreased.

The AppAgent admins can burn tokens at any moment regardless who owns them - a keyless address controlled by the AppAgent or a regular blockchain address controlled by a player. This power comes with responsibility - all actions with player' tokens must be justified.

Fungible token Metadata

Fungible tokens have metadata stored in a JSON file which includes information about the token such as its name, symbol, and a link to its cover image. Blockchain stores only a permanent link to the JSON file. JSON file itself is stored on a server or in a Content delivery network (CDN.) Client applications like TRAIT Wallet rely on this metadata to display the token to users. Metadata is the key element for token interoperability and a good player experience.

The blockchain record doesn't contain anything directly related to the visual assets, such as 3D models, textures, or shaders.

What data can be stored on-chain?

Generally, on-chain storage is suitable for critical data that requires immutability and transparency such as transaction records, token ownership. However, off-chain storage is preferred for large data sets such as multimedia files since storing them on the blockchain would be inefficient or costly.

Read more about Metadata

Precision

Usually when people deal with some fungible resources they operate with float numbers. For example, player's balance is 350.75 gold and 135.87 silver. But due to the technical reasons, the blockchain only works with integer values.

To overcome this we use a trick:

  • all values are represented as big integer numbers. For example, user balance would be represented as 350750000000000 gold and 13587000 silver;

  • in the metadata of the fungible token we specify the precision of the token. In this example, the precision of the gold token is 12 and the precision of the silver token is 5.

Precision affects how the balance is displayed in the client apps such as TRAIT Wallet. Precision of a particular token is set by the game admins.

Guides to use Fungible Tokens in your app:

Last updated