The URL of the JSON RPC provider.
JSON RPC Provider Implementation
JSONRpcProviderConfig Interface
The JSONRpcProviderConfig interface defines the complete set of options accepted by the JSONRpcProvider constructor. Only url and network are required; all other fields are optional and fall back to default values when omitted.
export interface JSONRpcProviderConfig {
readonly url: string;
readonly network: Network;
readonly timeout?: number;
readonly fetcherConfigurations?: Agent.Options;
readonly useThreadedParsing?: boolean;
readonly useThreadedHttp?: boolean;
}Reference
readonly url: stringreadonly network: NetworkThe network to connect to.
readonly timeout?: numberOptional timeout for requests in milliseconds (default: 20,000).
readonly fetcherConfigurations?: Agent.OptionsOptional configurations for the HTTP fetcher.
readonly useThreadedParsing?: booleanWhether to use threaded JSON parsing (default: false).
readonly useThreadedHttp?: booleanWhether to use threaded HTTP requests (default: false).
JSONRpcProvider Class
The JSONRpcProvider class extends AbstractRpcProvider to provide HTTP-based JSON-RPC communication with OP_NET nodes.
export class JSONRpcProvider extends AbstractRpcProvider {
public readonly url: string;
constructor(config: JSONRpcProviderConfig);
public async close(): Promise<void>;
public async _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
}Reference
constructor(config: JSONRpcProviderConfig)Creates a new JSONRpcProvider instance with the specified configuration.
| Name | Type | Required | Description |
|---|---|---|---|
| config | JSONRpcProviderConfig | - | The provider configuration. |
| Name | Type | Description |
|---|---|---|
| provider | JSONRpcProvider | A new JSONRpcProvider instance. |
readonly url: stringThe RPC endpoint URL used for all requests.
| Name | Type | Description |
|---|---|---|
| url | string | The formatted RPC endpoint URL. |
close(): Promise<void>Closes the provider and releases all associated resources including HTTP connections. This method should be called when the provider is no longer needed to prevent resource leaks.
_send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>Sends a JSON-RPC payload to the provider. This method implements the abstract _send() method from AbstractRpcProvider. When threaded HTTP is enabled, the entire request runs in a worker thread. Otherwise, the request runs on the main thread with optional threaded JSON parsing.
Throws an error if no data is fetched or if the request times out.
| Name | Type | Required | Description |
|---|---|---|---|
| payload | JsonRpcPayload | JsonRpcPayload[] | - | The JSON-RPC payload or array of payloads to send. |
| Name | Type | Description |
|---|---|---|
| result | Promise<JsonRpcCallResult> | The result of the JSON-RPC call. |