3

Different substrate chains have different denominations for native tokens.

For example, to get human readable amounts with Polkadot you have to divide by 1e10, Kusama by 1e12, Acala by 1e12 etc.

Is there a way to find the denomination by querying the chain itself rather than googling protocol information? In a storage function or the metadata for example?

1 Answer 1

4

PolkadotJS offers it. Simple as:

import { ApiPromise, WsProvider } from '@polkadot/api';

const wsProvider = new WsProvider('wss://rpc.polkadot.io');
const api = await ApiPromise.create({ provider: wsProvider });

const decimals = api.registry.chainDecimals;
console.log(`Polkadot has ${decimals} decimals`);
// Polkadot has 10 decimals

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.