What is the radixToken object in the sample code from the documentation?

js

#1

Question originally asked by phil#1495 in the radixdlt-js channel in the Radix Discord server


30

while I look at this, it is all about reading the balance using the ID of an object retrieved from radixTokenManager.getTokenByISO('TEST')

    myAccount.transferSystem.balanceSubject.subscribe(balance => {
      
      const floatingPointBalance = radixToken.toTokenUnits(
        balance[radixToken.id],
      );
});

I don’t get what the radixToken object is that is retrieved by getTokenByISO . What’s this all about? Thanks


The radixToken object is the token definition of the ‘TEST’ token. It holds all of the token properties - the name, description, total supply and permissions.

The balance object is indexed by different token ids - so basically what we’re doing here is “what’s the account balance for the token with the following id”. Since Radix will natively support user-created tokens, it needs to handle the balance for each token separately

Lastly, you need to do .toTokenUnits() because the actual balance on ledger is stored in integer subunits, like the satoshis for bitcoin. Due to how floating point math works, if you first convert them to the decimal amount and then add them up, you can end up with an incorrect amount

I’m hoping to clean up this API in the next big release however - in most cases you shouldn’t have to know these details