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

Quick Reference

MethodPurpose
view_accountGet basic account information
view_account_changesMonitor account state changes
view_access_keyGet the nonce and permissions of a single access key
view_access_key_listList all access keys on an account
view_codeGet deployed contract WASM code
view_stateGet contract storage data
data_changesMonitor contract state changes
contract_code_changesMonitor contract deployments
call_functionExecute read-only contract methods

View Account

Returns basic account information.
  • method: query
  • params: request_type: view_account, finality OR block_id, account_id
{
  "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_usage": 410
  },
  "id": "dontcare"
}

View Account Changes

Returns account changes from transactions in a given account.
  • method: changes
  • params: changes_type: account_changes, account_ids, finality OR block_id
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "changes",
  "params": {
    "changes_type": "account_changes",
    "account_ids": ["contract.rpc-examples.testnet"],
    "block_id": 187310139
  }
}

View Access Key

Returns the nonce and permissions of a single access key, given the account and the key’s public key.
  • method: query
  • params: request_type: view_access_key, finality OR block_id, account_id, public_key
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "query",
  "params": {
    "request_type": "view_access_key",
    "finality": "final",
    "account_id": "account.rpc-examples.testnet",
    "public_key": "ed25519:DCkbTMS8s4kqV4nGvz5kRBdNbY9YwjjvNGNXKpAg2eFa"
  }
}
{
  "jsonrpc": "2.0",
  "result": {
    "nonce": 187310139000001,
    "permission": "FullAccess",
    "block_hash": "56xEo2LorUFVNbkFhCncFSWNiobdp1kzm14nZ47b5JVW",
    "block_height": 187440904
  },
  "id": "dontcare"
}
For a function-call key, permission is an object instead of the "FullAccess" string:
"permission": {
  "FunctionCall": {
    "allowance": "250000000000000000000000",
    "receiver_id": "contract.rpc-examples.testnet",
    "method_names": ["get_greeting"]
  }
}
For a post-quantum ml-dsa-65 key, pass the full ml-dsa-65: public key in public_key. The network hashes it to locate the on-chain entry, so you query it exactly like an ed25519 or secp256k1 key.

View Access Key List

Returns all access keys for an account, each with its nonce and permissions.
  • method: query
  • params: request_type: view_access_key_list, finality OR block_id, account_id
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "query",
  "params": {
    "request_type": "view_access_key_list",
    "finality": "final",
    "account_id": "account.rpc-examples.testnet"
  }
}
{
  "jsonrpc": "2.0",
  "result": {
    "keys": [
      {
        "public_key": "ed25519:DCkbTMS8s4kqV4nGvz5kRBdNbY9YwjjvNGNXKpAg2eFa",
        "access_key": {
          "nonce": 187310139000001,
          "permission": "FullAccess"
        }
      },
      {
        "public_key": "ml-dsa-65-hash:7Xx2X4vHb9dG8pJ5tZqD3mN6kRfWcA1sLuYoP2eB4hT",
        "access_key": {
          "nonce": 187420021000003,
          "permission": "FullAccess"
        }
      }
    ],
    "block_hash": "56xEo2LorUFVNbkFhCncFSWNiobdp1kzm14nZ47b5JVW",
    "block_height": 187440904
  },
  "id": "dontcare"
}
Post-quantum ml-dsa-65 keys are stored on-chain by hash, so they appear here with an ml-dsa-65-hash: prefix (a base58-encoded 48-byte SHA3-384 digest) rather than the full ml-dsa-65: key. To match an entry to one of your own keys, hash your public key and compare it against the returned value.

View Contract Code

Returns the contract code (Wasm binary) deployed to the account. The returned code is encoded in base64.
  • method: query
  • params: request_type: view_code, finality OR block_id, account_id
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "query",
  "params": {
    "request_type": "view_code",
    "finality": "final",
    "account_id": "contract.rpc-examples.testnet"
  }
}

View Contract State

Returns the state (key-value pairs) of a contract based on a key prefix (base64 encoded). Pass an empty string for prefix_base64 to return the entire state.
  • method: query
  • params: request_type: view_state, finality OR block_id, account_id, prefix_base64
By default, RPC nodes only return up to 50kB of contract state. If the contract’s state exceeds this limit, the query will return an error. To query larger state, use an archival node and paginate with prefix_base64.
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "query",
  "params": {
    "request_type": "view_state",
    "finality": "final",
    "account_id": "contract.rpc-examples.testnet",
    "prefix_base64": ""
  }
}

View Contract State Changes

Returns state change details of a contract based on a key prefix (base64 encoded).
  • method: changes
  • params: changes_type: data_changes, account_ids, key_prefix_base64, finality OR block_id
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "changes",
  "params": {
    "changes_type": "data_changes",
    "account_ids": ["contract.rpc-examples.testnet"],
    "key_prefix_base64": "",
    "block_id": 187310139
  }
}

View Contract Code Changes

Returns code changes made when deploying a contract. Change is returned as a base64 encoded WASM file.
  • method: changes
  • params: changes_type: contract_code_changes, account_ids, finality OR block_id
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "method": "changes",
  "params": {
    "changes_type": "contract_code_changes",
    "account_ids": ["contract.rpc-examples.testnet"],
    "block_id": 187309439
  }
}

Call a Contract Function

Allows you to call a contract method as a view function (read-only).
  • method: query
  • params: request_type: call_function, finality OR block_id, account_id, method_name, args_base64
{
  "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": ""
  }
}

Error Handling

Error CodeDescriptionSolution
UnknownAccountAccount does not existCheck account ID spelling
InvalidAccountInvalid account formatUse valid account ID (e.g., account.near)
UnknownBlockBlock not foundUse a valid block hash or height
GarbageCollectedBlockBlock too oldUse archival node or more recent block
NoContractCodeNo 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