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)constendpoint='https://rootscan.io/archive'// Set RPC API Key into Headerconstheaders= { x-api-key:process.env['RPC_API_KEY'] ||''};// Initialize the provider instanceconstprovider=newHttpProvider(endpoint, headers);// Create an API instanceconstapi=awaitApiPromise.create({ ...getApiOptions(), provider,});
import"@therootnetwork/api-types";import { ApiPromise, WsProvider } from'@polkadot/api';// Set node endpoint (ideally replace with .env variable)constendpoint='wss://rootscan.io/archive/ws'// Set RPC API Key into Headerconstheaders= { x-api-key:process.env['RPC_API_KEY'] ||''};// Automatically reconnect after 1 secconstautoConnectMs=1000;// Initialize the provider instanceconstprovider=newWsProvider(endpoint, autoConnectMs, headers);// Create an API instanceconstapi=awaitApiPromise.create({ ...getApiOptions(), provider,});
Use api instance to interact with the node
import"@therootnetwork/api-types";// Query and display account dataconstdata=awaitapi.query.system.account("0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b");
Alternatively, we support passing the API key as a query parameter instead of a using it in the header. Here is an example of such a query: https://rootscan.io/archive?apikey={API_KEY}