Crate near_openapi_client

Source
Expand description

§near-openapi-client

Progenitor-generated client of NEAR JSON RPC API

Consists of two crates:

  • near-openapi-client - client to connect to the API, generated by progenitor
  • near-openapi-types - types used by client

§Usage example:

Add near-openapi-client to your project dependencies:

cargo add near-openapi-client

Use the client to get latest block info:

use near_openapi_client as client;

// Setup client
const NEAR_RPC_URL_REMOTE: &str = "https://archival-rpc.mainnet.near.org";
let client_remote = client::Client::new(NEAR_RPC_URL_LOCAL);

// Construct request
let payload_block_final = client::types::JsonRpcRequestForBlock {
    id: String::from("dontcare"),
    jsonrpc: String::from("2.0"),
    method: client::types::JsonRpcRequestForBlockMethod::Block,
    params: client::types::RpcBlockRequest::Finality(client::types::Finality::Final),
};

// Make the request, get the response
let block_final: client::types::JsonRpcResponseForRpcBlockResponseAndRpcError =
    client_local.block(&payload_block_final).await?.into_inner();
println!("block_final: {:#?}", block_final);
Example response
response for block_final: Variant0 {
    id: "dontcare",
    jsonrpc: "2.0",
    result: RpcBlockResponse {
        author: AccountId(
            "test.near",
        ),
        chunks: [
            ChunkHeaderView {
                balance_burnt: "0",
                bandwidth_requests: Some(
                    V1(
                        BandwidthRequestsV1 {
                            requests: [],
                        },
                    ),
                ),
                chunk_hash: CryptoHash(
                    "59srn1AQyCxqhXuURBGomupX8tCEj25XXFW15YZDgnM6",
                ),
                congestion_info: Some(
                    CongestionInfoView {
                        allowed_shard: 0,
                        buffered_receipts_gas: "0",
                        delayed_receipts_gas: "0",
                        receipt_bytes: 0,
                    },
                ),
                encoded_length: 8,
                encoded_merkle_root: CryptoHash(
                    "79Bt7ivt9Qhp3c6dJYnueaTyPVweYxZRpQHASRRAiyuy",
                ),
                gas_limit: 1000000000000000,
                gas_used: 0,
                height_created: 6,
                height_included: 6,
                outcome_root: CryptoHash(
                    "11111111111111111111111111111111",
                ),
                outgoing_receipts_root: CryptoHash(
                    "H4Rd6SGeEBTbxkitsCdzfu9xL9HtZ2eHoPCQXUeZ6bW4",
                ),
                prev_block_hash: CryptoHash(
                    "DeJY83ZJbakCtkwe9J8RTE9TEAybp4E1GFCVrdki8Z6c",
                ),
                prev_state_root: CryptoHash(
                    "7t7WeJdAzh9qmKLHfVRboDZupfAjfy9FC3onAN1LRnyp",
                ),
                rent_paid: "0",
                shard_id: ShardId(
                    0,
                ),
                signature: Signature(
                    "ed25519:5G8UWLLuVk3WvQTnSHmT7EQoCz521EaaxQ8f5mgNVxJjFW7o9VFfxuG6D5bNfCjmoTVWbc9WrUbXg2L11iGWQw2g",
                ),
                tx_root: CryptoHash(
                    "11111111111111111111111111111111",
                ),
                validator_proposals: [],
                validator_reward: "0",
            },
        ],
        header: BlockHeaderView {
            approvals: [
                Some(
                    Signature(
                        "ed25519:4GobVKSiiRfwMBrukNeCLbiUQLAzVprFCSn5jDVqA8zm6oR9H8EudEogsBAedBqJKF8vXhohSC5Kfnsdw2XMXMw6",
                    ),
                ),
            ],
            block_body_hash: Some(
                CryptoHash(
                    "CjDTJC25qznGymgHiUrDwSgaqsme3deDNj3ftPWFfBew",
                ),
            ),
            block_merkle_root: CryptoHash(
                "EXTvaXuYTcvEd8KnWjhruX9NYNCTbXJrwfzEJAnELBds",
            ),
            block_ordinal: Some(
                7,
            ),
            challenges_result: [],
            challenges_root: CryptoHash(
                "11111111111111111111111111111111",
            ),
            chunk_endorsements: Some(
                [
                    [
                        1,
                    ],
                ],
            ),
            chunk_headers_root: CryptoHash(
                "6fPXKHJce8krAwsXfdMgsSgmUd5CgcJBpBFKBhb7QT2j",
            ),
            chunk_mask: [
                true,
            ],
            chunk_receipts_root: CryptoHash(
                "9ETNjrt6MkwTgSVMMbpukfxRshSD1avBUUa4R4NuqwHv",
            ),
            chunk_tx_root: CryptoHash(
                "7tkzFg8RHBmMw1ncRJZCCZAizgq4rwCftTKYLce8RU8t",
            ),
            chunks_included: 1,
            epoch_id: CryptoHash(
                "11111111111111111111111111111111",
            ),
            epoch_sync_data_hash: None,
            gas_price: "100000000",
            hash: CryptoHash(
                "8UgWEvtdVcEu6uYBFboZKDoLsWk5DC5tz656fW3BA4ZL",
            ),
            height: 6,
            last_ds_final_block: CryptoHash(
                "DeJY83ZJbakCtkwe9J8RTE9TEAybp4E1GFCVrdki8Z6c",
            ),
            last_final_block: CryptoHash(
                "AMu9bpsii9wjFukjFc5cMaBNCNDvmiz4Z7AmwBAMcDLh",
            ),
            latest_protocol_version: 78,
            next_bp_hash: CryptoHash(
                "ChxUrwNyJDYA9PbecbLq1KBvkj2mEW3nvzXHC244X2rT",
            ),
            next_epoch_id: CryptoHash(
                "GsJ8x5msDUv7Zz4LgCxoqzeyWKvNT2sHdFyEdR3vZrCZ",
            ),
            outcome_root: CryptoHash(
                "7tkzFg8RHBmMw1ncRJZCCZAizgq4rwCftTKYLce8RU8t",
            ),
            prev_hash: CryptoHash(
                "DeJY83ZJbakCtkwe9J8RTE9TEAybp4E1GFCVrdki8Z6c",
            ),
            prev_height: Some(
                5,
            ),
            prev_state_root: CryptoHash(
                "9wppbHBR63GhoJWW3ti6qhD5AAEmiNr1DKWQq9kLwrHM",
            ),
            random_value: CryptoHash(
                "6MypYizcvSPkaxgd7cXAgGfHo8TsnmouzLtCHnGASbKe",
            ),
            rent_paid: "0",
            signature: Signature(
                "ed25519:3jHUhecrkNYoTDrQ8jARWco8vCNCdrwPewZrv1HQeTE5tQj78fjAYkJbgeFo8wcyi6maTFFYRNdHQ8nrmFa1Pjc",
            ),
            timestamp: 1750759979825366257,
            timestamp_nanosec: "1750759979825366257",
            total_supply: "2050000000000000000000000000000000",
            validator_proposals: [],
            validator_reward: "0",
        },
    },
}

Re-exports§

pub use near_openapi_types as types;

Modules§

prelude
Items consumers will typically use such as the Client.

Structs§

ByteStream
Untyped byte stream used for both success and error responses.
Client
Client for NEAR Protocol JSON RPC API
ResponseValue
Typed value returned by generated client methods.

Enums§

Error
Error produced by generated client methods.

Traits§

ClientInfo
Interface for which an implementation is generated for all clients.