Usage Example

To make RPC calls, you need to generate an RPC API Key and include it in the request header as the x-api-key parameter.

  • Create an API instance

import "@therootnetwork/api-types";
import { ApiPromise, HttpProvider } from '@polkadot/api';

// Set node endpoint (ideally, replace with .env variable)
const endpoint = 'https://rootscan.io/archive'

// Set RPC API Key into Header
const headers = { 
    x-api-key: process.env['RPC_API_KEY'] || '' 
};

// Initialize the provider instance
const provider = new HttpProvider(endpoint, headers);

// Create an API instance
const api = await ApiPromise.create({ 
    ...getApiOptions(),
    provider,
});
  • Use api instance to interact with the node

import "@therootnetwork/api-types";

// Query and display account data
const data = await api.query.system.account("0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b");

Last updated