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

Quick Reference

MethodEndpointPurpose
view_accountQuery account infoGet basic account information
view_account_changesTrack account changesMonitor account state changes
view_codeQuery contract codeGet deployed contract WASM code
view_stateQuery contract stateGet contract storage data
data_changesTrack state changesMonitor contract state changes
contract_code_changesTrack code changesMonitor contract deployments
call_functionCall view functionsExecute read-only contract methods

View account

Returns basic account information.
method
string
required
query
request_type
string
required
view_account
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.
account_id
string
required
Example: "example.testnet"
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "query",
  "params": {
    "request_type": "view_account",
    "finality": "final",
    "account_id": "account.rpc-examples.testnet"
  }
}
{
  "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"
}

View account changes

Returns account changes from transactions in a given account.
method
string
required
changes
changes_type
string
required
account_changes
account_ids
array
required
Example: ["example.testnet"]
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.

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
string
required
query
request_type
string
required
view_code
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.
account_id
string
required
Example: "example.testnet"

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
string
required
query
request_type
string
required
view_state
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.
account_id
string
required
Example: "example.testnet"
prefix_base64
string
required
Base64 encoded key prefix (empty string "" returns all state)

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
string
required
changes
changes_type
string
required
data_changes
account_ids
array
required
Example: ["example.testnet"]
key_prefix_base64
string
required
Base64 encoded key value
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.

View contract code changes

Returns code changes made when deploying a contract. Change is returned is a base64 encoded WASM file.
method
string
required
changes
changes_type
string
required
contract_code_changes
account_ids
array
required
Example: ["example.testnet"]
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.

Call a contract function

Allows you to call a contract method as a view function.
method
string
required
query
request_type
string
required
call_function
finality
string
Block finality. See finality param.
block_id
number | string
Block height or hash. See block_id param.
account_id
string
required
Example: "example.testnet"
method_name
string
required
The name of the contract method to call
args_base64
string
required
Method arguments base64 encoded
{
  "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": ""
  }
}
{
  "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"
}
The result field contains an array of bytes representing ASCII code. For example, [34, 71, ..., 33, 34] is the ASCII code for "Greetings from NEAR Protocol!". The near-sdk-rs and near-sdk-js return JSON-serialized results.

Error Handling

Common Error Types

Error CodeDescriptionSolution
UnknownAccountAccount does not existCheck account ID spelling and existence
InvalidAccountInvalid account formatUse valid account ID format (e.g., account.near)
UnknownBlockBlock not foundUse a valid block hash or height
GarbageCollectedBlockBlock too oldUse archival node or more recent block
TooManyInputsToo many accounts in requestReduce number of accounts per request
NoContractCodeAccount has no contract deployedVerify the account has a deployed contract
MethodNotFoundContract method does not existCheck method name and contract ABI
InvalidArgsInvalid method argumentsVerify args format and encoding

Best Practices

  • Use specific queries: Query only the data you need instead of broad state queries
  • Validate inputs: Always validate method arguments before contract calls
  • Cache contract code: Contract code rarely changes, consider caching
  • Handle errors gracefully: Implement proper error handling for all API calls

Build docs developers (and LLMs) love