Simple Connect

The following example shows how to instantiate a Polkadot API object and use it to connect to a node using ApiPromise.

// Required imports
const { ApiPromise, WsProvider } = require('@polkadot/api');

async function main () {
  // Initialise the provider to connect to the local node
  const provider = new WsProvider('ws://');

  // Create the API and wait until ready
  const api = await ApiPromise.create({ provider });

  // Retrieve the chain & node information information via rpc calls
  const [chain, nodeName, nodeVersion] = await Promise.all([

  console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);

main().catch(console.error).finally(() => process.exit());