Returns the UTXO manager instance associated with this provider.
Provider Abstraction Layer
AbstractRpcProvider Class
Both JSONRpcProvider and WebSocketRpcProvider extend the AbstractRpcProvider base class, which defines the complete set of methods and properties available across all provider types. This shared base ensures a consistent API regardless of which provider you use.
Any future custom provider implementation must also extend AbstractRpcProvider and fulfill its abstract method contracts to remain compatible with the rest of the library.
interface ChallengeCache {
readonly challenge: ChallengeSolution;
readonly expireAt: number;
}
export abstract class AbstractRpcProvider {
protected constructor(public readonly network: Network);
public get utxoManager(): UTXOsManager;
public getCSV1ForAddress(address: Address): IP2WSHAddress;
public async getPublicKeyInfo(addressRaw: string | Address, isContract: boolean, ): Promise<Address>;
public validateAddress(addr: string | Address, network: Network): AddressTypes | null;
public async getBlockNumber(): Promise<bigint>;
public async getBlockByChecksum(checksum: string, prefetchTxs: boolean = false,): Promise<Block>;
public async getChallenge(): Promise<ChallengeSolution>;
public async getBlock(blockNumberOrHash: BlockTag, prefetchTxs: boolean = false,): Promise<Block>;
public async getBlocks(blockNumbers: BlockTag[], prefetchTxs: boolean = false,): Promise<Block[]>;
public async getBlockByHash(blockHash: string): Promise<Block>;
public async getBalance(address: string | Address, filterOrdinals: boolean = true,): Promise<bigint>;
public async getBalances(addressesLike: string[], filterOrdinals: boolean = true,): Promise<Record<string, bigint>>;
public async getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>>;
public async getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
public getNetwork(): Network;
public async getChainId(): Promise<bigint>;
public async getCode(address: string | Address, onlyBytecode: boolean = false,): Promise<ContractData | Buffer>;
public async getStorageAt(address: string | Address, rawPointer: bigint | string, proofs: boolean = true, height?: BigNumberish,): Promise<StoredValue>;
public async call(to: string | Address, data: Buffer | string, from?: Address,height?: BigNumberish, simulatedTransaction?: ParsedSimulatedTransaction, accessList?: IAccessList,): Promise<CallResult | ICallRequestError>;
public async gasParameters(): Promise<BlockGasParameters>;
public async sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>;
public async sendRawTransactions(txs: string[]): Promise<BroadcastedTransaction[]>;
public async getBlockWitness(height: BigNumberish = -1, trusted?: boolean, limit?: number, page?: number,): Promise<BlockWitnesses>;
public async getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish,): Promise<ReorgInformation[]>;
public abstract _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
public async callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult>;
public async callMultiplePayloads(payloads: JsonRpcPayload[]): Promise<JsonRpcCallResult>;
public buildJsonRpcPayload<T extends JSONRpcMethods>(method: T, params: unknown[],): JsonRpcPayload;
public async getPublicKeysInfoRaw(addresses: string | string[] | Address | Address[],): Promise<IPublicKeyInfoResult>;
public async getPublicKeysInfo(addresses: string | string[] | Address | Address[], isContract: boolean = false, logErrors: boolean = false,): Promise<AddressesInfo>;
public async getLatestEpoch(includeSubmissions: boolean): Promise<Epoch>;
public async getEpochByNumber(epochNumber: BigNumberish, includeSubmissions: boolean = false,): Promise<Epoch | EpochWithSubmissions>;
public async getEpochByHash(epochHash: string, includeSubmissions: boolean = false,): Promise<Epoch | EpochWithSubmissions>;
public async getEpochTemplate(): Promise<EpochTemplate>;
public async submitEpoch(params: EpochSubmissionParams): Promise<SubmittedEpoch>;
protected abstract providerUrl(url: string): string;
}Reference
get utxoManager(): UTXOsManager| Name | Type | Description |
|---|---|---|
| utxoManager | UTXOsManager | The associated UTXOs manager. |
Returns the CSV1 address for a given address. Results are cached internally for improved performance.
getCSV1ForAddress(address: Address): IP2WSHAddress| Name | Type | Description |
|---|---|---|
| address | Address | The address to get the CSV1 address for |
| Name | Type | Description |
|---|---|---|
| csv1Address | IP2WSHAddress | The CSV1 address. |
Returns the public key information for a given address.
Throws an error if the address is invalid.
getPublicKeyInfo(addressRaw: string | Address, isContract: boolean): Promise<Address>| Name | Type | Description |
|---|---|---|
| addressRaw | string | Address | The address to get the public key information of |
| isContract | boolean | Whether the address is a contract |
| Name | Type | Description |
|---|---|---|
| address | Promise<Address> | The public key information. |
Fetches public key information from the API and converts results to Address instances containing both ML-DSA (quantum-resistant) and classical key data when available. For addresses with ML-DSA keys registered, the returned Address will have the SHA256 hash of the ML-DSA public key as primary content and the classical tweaked/original public key for Bitcoin address derivation as the legacy key.
Throws an error if any provided address fails validation before the API call.
getPublicKeysInfo(addresses: string | string[] | Address | Address[], isContract?: boolean, logErrors?: boolean): Promise<AddressesInfo>| Name | Type | Description |
|---|---|---|
| addresses | string | string[] | Address | Address[] | The address(es) to look up. Accepts p2tr addresses, p2op addresses, raw public keys, or existing Address instances |
| isContract | boolean | When true, uses tweakedPubkey as the legacy key since contracts don't have original untweaked keys |
| logErrors | boolean | When true, logs errors to console for addresses that fail lookup instead of silently skipping them |
| Name | Type | Description |
|---|---|---|
| addressesInfo | Promise<AddressesInfo> | Map of input keys to Address instances. Keys that failed lookup are omitted. |
Returns the raw API response for public key information without transforming to Address objects.
Throws an error if the address is invalid or the API call fails.
getPublicKeysInfoRaw(addresses: string | string[] | Address | Address[]): Promise<IPublicKeyInfoResult>| Name | Type | Description |
|---|---|---|
| addresses | string | string[] | Address | Address[] | The address or addresses to get the public key information of |
| Name | Type | Description |
|---|---|---|
| publicKeyInfo | Promise<IPublicKeyInfoResult> | The raw public keys information from the API |
Verifies an address and returns its type.
validateAddress(addr: string | Address, network: Network): AddressTypes | null| Name | Type | Description |
|---|---|---|
| addr | string | Address | The address to verify |
| network | Network | The network to verify the address against |
| Name | Type | Description |
|---|---|---|
| addressType | AddressTypes | null | The address type, returns null if the address is invalid. |
Returns the latest block number.
getBlockNumber(): Promise<bigint>| Name | Type | Description |
|---|---|---|
| blockNumber | Promise<bigint> | The latest block number. |
Returns a block by its number or hash.
Throws an error if the block is not found.
getBlock(blockNumberOrHash: BlockTag, prefetchTxs?: boolean): Promise<Block>| Name | Type | Description |
|---|---|---|
| blockNumberOrHash | BlockTag | The block number or hash |
| prefetchTxs | boolean | Whether to prefetch transactions. |
| Name | Type | Description |
|---|---|---|
| block | Promise<Block> | The requested block. |
Returns multiple blocks by their numbers or hashes.
getBlocks(blockNumbers: BlockTag[], prefetchTxs?: boolean): Promise<Block[]>| Name | Type | Description |
|---|---|---|
| blockNumbers | BlockTag[] | The block numbers or hashes |
| prefetchTxs | boolean | Whether to prefetch transactions |
| Name | Type | Description |
|---|---|---|
| blocks | Promise<Block[]> | The requested blocks. |
Returns a block by its hash. This method is an alias for getBlock().
Throws an error if the block is not found.
getBlockByHash(blockHash: string): Promise<Block>| Name | Type | Description |
|---|---|---|
| blockHash | string | The block hash |
| Name | Type | Description |
|---|---|---|
| block | Promise<Block> | The requested block. |
Returns a block by its checksum.
Throws an error if the block is not found.
getBlockByChecksum(checksum: string, prefetchTxs?: boolean): Promise<Block>| Name | Type | Description |
|---|---|---|
| checksum | string | The block checksum |
| prefetchTxs | boolean | Whether to prefetch transactions |
| Name | Type | Description |
|---|---|---|
| block | Promise<Block> | The requested block. |
Returns the witnesses of a block. This proves that the actions executed inside a block are valid and confirmed by the network. If the minimum number of witnesses are not met, the block is considered as potentially invalid.
Throws an error if something went wrong while fetching the witnesses.
getBlockWitness(height?: BigNumberish, trusted?: boolean, limit?: number, page?: number): Promise<BlockWitnesses>| Name | Type | Description |
|---|---|---|
| height | BigNumberish | The block number or hash, use -1 for latest block |
| trusted | boolean | Whether to trust the witnesses or not |
| limit | number | The maximum number of witnesses to return |
| page | number | The page number of the witnesses |
| Name | Type | Description |
|---|---|---|
| witnesses | Promise<BlockWitnesses> | The witnesses of the block. |
Returns the bitcoin balance of an address.
getBalance(address: string | Address, filterOrdinals?: boolean): Promise<bigint>| Name | Type | Description |
|---|---|---|
| address | string | Address | The address to get the balance of |
| filterOrdinals | boolean | Whether to filter ordinals or not |
| Name | Type | Description |
|---|---|---|
| balance | Promise<bigint> | The balance of the address. |
Returns the bitcoin balances of multiple addresses in a single request.
getBalances(addressesLike: string[], filterOrdinals?: boolean): Promise<Record<string, bigint>>| Name | Type | Description |
|---|---|---|
| addressesLike | string[] | The addresses to get the balances of |
| filterOrdinals | boolean | Whether to filter ordinals or not |
| Name | Type | Description |
|---|---|---|
| balances | Promise<Record<string, bigint>> | The balances of the addresses. |
Returns a transaction by its hash or hash id.
Throws an error if something went wrong while fetching the transaction.
getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>>| Name | Type | Description |
|---|---|---|
| txHash | string | The transaction hash |
| Name | Type | Description |
|---|---|---|
| transaction | Promise<TransactionBase<OPNetTransactionTypes>> | The requested transaction. |
Returns a transaction receipt by its hash.
Throws an error if something went wrong while fetching the transaction receipt.
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>| Name | Type | Description |
|---|---|---|
| txHash | string | The transaction hash |
| Name | Type | Description |
|---|---|---|
| receipt | Promise<TransactionReceipt> | The requested transaction receipt. |
Sends a raw transaction to the network.
Throws an error if the hex string is invalid or if something went wrong while sending the transaction.
sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>| Name | Type | Description |
|---|---|---|
| tx | string | The raw transaction to send as hex string |
| psbt | boolean | Whether the transaction is a PSBT or not |
| Name | Type | Description |
|---|---|---|
| result | Promise<BroadcastedTransaction> | The result of the transaction. |
Sends multiple raw transactions to the network in a single request.
Throws an error if something went wrong while sending the transactions.
sendRawTransactions(txs: string[]): Promise<BroadcastedTransaction[]>| Name | Type | Description |
|---|---|---|
| txs | string[] | The raw transactions to send as hex strings |
| Name | Type | Description |
|---|---|---|
| results | Promise<BroadcastedTransaction[]> | The results of the transactions. |
Returns the contract code of an address. When onlyBytecode is true, returns only the bytecode as a Buffer; otherwise returns the full ContractData object.
Throws an error if something went wrong while fetching the contract code.
getCode(address: string | Address, onlyBytecode?: boolean): Promise<ContractData | Buffer>| Name | Type | Description |
|---|---|---|
| address | string | Address | The address of the contract |
| onlyBytecode | boolean | Whether to return only the bytecode |
| Name | Type | Description |
|---|---|---|
| code | Promise<ContractData | Buffer> | The contract data or bytecode. |
Returns the storage value at a specific address and pointer.
Throws an error if something went wrong while fetching the storage.
getStorageAt(address: string | Address, rawPointer: bigint | string, proofs?: boolean, height?: BigNumberish): Promise<StoredValue>| Name | Type | Description |
|---|---|---|
| address | string | Address | The address to get the storage from |
| rawPointer | bigint | string | The pointer to get the storage from as base64 or bigint |
| proofs | boolean | Whether to send proofs or not |
| height | BigNumberish | The height to get the storage from |
| Name | Type | Description |
|---|---|---|
| value | Promise<StoredValue> | The storage value. |
Calls a contract function with a given calldata. Returns the result of the contract function call or an error object if the call reverts.
Throws an error if something went wrong while calling the contract.
call(to: string | Address, data: Buffer | string, from?: Address, height?: BigNumberish, simulatedTransaction?: ParsedSimulatedTransaction, accessList?: IAccessList): Promise<CallResult | ICallRequestError>| Name | Type | Description |
|---|---|---|
| to | string | Address | The address of the contract |
| data | Buffer | string | The calldata of the contract function |
| from | Address | The address to call the contract from |
| height | BigNumberish | The height to call the contract from |
| simulatedTransaction | ParsedSimulatedTransaction | UTXOs to simulate the transaction |
| accessList | IAccessList | The access list of previous simulation to use for this call |
| Name | Type | Description |
|---|---|---|
| result | Promise<CallResult | ICallRequestError> | The result of the contract function call. |
Returns the current connected network type.
Throws an error if the chain id is invalid.
getNetwork(): Network| Name | Type | Description |
|---|---|---|
| network | Network | The current connected network type. |
Returns the chain id. The result is cached internally after the first call.
Throws an error if something went wrong while fetching the chain id.
getChainId(): Promise<bigint>| Name | Type | Description |
|---|---|---|
| chainId | Promise<bigint> | The chain id. |
Returns the next block gas parameters including base gas, gas limit, and gas price. Results are cached for 10 seconds.
Throws an error if something went wrong while fetching the gas parameters.
gasParameters(): Promise<BlockGasParameters>| Name | Type | Description |
|---|---|---|
| gasParams | Promise<BlockGasParameters> | The gas parameters of the next block. |
Returns information about blockchain reorganizations that occurred between two blocks.
Throws an error if something went wrong while fetching the reorg information.
getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish): Promise<ReorgInformation[]>| Name | Type | Description |
|---|---|---|
| fromBlock | BigNumberish | The block number to start from |
| toBlock | BigNumberish | The block number to end at |
| Name | Type | Description |
|---|---|---|
| reorgs | Promise<ReorgInformation[]> | The reorg information. |
Returns the latest challenge to use in a transaction along with epoch winner and verification data. Results are cached for 10 seconds.
Throws an error if no challenge is found or if OPNet is not active on the blockchain.
getChallenge(): Promise<ChallengeSolution>| Name | Type | Description |
|---|---|---|
| challenge | Promise<ChallengeSolution> | The challenge and epoch data. |
Returns the latest epoch in the OPNet protocol.
Throws an error if something went wrong while fetching the epoch.
getLatestEpoch(includeSubmissions: boolean): Promise<Epoch>| Name | Type | Description |
|---|---|---|
| includeSubmissions | boolean | Whether to include submissions in the response |
| Name | Type | Description |
|---|---|---|
| epoch | Promise<Epoch> | The latest epoch. |
Returns an epoch by its number. Use -1 to get the latest epoch. When includeSubmissions is true, returns an EpochWithSubmissions instance.
Throws an error if something went wrong while fetching the epoch.
getEpochByNumber(epochNumber: BigNumberish, includeSubmissions?: boolean): Promise<Epoch | EpochWithSubmissions>| Name | Type | Description |
|---|---|---|
| epochNumber | BigNumberish | The epoch number (-1 for latest) |
| includeSubmissions | boolean | Whether to include submissions in the response |
| Name | Type | Description |
|---|---|---|
| epoch | Promise<Epoch | EpochWithSubmissions> | The requested epoch. |
Returns an epoch by its hash. When includeSubmissions is true, returns an EpochWithSubmissions instance.
Throws an error if something went wrong while fetching the epoch.
getEpochByHash(epochHash: string, includeSubmissions?: boolean): Promise<Epoch | EpochWithSubmissions>| Name | Type | Description |
|---|---|---|
| epochHash | string | The epoch hash |
| includeSubmissions | boolean | Whether to include submissions in the response |
| Name | Type | Description |
|---|---|---|
| epoch | Promise<Epoch | EpochWithSubmissions> | The requested epoch. |
Returns the current epoch mining template with target hash and requirements.
Throws an error if something went wrong while fetching the template.
getEpochTemplate(): Promise<EpochTemplate>| Name | Type | Description |
|---|---|---|
| template | Promise<EpochTemplate> | The epoch template. |
Submits a new epoch solution. This method is used to submit a SHA-1 collision solution for epoch mining.
Throws an error if something went wrong while submitting the epoch.
submitEpoch(params: EpochSubmissionParams): Promise<SubmittedEpoch>| Name | Type | Description |
|---|---|---|
| params | EpochSubmissionParams | The parameters for the epoch submission |
| Name | Type | Description |
|---|---|---|
| result | Promise<SubmittedEpoch> | The submission result. |
Builds a JSON-RPC payload for a given method and parameters.
buildJsonRpcPayload<T extends JSONRpcMethods>(method: T, params: unknown[]): JsonRpcPayload| Name | Type | Description |
|---|---|---|
| method | T | The method to call |
| params | unknown[] | The parameters to send |
| Name | Type | Description |
|---|---|---|
| payload | JsonRpcPayload | The JSON RPC payload. |
Sends a single payload to the node and returns the result.
Throws an error if no data is returned.
callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult>| Name | Type | Description |
|---|---|---|
| payload | JsonRpcPayload | The payload to send |
| Name | Type | Description |
|---|---|---|
| result | Promise<JsonRpcResult> | The result of the payload. |
Sends multiple payloads to the node in a single request and returns the results.
callMultiplePayloads(payloads: JsonRpcPayload[]): Promise<JsonRpcCallResult>| Name | Type | Description |
|---|---|---|
| payloads | JsonRpcPayload[] | The payloads to send |
| Name | Type | Description |
|---|---|---|
| results | Promise<JsonRpcCallResult> | The results of the payloads. |
Abstract method that must be implemented by derived classes to send requests to the OPNet node. This method handles the actual network communication.
abstract _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>| Name | Type | Description |
|---|---|---|
| payload | JsonRpcPayload | JsonRpcPayload[] | The payload or payloads to send |
| Name | Type | Description |
|---|---|---|
| result | Promise<JsonRpcCallResult> | The result of the request. |
Abstract method that must be implemented by derived classes to format the provider URL according to their specific requirements.
protected abstract providerUrl(url: string): string| Name | Type | Description |
|---|---|---|
| url | string | The URL to format |
| Name | Type | Description |
|---|---|---|
| url | string | The formatted provider URL. |