POSTview_state

NEAR Mainnethttps://near-mainnet.nodit.io/

Returns the key-value pairs stored in a contract's storage, encoded in base64. Only keys starting with the prefix given in prefix_base64 are returned; pass an empty string ("") to return the entire state.

Call the query method with request_type: "view_state". For large state, set how many entries to receive at once with limit, then pass the last_key from the response as after_key_base64 in the next request to continue. include_proof cannot be combined with after_key_base64 or limit; specifying them together returns REQUEST_VALIDATION_ERROR (PARSE_ERROR).

By default, RPC nodes return at most 50 kB of state. Querying state larger than this limit without pagination returns the TOO_LARGE_CONTRACT_STATE error (for example, requesting wrap.near with prefix_base64: ""). Querying an account that does not exist returns the UNKNOWN_ACCOUNT error.

Request Body
jsonrpcstringrequired
idstringrequired

Request ID. Any string; it is returned unchanged in the response.

methodstringrequired
request_typestring (enum)required

Query type. Fixed to view_state for contract state lookups.

finalitystring (enum)

Specifies the block finality. Cannot be used together with block_id.

  • optimistic: the latest block the node has received (may be reorganized)
  • near-final: a Doomslug-final block (not reverted in most cases)
  • final: a fully finalized block
block_idinteger

Specifies the block to query by block height (integer) or block hash (base58 string). Cannot be used together with finality.

account_idstringrequired

NEAR account ID. A human-readable name (e.g. wrap.near) or a 64-character hex implicit account ID.

prefix_base64stringrequired

Prefix of the keys to look up (base64). An empty string ("") targets all keys.

after_key_base64string

Resume listing after this key (exclusive). Pass the last_key from the previous response; it must start with prefix_base64. Cannot be combined with include_proof.

limitinteger

Maximum number of key-value pairs to return in one page. Cannot be combined with include_proof.

include_proofboolean

If true, also returns inclusion proofs (proof) for the state entries. Defaults to false; cannot be combined with after_key_base64 or limit.

Responses
jsonrpcstring

JSON-RPC version

idstring

Request ID

valuesobject[]

Key-value pairs matching the condition. An empty array if no key matches or the state is empty.

keystring

Storage key (base64)

valuestring

Storage value (base64). The value format follows the serialization chosen by the contract (Borsh, JSON, etc.).

last_keystring

Key (base64) to pass as after_key_base64 to fetch the next page. Present only when entries remain; absent on the last page.

proofstring[]

Inclusion proofs for the state entries (array of base64 strings). Present only when requested with include_proof: true.

block_heightinteger

Block height.

Example: 220785385

block_hashstring

Base58-encoded 32-byte hash (block hash, chunk hash, transaction hash, etc.).

Example: 8EjuQRnAJiWkRmqxfexQFJWXXonuSMbz5AZziJLCWnWS

namestring (enum)

Error class. REQUEST_VALIDATION_ERROR (invalid request), HANDLER_ERROR (processing error), INTERNAL_ERROR (node internal error)

causeobject

The specific cause of the error.

namestring

Name of the error cause (e.g. UNKNOWN_BLOCK, UNKNOWN_ACCOUNT, PARSE_ERROR)

infoobject

Additional information about the error (block hash, height, account ID, etc.)

codeinteger

Legacy JSON-RPC error code (e.g. -32000 server error, -32700 parse error, -32601 method not found)

messagestring

Legacy error message

datastring

Legacy error details

X-API-KEY
RequestCU60
cURL
curl -X POST "https://near-mainnet.nodit.io/" \
  -H "X-API-KEY: {YOUR_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": "dontcare",
    "method": "query",
    "params": {
      "request_type": "view_state",
      "finality": "final",
      "block_id": 220785385,
      "account_id": "wrap.near",
      "after_key_base64": "YQIAAAB0Zw==",
      "limit": 2,
      "include_proof": false
    }
  }'
Response
Example · 200
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "result": {
    "values": [
      {
        "key": "U1RBVEU=",
        "value": "AQAAAGFi02nsoIeYQcnjCmHEAQAAfQAAAAAAAAA="
      },
      {
        "key": "YQIAAAB0Zw==",
        "value": "AADAzLBGtbosOQAAAAAAAA=="
      }
    ],
    "last_key": "YQIAAAB0Zw==",
    "block_height": 220877592,
    "block_hash": "9W8m4p7dcURdJbgRUuWUdLfPwo3jHQ7vZud4EiwxmSs2"
  }
}