import type { BlockReference, RpcRetryConfigInput } from "../config-schemas.js"; import type { AccessKeyListResponse, AccessKeyView, AccountView, BlockEffectsResponse, BlockView, ContractCodeView, FinalExecutionOutcomeMap, FinalExecutionOutcomeWithReceiptsMap, GasKeyNoncesResponse, GasPriceResponse, GenesisConfigResponse, GlobalContractReference, MaintenanceWindowsResponse, ReceiptToTxResponse, StateItem, StatusResponse, ViewFunctionCallResult, ViewStateResult } from "../types.js"; export interface RpcRequest { jsonrpc: "2.0"; id: string | number; method: string; params: unknown; } export interface RpcResponse { jsonrpc: "2.0"; id: string | number; result?: T; error?: { name: string; code: number; message: string; data?: string; cause?: { name: string; info?: Record; }; }; } export interface RpcRetryConfig { maxRetries: number; initialDelayMs: number; } /** * Low-level JSON-RPC client for NEAR Protocol. * * @remarks * Most applications should use {@link Near} instead of interacting with this * class directly. `RpcClient` is exposed for advanced use cases that need full * control over RPC calls or access to methods not wrapped by `Near`. */ export declare class RpcClient { private readonly url; private readonly headers; private requestId; private readonly retryConfig; constructor(url: string, headers?: Record, retryConfig?: RpcRetryConfigInput); /** * Sleep for the specified number of milliseconds. * @internal */ private sleep; /** * Perform a raw JSON-RPC call with automatic retries and error mapping. * * @param method - RPC method name (e.g. `"query"`, `"status"`). * @param params - RPC params object or array. * * @returns Parsed JSON result typed as `T`. * * @throws {NetworkError} On HTTP failures, network issues, or malformed responses. * @throws {InvalidTransactionError} For transaction failures detected by {@link parseRpcError}. * @throws {NearError} For other RPC-level errors. */ call(method: string, params: unknown): Promise; /** * Perform a generic `query` RPC call. * * @param path - `request_type` (e.g. `"view_account"`, `"view_access_key"`). * @param data - Raw args as base64 string or bytes. */ query(path: string, data: string | Uint8Array): Promise; /** * Call a contract view function via RPC. * * @param contractId - Account ID of the target contract. * @param methodName - Name of the view method. * @param args - Arguments object or raw bytes; defaults to `{}`. * @param options - Optional {@link BlockReference} to control finality or block. */ viewFunction(contractId: string, methodName: string, args?: unknown, options?: BlockReference): Promise; /** * Get basic account information via `view_account`. * * @param accountId - Account ID to query. * @param options - Optional {@link BlockReference} to control finality or block. */ getAccount(accountId: string, options?: BlockReference): Promise; /** * Get the WASM code deployed on an account via `view_code`. * * @param accountId - Account whose contract code to fetch. * @param options - Optional {@link BlockReference} to control finality or block. * * @returns The base64-encoded code and its base58 SHA-256 hash. * * @throws {ContractNotDeployedError} If the account has no contract deployed. * @throws {AccountDoesNotExistError} If the account does not exist. */ viewCode(accountId: string, options?: BlockReference): Promise; /** * Get a published global contract's code via `view_global_contract_code` * (by code hash) or `view_global_contract_code_by_account_id` (by * publishing account). Requires nearcore >= 2.7. * * @param contract - {@link GlobalContractReference}: `{ codeHash }` or `{ accountId }`. * @param options - Optional {@link BlockReference} to control finality or block. * * @returns The base64-encoded code and its base58 SHA-256 hash. * * @throws {GlobalContractNotFoundError} If no code is published under the identifier. */ viewGlobalContractCode(contract: GlobalContractReference, options?: BlockReference): Promise; /** * Get an access key via `view_access_key`. * * @param accountId - Account ID that owns the key. * @param publicKey - Public key string (e.g. `"ed25519:..."`). * @param options - Optional {@link BlockReference} to control finality or block. */ getAccessKey(accountId: string, publicKey: string, options?: BlockReference): Promise; /** * Get all access keys for an account via `view_access_key_list`. * * @param accountId - Account ID to list keys for. * @param options - Optional {@link BlockReference} to control finality or block. */ getAccessKeys(accountId: string, options?: BlockReference): Promise; /** * Get a gas key's per-lane nonces via `view_gas_key_nonces` (nearcore 2.13). * * A gas key funds several parallel nonce lanes (`num_nonces` slots) so it can * sign multiple transactions concurrently; this returns the current `u64` * nonce of each lane, indexed by lane, plus the block the query was answered * against. Throws {@link AccessKeyDoesNotExistError} if `publicKey` is not a * gas key on `accountId`. * * @param accountId - Account ID that owns the gas key. * @param publicKey - Gas key public key string (e.g. `"ed25519:..."`). * @param options - Optional {@link BlockReference} to control finality or block. */ getGasKeyNonces(accountId: string, publicKey: string, options?: BlockReference): Promise; /** * Send a signed transaction via `send_tx`. * * @param signedTransaction - Borsh-serialized signed transaction bytes. * @param waitUntil - Execution status level to wait for (see {@link TxExecutionStatus}). */ sendTransaction(signedTransaction: Uint8Array, waitUntil?: W): Promise; /** * Query transaction status with receipts via `EXPERIMENTAL_tx_status`. * * @param txHash - Transaction hash. * @param senderAccountId - Account ID that sent the transaction. * @param waitUntil - Execution status level to wait for. */ getTransactionStatus(txHash: string, senderAccountId: string, waitUntil?: W): Promise; /** * Map a receipt back to its originating transaction via * `EXPERIMENTAL_receipt_to_tx`. * * @remarks * This is an experimental endpoint and requires nearcore >= 2.12. It looks up * the transaction that produced the given receipt and returns the transaction * hash and sender account ID. * * @param receiptId - Receipt ID (CryptoHash, base58) to look up. * * @returns The originating transaction's hash and sender account ID. * * @throws {UnknownReceiptError} If the receipt is not known to the node. * @throws {NetworkError} If the network request failed. */ receiptToTx(receiptId: string): Promise; /** * Get node status via `status`. */ getStatus(): Promise; /** * Get block information via `block`. * * @param options - Block reference specifying which block to fetch. * Use `{ finality: "final" }` for the latest finalized block, * `{ finality: "optimistic" }` for the latest block, * or `{ blockId: }` for a specific block. * * @example * ```typescript * // Get latest finalized block (recommended for transactions) * const block = await rpc.getBlock({ finality: "final" }) * * // Get latest optimistic block * const block = await rpc.getBlock({ finality: "optimistic" }) * * // Get specific block by height * const block = await rpc.getBlock({ blockId: 12345 }) * * // Get specific block by hash * const block = await rpc.getBlock({ blockId: "ABC123..." }) * ``` */ getBlock(options?: BlockReference): Promise; /** * Get gas price via `gas_price`. * * @param blockId - Optional block hash or height; `null` for latest. */ getGasPrice(blockId?: string | null): Promise; /** * Read a single page of contract state via `view_state`. * * Returns key/value entries (base64-encoded) whose keys start with `prefix`. * When the result has a `last_key`, more entries remain: pass it as * `options.afterKey` to fetch the next page, or use {@link viewStateAll} to * iterate every page automatically. * * @param accountId - Account whose contract state to read. * @param options - Optional pagination and block reference. * @param options.prefix - Base64 key prefix to filter by (default: all keys). * @param options.afterKey - Base64 continuation cursor from a prior `last_key`. * @param options.limit - Maximum number of entries to return. * @param options.includeProof - Request Merkle inclusion proofs. * * @example * ```typescript * const page = await rpc.viewState("contract.near", { limit: 100 }) * for (const { key, value } of page.values) { ... } * if (page.last_key) { * const next = await rpc.viewState("contract.near", { afterKey: page.last_key }) * } * ``` */ viewState(accountId: string, options?: BlockReference & { prefix?: string; afterKey?: string; limit?: number; includeProof?: boolean; }): Promise; /** * Iterate all contract state entries via `view_state`, following the * `last_key` cursor across pages until exhausted. * * Yields one {@link StateItem} at a time so large state can be streamed * without buffering it all in memory. * * @param accountId - Account whose contract state to read. * @param options - Optional `prefix`, per-request `limit`, and block reference. * * @example * ```typescript * for await (const { key, value } of rpc.viewStateAll("contract.near", { limit: 100 })) { * // process each entry * } * ``` */ viewStateAll(accountId: string, options?: BlockReference & { prefix?: string; limit?: number; }): AsyncGenerator; /** * Get the kinds of state changes in a block via `block_effects` * (stabilized in nearcore 2.13; falls back to the `EXPERIMENTAL_changes_in_block` * alias on older nodes). * * @param options - Block reference. Defaults to the latest final block. */ blockEffects(options?: BlockReference): Promise; /** * Get the network genesis configuration via `genesis_config` (stabilized in * nearcore 2.13; falls back to the `EXPERIMENTAL_genesis_config` alias on * older nodes). */ genesisConfig(): Promise; /** * Get the upcoming maintenance windows (half-open block-height ranges) for a * validator account via `maintenance_windows` (stabilized in nearcore 2.13; * falls back to the `EXPERIMENTAL_maintenance_windows` alias on older nodes). * * @param accountId - Validator account ID. */ maintenanceWindows(accountId: string): Promise; /** * Call a method that was stabilized (renamed without the `EXPERIMENTAL_` * prefix) in a recent protocol version, retrying with the legacy * `EXPERIMENTAL_` alias if the node does not recognize the new name. * @internal */ private callWithExperimentalFallback; } //# sourceMappingURL=rpc.d.ts.map