Tokens

Fungible Token

How do I transfer ROOT token?

Since ROOT token is a security token, it's managed by the balances pallet. To transfer ROOT tokens, use the following snippet:

// transfer 1 ROOT to Alice
await api.balances.transfer(1_000_000, "0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b").signAndSend(...);

Note: ROOT token has 6 decimals.

How do I transfer XRP or any other fungible tokens?

XRP and any other non-default fungible tokens are managed by the assets pallet, separate from the balances pallet. That also means you need to provide the asset ID when you want to transfer any of these tokens.

// get the `metadata` to determine the `decimals`
const XRP_ID = 2;
const metadata = (await api.query.assets.metadata(XRP_ID)).toJson();
const oneXRP = 1 * Math.pow(10, metadata.decimals);

// transfer 1 XRP to Alice
await api.assets.transfer(XRP_ID, "0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b", oneXRP).signAndSend(...);

Tip: To retrieve a list of available tokens and their asset IDs, checkout Tokens section in our Block Explorer.

NFT (Non-Fungible Token)

How do I create and mint an NFT?

To create your NFT collection, call the nft.createCollection() extrinsic with the following parameters:

await api.tx.nft.createCollection(
	collectionName,
	initialIssuance,
	maxIssuance,
	tokenOwner,
	metadataScheme,
	royaltiesSchedule,
	crossChainCompatibility
);

Caution: The royaltiesSchedule is in permill (parts per million) scaling, so if you want a 10% royalty, that would be 100,000 (as 100_000 / 1_000_000 = 0.1).

Once your collection is created, the collection owner can call the nft.mint() method on the collection to start minting additional tokens so long as the max issuance has not been reached:

await api.tx.nft.mint(collectionId, quantity, beneficiary);

SFT (Semi-Fungible Token)

How do I create and mint an SFT?

SFTs are similar to NFTs however due to their similarity to ERC1155, there can be multiple tokens per SFT collection. Each SFT token has a unique ID, and the collection owner can mint multiple tokens with the same ID. To create your SFT collection, call the sft.createCollection() extrinsic with the following parameters:

await api.tx.sft.createCollection(
    collectionName,
    collectionOwner,
    metadataScheme,
    royaltiesSchedule
)

To create an SFT token within the collection, call the sft.createToken() extrinsic with the following parameters:

await api.tx.sft.createToken(
    collectionId,
    tokenName,
    initialIssuance,
    maxIssuance,
    tokenOwner
)

Once your token is created, the collection owner can call the sft.mint() method to start minting additional tokens so long as the max issuance for that token has not been reached. The owner can pass in a tuple of serialNumbers and quantities to mint multiple tokens at once.

await api.tx.sft.mint(collectionId, serialNumbers, tokenOwner);

Last updated

© 2023 -> ♾️