Skip to content

RpcRequest

Utility types & functions for working with JSON-RPC 2.0 Requests and Ethereum JSON-RPC methods as defined on the Ethereum API specification

Examples

Instantiating a Request Store

A Request Store can be instantiated using RpcRequest.createStore:

import { RpcRequest } from 'ox'
 
const store = RpcRequest.createStore()
 
const request_1 = store.prepare({
  method: 'eth_blockNumber',
})
{ id: 0, jsonrpc: '2.0', method: 'eth_blockNumber' }
const request_2 = store.prepare({ method: 'eth_call', params: [ { to: '0x0000000000000000000000000000000000000000', data: '0xdeadbeef', }, ], })
{ id: 1, jsonrpc: '2.0', method: 'eth_call', params: [{ to: '0x0000000000000000000000000000000000000000', data: '0xdeadbeef' }] }

Functions

NameDescription
RpcRequest.createStoreCreates a JSON-RPC request store to build requests with an incrementing id.
RpcRequest.fromA type-safe interface to build a JSON-RPC request object as per the JSON-RPC 2.0 specification.

Types

NameDescription
RpcRequest.RpcRequestA JSON-RPC request object as per the JSON-RPC 2.0 specification.
RpcRequest.StoreJSON-RPC request store type.