Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Connection

Nikhil Ranjan edited this page Sep 22, 2022 · 2 revisions

To connect to astar/shiden node first install the dependencies and use ApiPromise with options.

yarn add @polkadot/api @astar-network/astar-api

Create API instance:

import { ApiPromise } from '@polkadot/api';
import { WsProvider } from '@polkadot/rpc-provider';
import { options } from '@astar-network/astar-api';

async function main() {
    const provider = new WsProvider('ws://localhost:9944');
    // OR
    // const provider = new WsProvider('wss://shiden.api.onfinality.io/public-ws');
    const api = new ApiPromise(options({ provider }));
    await api.isReady;

    // Use the api
    // For example:
    console.log((await api.rpc.system.properties()).toHuman());

    process.exit(0);
}

main()
Clone this wiki locally