pub struct RpcClient { /* private fields */ }Expand description
Low-level JSON-RPC client for NEAR.
Implementations§
Source§impl RpcClient
impl RpcClient
Sourcepub fn with_retry_config(
url: impl Into<String>,
retry_config: RetryConfig,
) -> Self
pub fn with_retry_config( url: impl Into<String>, retry_config: RetryConfig, ) -> Self
Create a new RPC client with custom retry configuration.
Sourcepub async fn call<P: Serialize, R: DeserializeOwned>(
&self,
method: &str,
params: P,
) -> Result<R, RpcError>
pub async fn call<P: Serialize, R: DeserializeOwned>( &self, method: &str, params: P, ) -> Result<R, RpcError>
Make a raw RPC call with retries.
Sourcepub async fn view_account(
&self,
account_id: &AccountId,
block: BlockReference,
) -> Result<AccountView, RpcError>
pub async fn view_account( &self, account_id: &AccountId, block: BlockReference, ) -> Result<AccountView, RpcError>
View account information.
Sourcepub async fn view_access_key(
&self,
account_id: &AccountId,
public_key: &PublicKey,
block: BlockReference,
) -> Result<AccessKeyView, RpcError>
pub async fn view_access_key( &self, account_id: &AccountId, public_key: &PublicKey, block: BlockReference, ) -> Result<AccessKeyView, RpcError>
View access key information.
Sourcepub async fn view_access_key_list(
&self,
account_id: &AccountId,
block: BlockReference,
) -> Result<AccessKeyListView, RpcError>
pub async fn view_access_key_list( &self, account_id: &AccountId, block: BlockReference, ) -> Result<AccessKeyListView, RpcError>
View all access keys for an account.
Sourcepub async fn view_function(
&self,
account_id: &AccountId,
method_name: &str,
args: &[u8],
block: BlockReference,
) -> Result<ViewFunctionResult, RpcError>
pub async fn view_function( &self, account_id: &AccountId, method_name: &str, args: &[u8], block: BlockReference, ) -> Result<ViewFunctionResult, RpcError>
Call a view function on a contract.
Sourcepub async fn block(&self, block: BlockReference) -> Result<BlockView, RpcError>
pub async fn block(&self, block: BlockReference) -> Result<BlockView, RpcError>
Get block information.
Sourcepub async fn status(&self) -> Result<StatusResponse, RpcError>
pub async fn status(&self) -> Result<StatusResponse, RpcError>
Get node status.
Sourcepub async fn gas_price(
&self,
block_hash: Option<&CryptoHash>,
) -> Result<GasPrice, RpcError>
pub async fn gas_price( &self, block_hash: Option<&CryptoHash>, ) -> Result<GasPrice, RpcError>
Get current gas price.
Sourcepub async fn send_tx(
&self,
signed_tx: &SignedTransaction,
wait_until: TxExecutionStatus,
) -> Result<SendTxResponse, RpcError>
pub async fn send_tx( &self, signed_tx: &SignedTransaction, wait_until: TxExecutionStatus, ) -> Result<SendTxResponse, RpcError>
Send a signed transaction.
Sourcepub async fn tx_status(
&self,
tx_hash: &CryptoHash,
sender_id: &AccountId,
wait_until: TxExecutionStatus,
) -> Result<SendTxWithReceiptsResponse, RpcError>
pub async fn tx_status( &self, tx_hash: &CryptoHash, sender_id: &AccountId, wait_until: TxExecutionStatus, ) -> Result<SendTxWithReceiptsResponse, RpcError>
Get transaction status with full receipt details.
Uses EXPERIMENTAL_tx_status which returns complete receipt information.
Sourcepub async fn sandbox_fast_forward(
&self,
delta_height: u64,
) -> Result<(), RpcError>
pub async fn sandbox_fast_forward( &self, delta_height: u64, ) -> Result<(), RpcError>
Patch account state in sandbox.
This is a sandbox-only method that allows modifying account state directly, useful for testing scenarios that require specific account configurations (e.g., setting a high balance for staking tests).
§Arguments
records- State records to patch (Account, Data, Contract, AccessKey, etc.)
§Example
// Set account balance to 1M NEAR
rpc.sandbox_patch_state(serde_json::json!([
{
"Account": {
"account_id": "alice.sandbox",
"account": {
"amount": "1000000000000000000000000000000",
"locked": "0",
"code_hash": "11111111111111111111111111111111",
"storage_usage": 182
}
}
}
])).await?;Fast-forward the sandbox by delta_height blocks.
This is useful for testing time-dependent logic (e.g., lockups, staking epoch changes) without waiting for real block production.
Note: This can take a while for large deltas — the sandbox node internally produces all intermediate blocks. The RPC call will block until fast-forwarding completes (up to 1 hour server-side timeout).
§Example
// Advance the sandbox by 1000 blocks
rpc.sandbox_fast_forward(1000).await?;