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,
});import "@therootnetwork/api-types";
import { ApiPromise, WsProvider } from '@polkadot/api';
// Set node endpoint (ideally replace with .env variable)
const endpoint = 'wss://rootscan.io/archive/ws'
// Set RPC API Key into Header
const headers = {
x-api-key: process.env['RPC_API_KEY'] || ''
};
// Automatically reconnect after 1 sec
const autoConnectMs = 1000;
// Initialize the provider instance
const provider = new WsProvider(endpoint, autoConnectMs, headers);
// Create an API instance
const api = await ApiPromise.create({
...getApiOptions(),
provider,
});Use api
instanceto interact with the node
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}
Last updated
Was this helpful?