Lower-level API for interfacing with the NEAR Protocol via JSONRPC.
Each one of the valid JSON RPC methods are defined in the methods
module.
For instance, to make a tx
request, you start with the tx
module
and construct a request using the methods::tx::RpcTransactionStatusRequest
struct.
```rust use nearjsonrpcclient::{methods, JsonRpcClient}; use nearjsonrpcprimitives::types::transactions::TransactionInfo;
let mainnet_client = JsonRpcClient::connect("https://archival-rpc.mainnet.near.org");
let txstatusrequest = methods::tx::RpcTransactionStatusRequest { transactioninfo: TransactionInfo::TransactionId { hash: "9FtHUFBQsZ2MG77K3x3MJ9wjX3UT8zE1TczCrhZEcG8U".parse()?, accountid: "miraclx.near".parse()?, }, };
// call a method on the server via the connected client let txstatus = mainnetclient.call(txstatusrequest).await?;
println!("{:?}", tx_status); ```
Check out the examples folder
for a comprehensive list of helpful demos. You can run the examples with cargo
. For example: cargo run --example view_account
.
For all intents and purposes, the predefined structures in methods
should suffice, if you find that they
don't or you crave extra flexibility, well, you can opt in to use the generic constructor methods::any()
with the any
feature flag.
In this example, we retrieve only the parts from the genesis config response that we care about.
```toml
near-jsonrpc-client = { ..., features = ["any"] } ```
```rust use serde::Deserialize; use serde_json::json;
use nearjsonrpcclient::{methods, JsonRpcClient}; use nearprimitives::serialize::u128decformat; use nearprimitives::types::*;
struct PartialGenesisConfig {
protocolversion: ProtocolVersion,
chainid: String,
genesisheight: BlockHeight,
epochlength: BlockHeightDelta,
#[serde(with = "u128decformat")]
mingasprice: Balance,
#[serde(with = "u128decformat")]
maxgasprice: Balance,
#[serde(with = "u128decformat")]
total_supply: Balance,
validators: Vec
impl methods::RpcHandlerResponse for PartialGenesisConfig {}
let mainnet_client = JsonRpcClient::connect("https://rpc.mainnet.near.org");
let genesisconfigrequest = methods::any::
let partialgenesis = mainnetclient.call(genesisconfigrequest).await?;
println!("{:#?}", partial_genesis); ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.