* Moved all e2e tests to 'api' folder * Moved metadata test * fix imports * Add jest options for testing the different endpoint types separately * Add check for empty test suites and return empt test to prevent jest from throwing an error * Fix import paths * Fix const tests for polkadot chains * Update to latest Substrate 2.0 image * Move contract files for e2e testing to e2e tesing folder * reorder & fix promise query tests for all test nodes * final fixes for promise query * eslint fixes * removed trailing space * fix linting errors * Address codeclimate "Function getWsEndpoints has a Cognitive Complexity of 7 (exceeds 5 allowed)." * Fix contract ABI import paths * linter endpoint types * replace alice with alice_stash * split off promise-queries file * Remove apiType, smaller cleanups, added local to only: [] tests suites * relative paths changed to `@polkadot` import * moved contract wasm & abi's back to `api-contract`
@polkadot/rpc-core
This library provides a clean wrapper around all the methods exposed by a Polkadot network client.
Usage
Installation -
yarn add @polkadot/rpc-core
Initialisation -
import Rpc from '@polkadot/rpc-core';
import WsProvider from '@polkadot/rpc-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9944');
const rpc = new Rpc(provider);
Retrieving the block header object for a given block header hash (a 0x-prefixed hex string with length of 64) -
rpc.chain
.getHeader('0x1234567890')
.subscribe(
(header) => console.log(header),
(error) => console.error('error:', error)
);
Retrieving the best block number, parent hash, state root hash, extrinsics root hash, and digest (once-off) -
rpc.chain
.getHead()
.pipe(
switchMap((headerHash) => {
return rpc.chain.getHeader(headerHash);
})
)
.subscribe(
(header) => {
console.log(`best #${header.blockNumber.toString()}`);
console.log(`parentHash: ${header.parentHash.toString()}`);
console.log(`stateRoot: ${header.stateRoot.toString()}`);
console.log(`extrinsicsRoot: ${header.extrinsicsRoot.toString()}`);
console.log(`digest: ${header.digest.toString()}`);
},
(error) => {
console.error('error:', error);
}
);
Retrieving best header via subscription -
api.chain
rpc
.subscribeNewHead()
.subscribe(
(header) => {
console.log(`best #${header.blockNumber}`);
},
(error) => {
console.error('error subscribing:', error);
}
);