Skip to Content

Implementation

In code, assets are governed by the assetsModule. The assetsModule encapsulates the runtime assets registry, where the list of supported asset plugins are supplied as a configuration parameter. These asset plugins define all the builtIn assets. In addition to builtIn assets, a set of Custom Tokens may be read from storage to be added immediately to the runtime assets registry. Additional Custom Tokens may be added during runtime. The assetsModule is responsible for initializing and maintaining assets during runtime.

Properties of Assets

The in-code keyword asset refers to the object exported via assetsModule.getAsset(assetName). This object contains all the asset metadata and API functions to interact with the asset. The following subsections describe some of the basic properties.

Name, Ticker and Asset ID

asset.name and asset.ticker are globally unique identifiers for an asset from the wallet’s point of view. Always use asset.name instead of asset.ticker for indexing assets. There may be legacy use cases where asset.ticker is still required (such as exchange), however use should limit the use to those areas as much as possible. There is also the asset.assetId identifier, which can be used to uniquely map an asset to its on-chain equivalent. This identifier is currently only supported for tokens (custom or builtIn).

Asset names are arbitrary lower-case strings containing alphanumeric characters and the underscore _, such as bitcoin or tetherusd_algorand.

Since the introduction of the Custom Tokens Registry, a new form for token names has been chosen: <prefix>_<network>_<hash>. An example on the Ethereum network would be: ach_ethereum_fbad19a6. This form is chosen to be globally unique and deriveable from on-blockchain information only. This new form of token names is now used for all new tokens, including new builtIn ones, making the old-form a legacy form.

Base Asset vs. Token

A base asset by definition is an asset for which it’s base asset is itself: asset.baseAsset.name === asset.name. There is only one such asset in each network. A token’s base asset can be found via asset.baseAsset. For all tokens the opposite is true: asset.baseAsset.name !== asset.name. And all tokens of the same network have the same base asset.

Built-in Asset vs. Custom Token

A built in asset can be identified by asset.isBuiltIn === true. Similarly a Custom Token is identified by: asset.isCustomToken === true. The two properties are mutually exclusive. Please note that when adding a Custom Token to the assetsModule a builtIn token may be added if found.

Asset initialization

Initialization of assets is done by the assetsModule.
The assetsModule.initialize({ assetClientInterface }) function (See @exodus/assets-feature/module/assets-module) performs the initialization by iterating over all supplied asset plugins and calling assetPlugin.createAsset({ assetClientInterface }).
The initialize function is invoked by the asset-client-interface module (See @exodus/assets-feature/client/asset-client-interface), which is passed to the assets being initialized. During this initialization the asset.api.getTokens() function is called to add all builtIn tokens for the current network.

Last updated on

Start building

XO

Request Demo

Schedule a call with our team

Select a product
Arrow right