Skip to main content

Connecting with Polkadot.js

Polkadot.js is the most widely used JS/TS library for interacting with Polkadot and Substrate-based chains.

Installation

npm install @polkadot/api

Connecting to the geo-steered endpoint

import { ApiPromise, WsProvider } from '@polkadot/api';

const provider = new WsProvider('wss://asset-hub.polkadot.rpc.deserve.network');
const api = await ApiPromise.create({ provider });

console.log(`Connected to chain: ${await api.rpc.system.chain()}`);

Connecting to a regional endpoint

import { ApiPromise, WsProvider } from '@polkadot/api';

// replace with your preferred regional endpoint
const provider = new WsProvider('wss://london.asset-hub.polkadot.rpc.deserve.network');
const api = await ApiPromise.create({ provider });

console.log(`Connected to chain: ${await api.rpc.system.chain()}`);

Available endpoints

NetworkEndpoints
Polkadot Asset HubLink
Polkadot CoretimeLink