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.

typescript
AbstractRpcProvider Class - Simplified
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

utxoManager
getCSV1ForAddress
getPublicKeyInfo
getPublicKeysInfo
getPublicKeysInfoRaw
validateAddress
getBlockNumber
getBlock
getBlocks
getBlockByHash
getBlockByChecksum
getBlockWitness
getBalance
getBalances
getTransaction
getTransactionReceipt
sendRawTransaction
sendRawTransactions
getCode
getStorageAt
call
getNetwork
getChainId
gasParameters
getReorg
getChallenge
getLatestEpoch
getEpochByNumber
getEpochByHash
getEpochTemplate
submitEpoch
buildJsonRpcPayload
callPayloadSingle
callMultiplePayloads
_send
providerUrl