Class JsonRpcClient<ChainApi, Events>

A generic interface for JSON-RPC clients

Type Parameters

Hierarchy (view full)

Implements

Constructors

Accessors

  • get rpc(): ChainApi[RpcVersion]["rpc"]
  • Returns ChainApi[RpcVersion]["rpc"]

    Entry-point for executing JSON-RPCs to blockchain node.

    const client = new JsonRpcClient('wss://rpc.polkadot.io');
    await client.connect();

    // Subscribe to new heads
    client.rpc.chain_subscribeNewHeads((header) => {
    console.log(header);
    });

    // Execute arbitrary rpc method: `module_rpc_name`
    const result = await client.rpc.module_rpc_name();

Methods

  • Returns void

  • Parameters

    • event: Events
    • Rest...args: any[]

    Returns boolean

  • Parameters

    • event: Events
    • Optionalhandler: HandlerFn

    Returns this

  • Parameters

    • event: Events
    • handler: HandlerFn

    Returns Unsub

  • Parameters

    • event: Events
    • handler: HandlerFn

    Returns Unsub