JSON RPC Provider Implementation

JSONRpcProvider Class

The JSONRpcProvider class extends AbstractRpcProvider to provide HTTP-based JSON-RPC communication with OP_NET nodes.

JSONRpcProvidertypescript
export class JSONRpcProvider extends AbstractRpcProvider {
    public readonly url: string;

    constructor(
        url: string,
        network: Network,
        private readonly timeout: number = 20_000,
        private readonly fetcherConfigurations: Agent.Options = {
            keepAliveTimeout: 30_000,
            keepAliveTimeoutThreshold: 30_000,
            connections: 128,
            pipelining: 2,
        },
        private useRESTAPI: boolean = true,
        private readonly useThreadedParsing: boolean = false,
        private readonly useThreadedHttp: boolean = false,
    );

    public async close(): Promise<void>;
    public setFetchMode(useRESTAPI: boolean);
    public async _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
    protected providerUrl(url: string): string;
}

Methods & Properties Reference

Constructor

constructor(url: string, network: Network, timeout?: number, fetcherConfigurations?: Agent.Options, useRESTAPI?: boolean, useThreadedParsing?: boolean, useThreadedHttp?: boolean)

Properties

readonly url: string

Methods

close(): Promise<void>
setFetchMode(useRESTAPI: boolean): void
_send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>
protected providerUrl(url: string): string