---
title: "POST /query"
method: POST
path: "/query"
---

# POST /query

`POST /query`

This module allows you to make generic requests to the network.

The `RpcQueryRequest` struct takes in a [`BlockReference`](https://docs.rs/near-primitives/0.12.0/near_primitives/types/enum.BlockReference.html) and a [`QueryRequest`](https://docs.rs/near-primitives/0.12.0/near_primitives/views/enum.QueryRequest.html).

The `BlockReference` enum allows you to specify a block by `Finality`, `BlockId` or `SyncCheckpoint`.

The `QueryRequest` enum provides multiple variants for performing the following actions:
 - View an account's details
 - View a contract's code
 - View the state of an account
 - View the `AccessKey` of an account
 - View the `AccessKeyList` of an account
 - Call a function in a contract deployed on the network.

## Request body

- JsonRpcRequestForQuery
  - `id` string — JSON-RPC request id. Auto-populated; can be any string.
  - `jsonrpc` '2.0' — JSON-RPC protocol version. Always `2.0`.
  - `method` 'query', required
  - `params` union, required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_account', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_code', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `after_key_base64` union
        - string, bytes — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
        - unknown
      - `include_proof` boolean
      - `limit` integer, nullable
      - `prefix_base64` string, bytes, required — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
      - `request_type` 'view_state', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `public_key` string, required
      - `request_type` 'view_access_key', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `after_key` union
        - string
        - unknown
      - `limit` integer, nullable
      - `request_type` 'view_access_key_list', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `public_key` string, required
      - `request_type` 'view_gas_key_nonces', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `args_base64` string, bytes, required — This type is used to mark function arguments. NOTE: The main reason for this to exist (except the type-safety) is that the value is transparently serialized and deserialized as a base64-encoded string when serde is used (serde_json).
      - `method_name` string, required
      - `request_type` 'call_function', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `code_hash` string, required
      - `request_type` 'view_global_contract_code', required
    - object
      - `block_id` union, required
        - integer
        - string
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_global_contract_code_by_account_id', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_account', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_code', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `after_key_base64` union
        - string, bytes — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
        - unknown
      - `include_proof` boolean
      - `limit` integer, nullable
      - `prefix_base64` string, bytes, required — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
      - `request_type` 'view_state', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `public_key` string, required
      - `request_type` 'view_access_key', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `after_key` union
        - string
        - unknown
      - `limit` integer, nullable
      - `request_type` 'view_access_key_list', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `public_key` string, required
      - `request_type` 'view_gas_key_nonces', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `args_base64` string, bytes, required — This type is used to mark function arguments. NOTE: The main reason for this to exist (except the type-safety) is that the value is transparently serialized and deserialized as a base64-encoded string when serde is used (serde_json).
      - `method_name` string, required
      - `request_type` 'call_function', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `code_hash` string, required
      - `request_type` 'view_global_contract_code', required
    - object
      - `finality` 'optimistic' | 'near-final' | 'final', required — Different types of finality.
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_global_contract_code_by_account_id', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_account', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_code', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `after_key_base64` union
        - string, bytes — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
        - unknown
      - `include_proof` boolean
      - `limit` integer, nullable
      - `prefix_base64` string, bytes, required — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
      - `request_type` 'view_state', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `public_key` string, required
      - `request_type` 'view_access_key', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `after_key` union
        - string
        - unknown
      - `limit` integer, nullable
      - `request_type` 'view_access_key_list', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `public_key` string, required
      - `request_type` 'view_gas_key_nonces', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `args_base64` string, bytes, required — This type is used to mark function arguments. NOTE: The main reason for this to exist (except the type-safety) is that the value is transparently serialized and deserialized as a base64-encoded string when serde is used (serde_json).
      - `method_name` string, required
      - `request_type` 'call_function', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `code_hash` string, required
      - `request_type` 'view_global_contract_code', required
    - object
      - `sync_checkpoint` 'genesis' | 'earliest_available', required
      - `account_id` string, required — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
      - `request_type` 'view_global_contract_code_by_account_id', required

## Response `200`

- union
  - object
    - `result` union, required
      - object — A view of the account
        - `amount` string, required
        - `code_hash` string, required
        - `global_contract_account_id` union
          - string — NEAR Account Identifier. This is a unique, syntactically valid, human-readable account identifier on the NEAR network. [See the crate-level docs for information about validation.](index.html#account-id-rules) Also see [Error kind precedence](AccountId#error-kind-precedence). ## Examples ``` use near_account_id::AccountId; let alice: AccountId = "alice.near".parse().unwrap(); assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f) ```
          - unknown
        - `global_contract_hash` union
          - string
          - unknown
        - `locked` string, required
        - `storage_paid_at` integer — TODO(2271): deprecated.
        - `storage_usage` integer, required
        - `block_hash` string, required
        - `block_height` integer, required
      - object — A view of the contract code.
        - `code_base64` string, required
        - `hash` string, required
        - `block_hash` string, required
        - `block_height` integer, required
      - object — Resulting state values for a view state query request
        - `last_key` union
          - string, bytes — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
          - unknown
        - `proof` string[]
        - `values` StateItem[], required
          - `key` string, bytes, required — This type is used to mark keys (arrays of bytes) that are queried from store. NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
          - `value` string, bytes, required — This type is used to mark values returned from store (arrays of bytes). NOTE: Currently, this type is only used in the view_client and RPC to be able to transparently pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`).
        - `block_hash` string, required
        - `block_height` integer, required
      - object — A result returned by contract method
        - `logs` string[], required
        - `result` integer[], required
        - `block_hash` string, required
        - `block_height` integer, required
      - object — Describes access key permission scope and nonce.
        - `nonce` integer, required
        - `permission` union, required — Describes the permission scope for an access key. Whether it is a function call or a full access key.
          - 'FullAccess'
          - object
            - `FunctionCall` object, required
              - …
          - object
            - `GasKeyFunctionCall` object, required
              - …
          - object
            - `GasKeyFullAccess` object, required
              - …
        - `block_hash` string, required
        - `block_height` integer, required
      - object — Lists access keys
        - `keys` AccessKeyInfoView[], required
          - `access_key` AccessKeyView, required — Describes access key permission scope and nonce.
            - `nonce` integer, required
            - `permission` union, required — Describes the permission scope for an access key. Whether it is a function call or a full access key.
              - …
          - `public_key` string, required
        - `last_key` union — Pagination cursor. When `Some`, the listing was truncated and the caller should issue another request with `after_key` set to this handle to fetch the next page. `None` means this was the last page.
          - string
          - unknown
        - `block_hash` string, required
        - `block_height` integer, required
      - object — Gas key nonces view returned by the `view_gas_key_nonces` RPC query.
        - `nonces` integer[], required
        - `block_hash` string, required
        - `block_height` integer, required
    - `id` string, required
    - `jsonrpc` string, required
  - object
    - `error` union, required
      - object
        - `cause` union, required
          - object
            - `info` object, required
              - …
            - `name` 'METHOD_NOT_FOUND', required
          - object
            - `info` object, required
              - …
            - `name` 'PARSE_ERROR', required
        - `name` 'REQUEST_VALIDATION_ERROR', required
      - object
        - `cause` union, required
          - object
            - `name` 'NO_SYNCED_BLOCKS', required
          - object
            - `info` object, required
              - …
            - `name` 'UNAVAILABLE_SHARD', required
          - object
            - `info` object, required
              - …
            - `name` 'GARBAGE_COLLECTED_BLOCK', required
          - object
            - `info` object, required
              - …
            - `name` 'UNKNOWN_BLOCK', required
          - object
            - `info` object, required
              - …
            - `name` 'INVALID_ACCOUNT', required
          - object
            - `info` object, required
              - …
            - `name` 'UNKNOWN_ACCOUNT', required
          - object
            - `info` object, required
              - …
            - `name` 'NO_CONTRACT_CODE', required
          - object
            - `info` object, required
              - …
            - `name` 'TOO_LARGE_CONTRACT_STATE', required
          - object
            - `info` object, required
              - …
            - `name` 'UNKNOWN_ACCESS_KEY', required
          - object
            - `info` object, required
              - …
            - `name` 'UNKNOWN_GAS_KEY', required
          - object
            - `info` object, required
              - …
            - `name` 'TOO_MANY_ACCESS_KEYS', required
          - object
            - `info` object, required
              - …
            - `name` 'CONTRACT_EXECUTION_ERROR', required
          - object
            - `info` object, required
              - …
            - `name` 'NO_GLOBAL_CONTRACT_CODE', required
          - object
            - `info` object, required
              - …
            - `name` 'INTERNAL_ERROR', required
        - `name` 'HANDLER_ERROR', required
      - object
        - `cause` InternalError, required
          - `info` object, required
            - `error_message` string, required
          - `name` 'INTERNAL_ERROR', required
        - `name` 'INTERNAL_ERROR', required
    - `id` string, required
    - `jsonrpc` string, required

---

[API](https://skmtc.net/near/apis/near-protocol-json-rpc-api.md) · [All operations](https://skmtc.net/near/apis/near-protocol-json-rpc-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/near/near-protocol-json-rpc-api/versions/cb6bdde6167d/schema)
