Interface | Description |
---|---|
SubmittableExtrinsic<ApplyResult> | |
SubmittableExtrinsic.StatusCb | |
Types | |
Types.ApiBaseInterface<ApplyResult> | |
Types.ApiInterfacePromise | |
Types.OnCallDefinition<ApplyResult> | |
Types.OnCallFunction | |
Types.Signer |
Class | Description |
---|---|
ApiBase<ApplyResult> | |
ApiUtils | |
SubmittableExtrinsic.SubmittableExtrinsicImpl | |
SubmittableExtrinsic.SubmittableResult | |
Types.ApiOptions | |
Types.DecoratedRpc<ApplyResult> | |
Types.DecoratedRpcMethod<ApplyResult> | |
Types.DecoratedRpcSection<ApplyResult> | |
Types.Derive<ApplyResult> | |
Types.DeriveMethod<ApplyResult> | |
Types.DeriveSection<ApplyResult> | |
Types.QueryableModuleStorage<ApplyResult> | |
Types.QueryableStorage<ApplyResult> | |
Types.QueryableStorageFunction<ApplyResult> |
export interface QueryableStorageFunctionBase<CodecResult, SubscriptionResult> extends StorageFunction {
(arg?: CodecArg): CodecResult;
at: (hash: Hash | Uint8Array | string, arg?: CodecArg) => CodecResult;
hash: (arg?: CodecArg) => HashResult<CodecResult, SubscriptionResult>;
key: (arg?: CodecArg) => string;
size: (arg?: CodecArg) => U64Result<CodecResult, SubscriptionResult>;
}
|
Types.SubmittableExtrinsicFunction<ApplyResult> | |
Types.SubmittableExtrinsics<ApplyResult> | |
Types.SubmittableModuleExtrinsics |
Enum | Description |
---|---|
ApiBase.ApiType |
This library provides a clean wrapper around all the methods exposed by a Polkadot network client.
Installation -
yarn add @polkadot/rpc-core
Initialisation -
const provider = new WsProvider("http://127.0.0.1:9944");
const api = new Rpc(provider);
Retrieving the block header object for a given block header hash (a 0x-prefixed hex string with length of 64) -
api.chain
.getHeader("0x1234567890")
.then((header) => System.out.println(header))
.catch((error) => System.out.println(error));
Retrieving the best block number, parent hash, state root hash, extrinsics root hash, and digest (once-off) -
api.chain
.getHead()
.then((headerHash) => {
return api.chain.getHeader(headerHash);
})
.then((header) => {
System.out.print("best ");
System.out.println(header.blockNumber);
System.out.print("parentHash: ");
System.out.println(header.parentHash.toString());
System.out.print("stateRoot: ");
System.out.println(header.stateRoot.toString());
System.out.print("extrinsicsRoot: ");
System.out.println(header.extrinsicsRoot.toString());
System.out.print("digest: ");
System.out.println(header.digest.toString());
})
.catch((error) => {
System.out.println(error);
});
Retrieving best header via subscription -
api.chain
.subscribeNewHead((header) => {
System.out.print("best ");
System.out.println(header.blockNumber);
})
.then((subscriptionId) => {
System.out.print("subscriptionId: ");
System.out.println(subscriptionId);
// id for the subscription, can unsubscribe via
// api.chain.subscribeNewHead.unsubscribe(subscriptionId);
})
.catch((error) => {
System.out.println(error);
});