How to use the @polkadot/api.ApiPromise function in @polkadot/api

To help you get started, we’ve selected a few @polkadot/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github w3f / polkadot-deployer / lib / benchmarks / strategies / finality.js View on Github external
return new Promise(async (resolve) => {
      const provider = new WsProvider(this.config.wsEndpoint);
      const api = await new ApiPromise(provider).isReady;
      const result = [];

      let blockCounter = 0;

      const creationTimestamps = new Map();

      api.rpc.chain.subscribeNewHead(async (header) => {
        // for each produced block we store the timestamp
        const timestamp = Date.now();
        console.log(`New produced block: ${header.blockNumber}, timestamp: ${timestamp}`);
        creationTimestamps.set(header.blockNumber.toString(), timestamp);
      });

      api.rpc.chain.subscribeFinalizedHeads(async (header) => {
        const finalizationTimestamp = Date.now();
        blockCounter++;
github w3f / polkadot-deployer / lib / cluster / strategies / remote / index.js View on Github external
async _waitReadyDNS(index=0) {
    const wsEndpoint = this._wsEndpoint(index);

    const provider = new WsProvider(wsEndpoint);
    const api = await new ApiPromise(provider);

    const [chain, nodeName, nodeVersion] = await Promise.all([
      api.rpc.system.chain(),
      api.rpc.system.name(),
      api.rpc.system.version()
    ]);

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

    api.disconnect();

    return { wsEndpoint };
  }

@polkadot/api

Promise and RxJS wrappers around the Polkadot JS RPC

Apache-2.0
Latest version published 10 days ago

Package Health Score

92 / 100
Full package analysis

Similar packages