Skip to main content

Accounts / Contracts

The RPC API enables you to view details about accounts and contracts as well as perform contract calls.


View account​

Returns basic account information.

  • method: query
  • params:

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_account",
"finality": "final",
"account_id": "account.rpc-examples.testnet"
}
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"amount": "999788200694421800000000",
"block_hash": "56xEo2LorUFVNbkFhCncFSWNiobdp1kzm14nZ47b5JVW",
"block_height": 187440904,
"code_hash": "11111111111111111111111111111111",
"locked": "0",
"storage_paid_at": 0,
"storage_usage": 410
},
"id": "dontcare"
}

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by view_account request type:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

INVALID_ACCOUNT200

The requested account_id is invalid

  • Provide a valid account_id

UNKNOWN_ACCOUNT200

The requested account_id has not been found while viewing since the account has not been created or has been already deleted

  • Check the account_id

  • Specify a different block or retry if you request the latest state

UNAVAILABLE_SHARD200

The node was unable to find the requested data because it does not track the shard where data is present

  • Send a request to a different node which might track the shard

NO_SYNCED_BLOCKS200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


View account changes​

Returns account changes from transactions in a given account.

  • method: EXPERIMENTAL_changes
  • params:
    • changes_type: account_changes
    • account_ids: ["example.testnet"]
    • finality OR block_id

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "account_changes",
"account_ids": ["contract.rpc-examples.testnet"],
"block_id": 187310139
}
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "8woqfx6kyjgfgU1S2L6Kur27h5jpBtDTmG8vQ8vpAUut",
"changes": [
{
"cause": {
"receipt_hash": "FseKd4rmjPSAuEz9zh9b5PfUS4jJV4rB6XkeHwVkyXkk",
"type": "receipt_processing"
},
"change": {
"account_id": "contract.rpc-examples.testnet",
"amount": "4999184472524996100000000",
"code_hash": "GVvBFWDPNmomMwXH4LvQW2cRaZJ8N6gxsdBhbJ8ReVJf",
"locked": "0",
"storage_paid_at": 0,
"storage_usage": 81621
},
"type": "account_update"
},
{
"cause": {
"receipt_hash": "FseKd4rmjPSAuEz9zh9b5PfUS4jJV4rB6XkeHwVkyXkk",
"type": "action_receipt_gas_reward"
},
"change": {
"account_id": "contract.rpc-examples.testnet",
"amount": "4999212038891301300000000",
"code_hash": "GVvBFWDPNmomMwXH4LvQW2cRaZJ8N6gxsdBhbJ8ReVJf",
"locked": "0",
"storage_paid_at": 0,
"storage_usage": 81621
},
"type": "account_update"
}
]
},
"id": "dontcare"
}

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by EXPERIMENTAL_changes method:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

NOT_SYNCED_YET200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


View contract code​

Returns the contract code (Wasm binary) deployed to the account. Please note that the returned code will be encoded in base64.

  • method: query
  • params:

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_code",
"finality": "final",
"account_id": "contract.rpc-examples.testnet"
}
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "bxucHpnP8VsiB3pLvA7DpBwri9x1DCZxVfBNkrdWbqn",
"block_height": 187441984,
"code_base64": "AGFzbQEAAAABugEbYAJ/fwF/YAN/f38Bf2ACf38AYAN/...",
"hash": "GVvBFWDPNmomMwXH4LvQW2cRaZJ8N6gxsdBhbJ8ReVJf"
},
"id": "dontcare"
}

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by view_code request type:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

INVALID_ACCOUNT200

The requested account_id is invalid

  • Provide a valid account_id

UNKNOWN_ACCOUNT200

The requested account_id has not been found while viewing since the account has not been created or has been already deleted

  • Check the account_id

  • Specify a different block or retry if you request the latest state

NO_CONTRACT_CODE200

The account does not have any contract deployed on it

  • Use different account
  • Specify a different block or retry if you request the latest state

UNAVAILABLE_SHARD200

The node was unable to find the requested data because it does not track the shard where data is present

  • Send a request to a different node which might track the shard

NO_SYNCED_BLOCKS200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


View contract state​

