Setting Up HTTP Connections
Creating a JSONRpcProvider
To create a new JSONRpcProvider, instantiate the class by calling its constructor. You can pass optional parameters to customize the provider's behavior.
For advanced setup and configuration options, refer to the Configuring JSON RPC section.
Default Configuration
typescript
Instantiate with Default Configuration
import { JSONRpcProvider } from 'opnet';
import { networks } from '@btc-vision/bitcoin';
const provider = new JSONRpcProvider({
url: 'https://regtest.opnet.org',
network: networks.regtest
});Specifying Custom Timeout
typescript
Instantiate Specifying a Timeout
import { JSONRpcProvider } from 'opnet';
import { networks } from '@btc-vision/bitcoin';
const provider = new JSONRpcProvider({
url: 'https://regtest.opnet.org',
network: networks.regtest,
timeout: 30_000 // 30 second timeout
});Network Configuration
Each OP_NET network has a dedicated RPC endpoint. Use the appropriate URL when initializing your provider based on your target environment.
| Network Name | Endpoint URL | Network | Description |
|---|---|---|---|
| Mainnet | https://mainnet.opnet.org | networks.bitcoin | Production network. |
| Regtest | https://regtest.opnet.org | networks.regtest | Development and testing. |