How to use the @polkadot/api.WsProvider 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 ChainSafe / gossamer / tests / polkadotjs_test / test_transaction.js View on Github external
async function main() {
    // Construct

    const wsProvider = new WsProvider('ws://127.0.0.1:8546');
    const api = await ApiPromise.create({ provider: wsProvider });

    // Simple transaction
    const keyring = new Keyring({type: 'sr25519' });
    const aliceKey = keyring.addFromUri('//Alice',  { name: 'Alice default' });
    console.log(`${aliceKey.meta.name}: has address ${aliceKey.address} with publicKey [${aliceKey.publicKey}]`);

    const ADDR_Bob = '0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22';

    const transfer = await api.tx.balances.transfer(ADDR_Bob, 12345)
        .signAndSend(aliceKey, {era: 0, blockHash: '0x64597c55a052d484d9ff357266be326f62573bb4fbdbb3cd49f219396fcebf78', blockNumber:0,  genesisHash: '0x64597c55a052d484d9ff357266be326f62573bb4fbdbb3cd49f219396fcebf78', nonce: 1, tip: 0, transactionVersion: 1});

    console.log(`hxHash ${transfer}`);

}
github polkadot-js / api / docs / examples / rx / 10_upgrade_chain / index.js View on Github external
async function main () {
  // Initialise the provider to connect to the local node
  const provider = new WsProvider('ws://127.0.0.1:9944');

  // Create the API and wait until ready (optional provider passed through)
  const api = await ApiRx.create({ provider }).toPromise();

  // Retrieve the upgrade key from the chain state
  // TODO It seems like this promise doesn't resolve
  const adminId = await api.query.sudo.key().toPromise();

  // Find the actual keypair in the keyring (if this is an changed value, the key
  // needs to be added to the keyring before - this assumes we have defaults, i.e.
  // Alice as the key - and this already exists on the test keyring)
  const keyring = testKeyring.default();
  const adminPair = keyring.getPair(adminId.toString());

  // Retrieve the runtime to upgrade to
  const code = fs.readFileSync('./test.wasm').toString('hex');
github paritytech / srml-contracts-waterfall / tests / contracts-assemblyscript.spec.ts View on Github external
async (done): Promise<() => void> => {
    api = await ApiPromise.create({ provider: new WsProvider(WSURL) });
    testAccount = keyring.addFromSeed(randomSeed);

    return api.tx.balances
      .transfer(testAccount.address, CREATION_FEE.muln(3))
      .signAndSend(bobPair, (result: SubmittableResult): void => {
        if (
          result.status.isFinalized &&
          result.findRecord("system", "ExtrinsicSuccess")
        ) {
          console.log("New test account has been created.");
          done();
        }
      });
  }
);
github polkadot-js / tools / packages / api-cli / src / api.ts View on Github external
async function getCallInfo (): Promise {
  assert(endpoint && endpoint.includes('.'), 'You need to specify the command to execute, e.g. query.balances.freeBalance');

  const provider = new WsProvider(ws);
  const api = (await ApiPromise.create({ provider })) as unknown as ApiExt;
  const [type, section, method] = endpoint.split('.') as [keyof ApiExt, string, string];

  assert(['consts', 'derive', 'query', 'rpc', 'tx'].includes(type), `Expected one of consts, derive, query, rpc, tx, found ${type}`);
  assert(api[type][section], `Cannot find ${type}.${section}`);
  assert(api[type][section][method], `Cannot find ${type}.${section}.${method}`);

  const fn = api[type][section][method];

  return {
    fn,
    log: (result: SubmittableResult | Codec | ApiCallFn): void =>
      console.log(JSON.stringify({ [method]: result }, null, 2)),
    method,
    section,
    type
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 };
  }
github polkadot-js / tools / packages / monitor-rpc / src / monitor.ts View on Github external
async function main (): Promise {
  const app = new Koa();

  app.use(koaRoute.all('/', httpStatus));
  app.listen(port);

  const provider = new WsProvider(ws);
  const api = await ApiPromise.create({ provider });

  await api.rpc.chain.subscribeNewHeads(updateCurrent);

  setInterval(checkDelay, 1000);
}

@polkadot/api

Promise and RxJS wrappers around the Polkadot JS RPC

Apache-2.0
Latest version published 5 days ago

Package Health Score

90 / 100
Full package analysis

Similar packages