Returns the state (key value pairs) of a contract based on the key prefix (base64 encoded). Pass an empty string for prefix_base64 if you would like to return the entire state. Please note that the returned state will be base64 encoded as well.

  • method: query
  • params:
    • request_type: view_state
    • finality OR block_id
    • account_id: "example.testnet",
    • prefix_base64: ""

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_state",
"finality": "final",
"account_id": "contract.rpc-examples.testnet",
"prefix_base64": ""
}
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "GN5R7S8mMTEkUT1njWu9jARV29G7izVDjdSNs976BJVw",
"block_height": 187442491,
"values": [
{
"key": "U1RBVEU=",
"value": "HQAAAEdyZWV0aW5ncyBmcm9tIE5FQVIgUHJvdG9jb2whAQAAAHI="
},
{
"key": "cgEAAAAAAAAA",
"value": "FQAAAEhlbGxvLCBOZWFyIFByb3RvY29sIQ=="
}
]
},
"id": "dontcare"
}

Note: Currently, the response includes a proof field directly in the result, and a proof fields on each element of the values list. In the future, the result.proof will be included only if the result is not empty, and the proof field will be removed from all values. When parsing the result, you should accept objects with or without these fields set.

Heads up

There is a limitation on default RPC nodes. You won't be able to get the contract state if it is too big. The default limit of for contract state is 50kb of state size. You're able to change the limits if you run your own RPC node with adjusted trie_viewer_state_size_limit value in config.json

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by view_state request type:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

INVALID_ACCOUNT200

The requested account_id is invalid

  • Provide a valid account_id

UNKNOWN_ACCOUNT200

The requested account_id has not been found while viewing since the account has not been created or has been already deleted

  • Check the account_id

  • Specify a different block or retry if you request the latest state

NO_CONTRACT_CODE200

The account does not have any contract deployed on it

  • Query and account with contract deployed
  • Specify a different block or retry if you request the latest state

TOO_LARGE_CONTRACT_STATE200

The requested contract state is too large to be returned from this node (the default limit is 50kb of state size)

  • Send the request to a node with larger limits in order to view the requested state

  • Spin up your own node where you can increase the limits to view state

UNAVAILABLE_SHARD200

The node was unable to find the requested data because it does not track the shard where data is present

  • Send a request to a different node which might track the shard

NO_SYNCED_BLOCKS200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


View contract state changes​

Returns the state change details of a contract based on the key prefix (encoded to base64). Pass an empty string for this param if you would like to return all state changes.

  • method: EXPERIMENTAL_changes
  • params:
    • changes_type: data_changes
    • account_ids: ["example.testnet"],
    • key_prefix_base64: "base64 encoded key value",
    • finality OR block_id

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "data_changes",
"account_ids": ["contract.rpc-examples.testnet"],
"key_prefix_base64": "",
"block_id": 187310139
}
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "8woqfx6kyjgfgU1S2L6Kur27h5jpBtDTmG8vQ8vpAUut",
"changes": [
{
"cause": {
"receipt_hash": "FseKd4rmjPSAuEz9zh9b5PfUS4jJV4rB6XkeHwVkyXkk",
"type": "receipt_processing"
},
"change": {
"account_id": "contract.rpc-examples.testnet",
"key_base64": "U1RBVEU=",
"value_base64": "HQAAAEdyZWV0aW5ncyBmcm9tIE5FQVIgUHJvdG9jb2whAQAAAHI="
},
"type": "data_update"
},
{
"cause": {
"receipt_hash": "FseKd4rmjPSAuEz9zh9b5PfUS4jJV4rB6XkeHwVkyXkk",
"type": "receipt_processing"
},
"change": {
"account_id": "contract.rpc-examples.testnet",
"key_base64": "cgEAAAAAAAAA",
"value_base64": "FQAAAEhlbGxvLCBOZWFyIFByb3RvY29sIQ=="
},
"type": "data_update"
}
]
},
"id": "dontcare"
}

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by EXPERIMENTAL_changes method:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

NOT_SYNCED_YET200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


View contract code changes​

