Skip to content

createJsonRpcFetcherLegacy

createJsonRpcFetcherLegacy(url, headers, retries?): JsonRpcClient & object

Makes a JSON-RPC request to a url

Parameters

url: string

to JSON RPC backend

headers: HeadersInit= undefined

to send with the request

retries?: number= 3

defaults to 3

Returns

JsonRpcClient & object

the result field from the JSON-RPC response

See

https://ethereum.org/en/developers/docs/apis/json-rpc/

Example

const url = 'https://mainnet.optimism.io'
const params = {
method: 'eth_getBlockByNumber',
params: ['latest', false],
}
const {result: block} = await fetchJsonRpc(url, params)

Source

packages/jsonrpc/src/fetchJsonRpcLegacy.js:20