Get chain information

This example shows how to connect to the api and retrieve the chain information such as the token name, the ss58 format for address encoding and the token decimals.

// Import the API
const { ApiPromise } = require('@polkadot/api');
const { typesBundleForPolkadot } = require('@crustio/type-definitions');
async function main () {
// Create a new instance of the api
const api = await ApiPromise.create({
provider: new WsProvider('ws://127.0.0.1:9944'),
typesBundle: typesBundleForPolkadot
});
// get the chain information
const chainInfo = await api.registry.getChainProperties()
console.log(chainInfo);
// for Polkadot this would print
// {ss58Format: 0, tokenDecimals: [10], tokenSymbol: [DOT]}
}
main().catch(console.error).finally(() => process.exit());;