Returns the UTXO manager instance associated with this provider.
Provider Abstraction Layer
AbstractRpcProvider Class
Providers share a common base class, AbstractRpcProvider, which defines the methods and properties that all provider implementations must adhere to. This base class provides a unified implementation of shared functionality while requiring derived classes to implement specific abstract methods according to their individual requirements.
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;
}Methods & Properties Reference
Properties
- utxoManager: UTXOsManager
Address Methods
Returns the CSV1 address for a given address. Results are cached internally for improved performance.
- address: Address
The address to get the CSV1 address for
- csv1Address: IP2WSHAddress - The CSV1 address
Returns the public key information for a given address.
Throws an error if the address is invalid.
- addressRaw: string | Address
The address to get the public key information of - isContract: boolean
Whether the address is a contract
- 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.
- 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
- 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.
- addresses: string | string[] | Address | Address[]
The address or addresses to get the public key information of
- publicKeyInfo: Promise<IPublicKeyInfoResult> - The raw public keys information from the API
Verifies an address and returns its type.
- addr: string | Address
The address to verify - network: Network
The network to verify the address against
- addressType: AddressTypes | null - The address type, returns null if the address is invalid
Block Methods
Returns the latest block number.
- blockNumber: Promise<bigint> - The latest block number
Returns a block by its number or hash.
Throws an error if the block is not found.
- blockNumberOrHash: BlockTag
The block number or hash - prefetchTxs: boolean
Whether to prefetch transactions
- block: Promise<Block> - The requested block
Returns multiple blocks by their numbers or hashes.
- blockNumbers: BlockTag[]
The block numbers or hashes - prefetchTxs: boolean
Whether to prefetch transactions
- 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.
- blockHash: string
The block hash
- block: Promise<Block> - The requested block
Returns a block by its checksum.
Throws an error if the block is not found.
- checksum: string
The block checksum - prefetchTxs: boolean
Whether to prefetch transactions
- 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.
- 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
- witnesses: Promise<BlockWitnesses> - The witnesses of the block
Balance Methods
Returns the bitcoin balance of an address.
- address: string | Address
The address to get the balance of - filterOrdinals: boolean
Whether to filter ordinals or not
- balance: Promise<bigint> - The balance of the address
Returns the bitcoin balances of multiple addresses in a single request.
- addressesLike: string[]
The addresses to get the balances of - filterOrdinals: boolean
Whether to filter ordinals or not
- balances: Promise<Record<string, bigint>> - The balances of the addresses
Transaction Methods
Returns a transaction by its hash or hash id.
Throws an error if something went wrong while fetching the transaction.
- txHash: string
The transaction hash
- 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.
- txHash: string
The transaction hash
- 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.
- tx: string
The raw transaction to send as hex string - psbt: boolean
Whether the transaction is a PSBT or not
- 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.
- txs: string[]
The raw transactions to send as hex strings
- results: Promise<BroadcastedTransaction[]> - The results of the transactions
Contract Methods
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.
- address: string | Address
The address of the contract - onlyBytecode: boolean
Whether to return only the bytecode
- 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.
- 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
- 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.
- 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
- result: Promise<CallResult | ICallRequestError> - The result of the contract function call
Network Methods
Returns the current connected network type.
Throws an error if the chain id is invalid.
- 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.
- 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.
- 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.
- fromBlock: BigNumberish
The block number to start from - toBlock: BigNumberish
The block number to end at
- 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.
- challenge: Promise<ChallengeSolution> - The challenge and epoch data
Epoch Methods
Returns the latest epoch in the OPNet protocol.
Throws an error if something went wrong while fetching the epoch.
- includeSubmissions: boolean
Whether to include submissions in the response
- 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.
- epochNumber: BigNumberish
The epoch number (-1 for latest) - includeSubmissions: boolean
Whether to include submissions in the response
- 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.
- epochHash: string
The epoch hash - includeSubmissions: boolean
Whether to include submissions in the response
- 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.
- 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.
- params: EpochSubmissionParams
The parameters for the epoch submission
- result: Promise<SubmittedEpoch> - The submission result
Payload Methods
Builds a JSON-RPC payload for a given method and parameters.
- method: T
The method to call - params: unknown[]
The parameters to send
- 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.
- payload: JsonRpcPayload
The payload to send
- result: Promise<JsonRpcResult> - The result of the payload
Sends multiple payloads to the node in a single request and returns the results.
- payloads: JsonRpcPayload[]
The payloads to send
- results: Promise<JsonRpcCallResult> - The results of the payloads
Abstract Methods
Abstract method that must be implemented by derived classes to send requests to the OPNet node. This method handles the actual network communication.
- payload: JsonRpcPayload | JsonRpcPayload[]
The payload or payloads to send
- 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.
- url: string
The URL to format
- url: string - The formatted provider URL