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: stringThe network to connect to.
readonly network: NetworkOptional timeout for requests in milliseconds (default: 20,000).
readonly timeout?: numberOptional configurations for the HTTP fetcher.
readonly fetcherConfigurations?: Agent.OptionsWhether to use threaded JSON parsing (default: false).
readonly useThreadedParsing?: booleanWhether to use threaded HTTP requests (default: false).
readonly useThreadedHttp?: booleanJSONRpcProvider 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
Creates a new JSONRpcProvider instance with the specified configuration.
constructor(config: JSONRpcProviderConfig)| Name | Type | Description |
|---|---|---|
| config | JSONRpcProviderConfig | The provider configuration. |
| Name | Type | Description |
|---|---|---|
| provider | JSONRpcProvider | A new JSONRpcProvider instance. |
The RPC endpoint URL used for all requests.
readonly url: string| Name | Type | Description |
|---|---|---|
| url | string | The formatted RPC endpoint URL. |
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.
close(): Promise<void>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.
_send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>| Name | Type | 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. |