Token management

Introduction

Let's review the following code examples on how to create, mint, and burn tokens:

Creating tokens

Tokens can be single or multi-issuance. Multi-issuance tokens can be minted after token creation, while single issuance tokens are limited to the amount specified in the token definition.

Note: A token is uniquely identified by its symbol and the account that owns it. It can be referred to with a unique URI in the form of /address/symbol. We call these URIs Radix Resource Identifiers or RRIs for short.

Token amounts on the ledger are stored as integer values in subunits. All tokens have 10^18 subunits.

Granularity defines the minimum increment of tokens that can be transacted. For example, if we set granularity to 0.1, then 1.0 or 1.2 are valid token amounts but 1.25 is not.

const symbol = 'EXMP'
const name = 'Example Coin'
const description = 'My example coin'
const granularity = 1
const amount = 1000
const iconUrl = 'http://a.b.com/icon.png'
new RadixTransactionBuilder().createTokenSingleIssuance(
myIdentity.account,
name,
symbol,
description,
granularity,
amount,
iconUrl,
).signAndSubmit(myIdentity)
.subscribe({
next: status => {console.log(status)},
complete: () => { console.log('Token defintion has been created') },
error: error => { console.error('Error submitting transaction', error) }
})

After that you can observe the token in the accounts tokenDefinitionSystem

const tokenReference = `/${myIdentity.account.getAddress()}/${symbol}`
myIdentity.account.transferSystem.tokenUnitsBalance[RLAU_URI] // will be equal to amount
myIdentity.account.tokenDefinitionSystem.getTokenDefinition(symbol) // will return token defintion

Querying the ledger for token definitions

It is possible to query the ledger for token information such as the total supply without manually managing the account using the radixTokenManager

import {radixTokenManager} from 'radixdlt'
const tokenReference = `/${myIdentity.account.getAddress()}/${symbol}`
radixTokenManager.getTokenDefinition(tokenReference).then(tokenDefinition => {
tokenDefinition.totalSupply // Check the total supply
}).catch(error => {
// Token wasn't found for some reason
})

Minting tokens

For multi-issuance tokens, it is possible to mint more tokens after they have been created

const tokenReference = `/${myIdentity.account.getAddress()}/${symbol}`
const amount = 10
RadixTransactionBuilder.createMintAtom(myIdentity.account, tokenReference, amount)
.signAndSubmit(myIdentity)
.subscribe({
next: status => {console.log(status)},
complete: () => { console.log('Tokens have been minted') },
error: error => { console.error('Error submitting transaction', error) }
})

Burning tokens

For multi-issuance tokens, it is possible to burn tokens after they have been created The account that owns the token definiton must also hold the tokens to be burned

const tokenReference = `/${myIdentity.account.getAddress()}/${symbol}`
const amount = 10
RadixTransactionBuilder.createBurnAtom(myIdentity.account, tokenReference, amount)
.signAndSubmit(myIdentity)
.subscribe({
next: status => {console.log(status)},
complete: () => { console.log('Tokens have been burned') },
error: error => { console.error('Error submitting transaction', error) }
})