Crate near_jsonrpc_client

source ·
Expand description

Lower-level API for interfacing with the NEAR Protocol via JSONRPC.

§Layout

Each one the valid public JSON RPC methods are pre-defined in specialized modules within the methods module.

Inside every method module (e.g methods::query) there’s;

Calling a constructed request on a client returns with the response and error types for that method.

§Examples

  1. Request server status from testnet RPC

    use near_jsonrpc_client::{methods, JsonRpcClient};
    
    let client = JsonRpcClient::connect("https://rpc.testnet.near.org");
    
    let request = methods::status::RpcStatusRequest; // no params
    
    // call a method on the server via the connected client
    let server_status = client.call(request).await?;
    
    println!("{:?}", server_status);
  2. Query transaction status from mainnet RPC

    use near_jsonrpc_client::{methods, JsonRpcClient};
    use near_jsonrpc_primitives::types::transactions::TransactionInfo;
    use near_primitives::views::TxExecutionStatus;
    
    let client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
    
    let tx_status_request = methods::tx::RpcTransactionStatusRequest {
        transaction_info: TransactionInfo::TransactionId {
            tx_hash: "9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U".parse()?,
            sender_account_id: "miraclx.near".parse()?,
        },
        wait_until: TxExecutionStatus::Executed,
    };
    
    let tx_status = client.call(tx_status_request).await?;
    
    println!("{:?}", tx_status);

Modules§

  • Helpers for client authentication.
  • Error types.
  • Client headers.
  • This module contains all the RPC methods.

Structs§

Constants§

Traits§

Type Aliases§