πŸŽ‡Get the chain information for a Signer

In this section we'll learn how to get the some basic network information using polkadot.js API

Check the network information using Polkadot API

// Import the Polkadot API
import { ApiPromise, WsProvider } from '@polkadot/api';

async function connectAndFetchChainInfo() {
  // Create a connection to the Polkadot network via websocket
  const polkadotWsProvider = new WsProvider('wss://rpc.polkadot.io');
  // Create a new instance of the Polkadot API
  const polkadotApi = await ApiPromise.create({ provider: polkadotWsProvider });
  // Retrieve information about the Polkadot chain
  const polkadotChainInfo = await polkadotApi.registry.getChainProperties();

  console.log(polkadotChainInfo);
  // For Polkadot, this would print
  // {ss58Format: 0, tokenDecimals: [10], tokenSymbol: [DOT]}
}

connectAndFetchChainInfo().catch(console.error).finally(() => process.exit());

Last updated