Returns code changes made when deploying a contract. Change is returned is a base64 encoded WASM file.

  • method: EXPERIMENTAL_changes
  • params:
    • changes_type: contract_code_changes
    • account_ids: ["example.testnet"],
    • finality OR block_id

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "contract_code_changes",
"account_ids": ["contract.rpc-examples.testnet"],
"block_id": 187309439
}
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"block_hash": "D1ZY3y51Z2v5tXq2nZPmXHgA3zZsPBzbtwHXjCvAEuLV",
"changes": [
{
"cause": {
"receipt_hash": "AR4cxtxc52WfnZcGEZHmPfQ1Dk3vQNb7vjSyicykfJWZ",
"type": "receipt_processing"
},
"change": {
"account_id": "contract.rpc-examples.testnet",
"code_base64": "AGFzbQEAAAABugEbYAJ/fwF/YAN/f38Bf2ACf38AYAN/..."
},
"type": "contract_code_update"
}
]
},
"id": "dontcare"
}

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by EXPERIMENTAL_changes method:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

NOT_SYNCED_YET200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


Call a contract function​

Allows you to call a contract method as a view function.

  • method: query
  • params:
    • request_type: call_function
    • finality OR block_id
    • account_id: "example.testnet"
    • method_name: get_method_name (example view methods)
    • args_base64: method_arguments_base_64_encoded

get_greeting example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "contract.rpc-examples.testnet",
"method_name": "get_greeting",
"args_base64": ""
}
}
Example response:

{
"jsonrpc": "2.0",
"result": {
"block_hash": "GTZdXfNmnL6TkJFdBeVMHCadgLuKChVfRNCSVsEQoJ7L",
"block_height": 187444191,
"logs": [],
"result": [
34, 71, 114, 101, 101, 116, 105, 110, 103, 115, 32, 102, 114, 111, 109,
32, 78, 69, 65, 82, 32, 80, 114, 111, 116, 111, 99, 111, 108, 33, 34
]
},
"id": "dontcare"
}

Note: [34, 71, ..., 33, 34] is an array of bytes, to be specific it is an ASCII code of "Greetings from NEAR Protocol!". near-sdk-rs and near-sdk-js return JSON-serialized results.


get_record example :

The args_base64 in this example can be decoded as

{
"record_id": 1
}
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "contract.rpc-examples.testnet",
"method_name": "get_record",
"args_base64": "ewogICJyZWNvcmRfaWQiOiAxCn0="
}
}
Example response:

{
"jsonrpc": "2.0",
"result": {
"block_hash": "8Gp8x1ZcanL3C2ris9rgk1nY8v6MuickLWeM6Gj2jGKs",
"block_height": 187445443,
"logs": [],
"result": [
34, 72, 101, 108, 108, 111, 44, 32, 78, 101, 97, 114, 32, 80, 114, 111,
116, 111, 99, 111, 108, 33, 34
]
},
"id": "dontcare"
}

Note: [34, 72, ..., 108, 33, 34] is an array of bytes, to be specific it is an ASCII code of "Hello, Near Protocol!". near-sdk-rs and near-sdk-js return JSON-serialized results.

What Could Go Wrong?​

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error"
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by call_function request type:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
Status CodeReasonSolution
HANDLER_ERRORUNKNOWN_BLOCK200

The requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)

  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to

    an archival node

INVALID_ACCOUNT200

The requested account_id is invalid

  • Provide a valid account_id

UNKNOWN_ACCOUNT200

The requested account_id has not been found while viewing since the account has not been created or has been already deleted

  • Check the account_id

  • Specify a different block or retry if you request the latest state

NO_CONTRACT_CODE200

The requested contract_code has not been found while viewing

  • Check the public_key

  • Specify a different block or retry if you request the latest state

CONTRACT_EXECUTION_ERROR200

The execution of the view function call failed (crashed, run out of the default 200 TGas limit, etc)

  • Check error.cause.info for more details

UNAVAILABLE_SHARD200

The node was unable to find the requested data because it does not track the shard where data is present

  • Send a request to a different node which might track the shard

NO_SYNCED_BLOCKS200

The node is still syncing and the requested block is not in the database yet

  • Wait until the node finish syncing
  • Send a request to a different node which is synced
REQUEST_VALIDATION_ERRORPARSE_ERROR400

Passed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)

  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details

INTERNAL_ERRORINTERNAL_ERROR500Something went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details


Was this page helpful?