NEAR — Access Keys, Accounts/Contracts, Block/Chunk, Gas, Protocol (1/2)
API reference for NEAR. All methods ->
Part 1 of 2: 1 · 2
Access Keys
The API enables you to retrieve information about an account's access keys.
View access key
Retrieves information about a single access key for a given account.
If permission of the key is FunctionCall, it will return more details such as the allowance, receiver_id, and method_names.
Parameters
-
id(integer; required): a request ID; unlike other networks, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —query. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_access_key",
"finality": "final",
"account_id": "client.chainlink.testnet",
"public_key": "ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW"
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"nonce": 85,
"permission": {
"FunctionCall": {
"allowance": "18501534631167209000000000",
"receiver_id": "client.chainlink.testnet",
"method_names": ["get_token_price"]
}
},
"block_height": 19884918,
"block_hash": "GGJQ8yjmo7aEoj8ZpAhGehnq9BSWFx4xswHYzDwwAP2n"
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View access key list
Retrieves all access keys for a given account.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —query. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_access_key_list",
"finality": "final",
"account_id": "example.testnet"
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"keys": [
{
"public_key": "ed25519:2j6qujbkPFuTstQLLTxKZUw63D5Wu3SG79Gop5JQrNJY",
"access_key": {
"nonce": 17,
"permission": {
"FunctionCall": {
"allowance": "9999203942481156415000",
"receiver_id": "place.meta",
"method_names": []
}
}
}
},
{
"public_key": "ed25519:46etzhzZHN4NSQ8JEQtbHCX7sT8WByS3vmSEb3fbmSgf",
"access_key": {
"nonce": 2,
"permission": {
"FunctionCall": {
"allowance": "9999930655034196535000",
"receiver_id": "dev-1596616186817-8588944",
"method_names": []
}
}
}
},
{
"public_key": "ed25519:4F9TwuSqWwvoyu7JVZDsupPhC7oYbYNsisBV2yQvyXFn",
"access_key": {
"nonce": 0,
"permission": "FullAccess"
}
},
{
"public_key": "ed25519:4bZqp6nm1btr92UfKbyADDzJ4oPK9JetHXqEYqbYZmkD",
"access_key": {
"nonce": 2,
"permission": "FullAccess"
}
},
{
"public_key": "ed25519:6ZPzX7hS37jiU9dRxbV1Waf8HSyKKFypJbrnZXzNhqjs",
"access_key": {
"nonce": 2,
"permission": {
"FunctionCall": {
"allowance": "9999922083697042955000",
"receiver_id": "example.testnet",
"method_names": []
}
}
}
},
{
"public_key": "ed25519:81RKfuo7mBbsaviTmBsq18t6Eq4YLnSi3ye2CBLcKFUX",
"access_key": {
"nonce": 8,
"permission": "FullAccess"
}
},
{
"public_key": "ed25519:B4W1oAYTcG8GxwKev8jQtsYWkGwGdqP24W7eZ6Fmpyzc",
"access_key": {
"nonce": 0,
"permission": {
"FunctionCall": {
"allowance": "10000000000000000000000",
"receiver_id": "dev-1594144238344",
"method_names": []
}
}
}
},
{
"public_key": "ed25519:BA3AZbACoEzAsxKeToFd36AVpPXFSNhSMW2R6UYeGRwM",
"access_key": {
"nonce": 0,
"permission": {
"FunctionCall": {
"allowance": "10000000000000000000000",
"receiver_id": "new-corgis",
"method_names": []
}
}
}
},
{
"public_key": "ed25519:BRyHUGAJjRKVTc9ZqXTTSJnFmSca8WLj8TuVe1wXK3LZ",
"access_key": {
"nonce": 17,
"permission": "FullAccess"
}
},
{
"public_key": "ed25519:DjytaZ1HZ5ZFmH3YeJeMCiC886K1XPYeGsbz2E1AZj2J",
"access_key": {
"nonce": 31,
"permission": "FullAccess"
}
},
{
"public_key": "ed25519:DqJn5UCq6vdNAvfhnbpdAeuui9a6Hv9DKYDxeRACPUDP",
"access_key": {
"nonce": 0,
"permission": "FullAccess"
}
},
{
"public_key": "ed25519:FFxG8x6cDDyiErFtRsdw4dBNtCmCtap4tMTjuq3umvSq",
"access_key": {
"nonce": 0,
"permission": "FullAccess"
}
}
],
"block_height": 17798231,
"block_hash": "Gm7YSdx22wPuciW1jTTeRGP9mFqmon69ErFQvgcFyEEB"
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View access key changes (single)
Retrieves individual access key changes in a specific block.
You can query multiple keys by passing an array of objects containing the account_id and public_key.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —EXPERIMENTAL_changes. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "single_access_key_changes",
"keys": [
{
"account_id": "example-acct.testnet",
"public_key": "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM"
}
],
"finality": "final"
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"block_hash": "4kvqE1PsA6ic1LG7S5SqymSEhvjqGqumKjAxnVdNN3ZH",
"changes": [
{
"cause": {
"type": "transaction_processing",
"tx_hash": "HshPyqddLxsganFxHHeH9LtkGekXDCuAt6axVgJLboXV"
},
"type": "access_key_update",
"change": {
"account_id": "example-acct.testnet",
"public_key": "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM",
"access_key": {
"nonce": 1,
"permission": "FullAccess"
}
}
}
]
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View access key changes (all)
Retrieves the changes to all access keys of a specific block.
Multiple accounts can be queried by passing an array of account_ids.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —EXPERIMENTAL_changes. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "all_access_key_changes",
"account_ids": ["example-acct.testnet"],
"block_id": "4kvqE1PsA6ic1LG7S5SqymSEhvjqGqumKjAxnVdNN3ZH"
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"block_hash": "4kvqE1PsA6ic1LG7S5SqymSEhvjqGqumKjAxnVdNN3ZH",
"changes": [
{
"cause": {
"type": "transaction_processing",
"tx_hash": "HshPyqddLxsganFxHHeH9LtkGekXDCuAt6axVgJLboXV"
},
"type": "access_key_update",
"change": {
"account_id": "example-acct.testnet",
"public_key": "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM",
"access_key": {
"nonce": 1,
"permission": "FullAccess"
}
}
},
{
"cause": {
"type": "receipt_processing",
"receipt_hash": "CetXstu7bdqyUyweRqpY9op5U1Kqzd8pq8T1kqfcgBv2"
},
"type": "access_key_update",
"change": {
"account_id": "example-acct.testnet",
"public_key": "ed25519:96pj2aVJH9njmAxakjvUMnNvdB3YUeSAMjbz9aRNU6XY",
"access_key": {
"nonce": 0,
"permission": "FullAccess"
}
}
}
]
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
Accounts/Contracts
The API enables you to view details about accounts and contracts as well as perform contract calls.
View account
Retrieves basic account information.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —query. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_account",
"finality": "final",
"account_id": "nearkat.testnet"
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"amount": "399992611103597728750000000",
"locked": "0",
"code_hash": "11111111111111111111111111111111",
"storage_usage": 642,
"storage_paid_at": 0,
"block_height": 17795474,
"block_hash": "9MjpcnwW3TSdzGweNfPbkx8M74q1XzUcT1PAN8G5bNDz"
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View account changes
Retrieves account changes from transactions in a given account.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —EXPERIMENTAL_changes. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "account_changes",
"account_ids": ["your_account.testnet"],
"block_id": 19703467
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"block_hash": "6xsfPSG89s6fCMShxxxQTP6D4ZHM9xkGCgubayTDRzAP",
"changes": [
{
"cause": {
"type": "transaction_processing",
"tx_hash": "HLvxLKFM7gohFSqXPp5SpyydNEVpAno352qJJbnddsz3"
},
"type": "account_update",
"change": {
"account_id": "your_account.testnet",
"amount": "499999959035075000000000000",
"locked": "0",
"code_hash": "11111111111111111111111111111111",
"storage_usage": 182,
"storage_paid_at": 0
}
},
{
"cause": {
"type": "receipt_processing",
"receipt_hash": "CPenN1dp4DNKnb9LiL5hkPmu1WiKLMuM7msDjEZwDmwa"
},
"type": "account_update",
"change": {
"account_id": "your_account.testnet",
"amount": "499999959035075000000000000",
"locked": "0",
"code_hash": "11111111111111111111111111111111",
"storage_usage": 264,
"storage_paid_at": 0
}
}
]
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View contract code
Retrieves the contract code (Wasm binary) deployed to the account.
The returned code will be encoded in base64.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —query. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_code",
"finality": "final",
"account_id": "guest-book.testnet"
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"code_base64": "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
"hash": "7KoFshMQkdyo5iTx8P2LbLu9jQpxRn24d27FrKShNVXs",
"block_height": 17814234,
"block_hash": "GT1D8nweVQU1zyCUv399x8vDv2ogVq71w17MyR66hXBB"
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View contract state
Retrieves the state (key value pairs) of a contract based on the key prefix (base64 encoded).
Pass an empty string for prefix_base64 to read the whole state. Keys and values come back base64 encoded. A contract with a large state answers State of contract <account> is too large to be viewed unless you page through it with limit and after_key_base64.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —query. -
params(array; required):request_type:view_statefinality/block_idaccount_id:"wrap.near"prefix_base64:""limit(integer; optional): the maximum number of key value pairs to return,1or more. The node can return fewer.after_key_base64(string; optional): return keys after this one; passlast_keyfrom the previous page.
Pagination
When more keys remain, the response carries last_key. Pass it as after_key_base64 with the same block_id to get the next page, and stop when last_key is absent. Pin block_id from the first page so every page reads the same state. Full nodes keep only recent blocks, so in the next-page example use the block_height and last_key from your own first page.
Request example (first page)
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_state",
"finality": "final",
"account_id": "wrap.near",
"prefix_base64": "",
"limit": 2
}
}'
Response example (first page)
{
"jsonrpc": "2.0",
"result": {
"block_hash": "GpgKGUU6NNFh9oSXhgHspzr5zNfCBnCXza5XR62cD1SR",
"block_height": 220201908,
"last_key": "YQIAAAB0Zw==",
"values": [
{
"key": "U1RBVEU=",
"value": "AQAAAGHLrveARA/389vU5THGAQAAfQAAAAAAAAA="
},
{
"key": "YQIAAAB0Zw==",
"value": "AADAzLBGtbosOQAAAAAAAA=="
}
]
},
"id": "dontcare"
}
Request example (next page)
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_state",
"block_id": 220201908,
"account_id": "wrap.near",
"prefix_base64": "",
"limit": 2,
"after_key_base64": "YQIAAAB0Zw=="
}
}'
Response example (next page)
{
"jsonrpc": "2.0",
"result": {
"block_hash": "GpgKGUU6NNFh9oSXhgHspzr5zNfCBnCXza5XR62cD1SR",
"block_height": 220201908,
"last_key": "YQQAAAAwLjAw",
"values": [
{
"key": "YQMAAAB1c24=",
"value": "AAAAAAAAAAAAAAAAAAAAAA=="
},
{
"key": "YQQAAAAwLjAw",
"value": "AACsjNtDnO1nEAAAAAAAAA=="
}
]
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View contract state changes
Retrieves 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.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —EXPERIMENTAL_changes. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "data_changes",
"account_ids": ["guest-book.testnet"],
"key_prefix_base64": "",
"block_id": 19450732
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"block_hash": "6U8Yd4JFZwJUNfqkD4KaKgTKmpNSmVRTSggpjmsRWdKY",
"changes": [
{
"cause": {
"type": "receipt_processing",
"receipt_hash": "9ewznXgs2t7vRCssxW4thgaiwggnMagKybZ7ryLNTT2z"
},
"type": "data_update",
"change": {
"account_id": "guest-book.testnet",
"key_base64": "bTo6Mzk=",
"value_base64": "eyJwcmVtaXVtIjpmYWxzZSwic2VuZGVyIjoiZmhyLnRlc3RuZXQiLCJ0ZXh0IjoiSGkifQ=="
}
},
{
"cause": {
"type": "receipt_processing",
"receipt_hash": "9ewznXgs2t7vRCssxW4thgaiwggnMagKybZ7ryLNTT2z"
},
"type": "data_update",
"change": {
"account_id": "guest-book.testnet",
"key_base64": "bTpsZW4=",
"value_base64": "NDA="
}
}
]
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
View contract code changes
Retrieves code changes made when deploying a contract.
The change are returned as a base64-encoded WASM file.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —EXPERIMENTAL_changes. -
params(array; required):
Request example
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "contract_code_changes",
"account_ids": ["dev-1602714453032-7566969"],
"block_id": 20046655
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"block_hash": "3yLNV5zdpzRJ8HP5xTXcF7jdFxuHnmKNUwWcok4616WZ",
"changes": [
{
"cause": {
"type": "receipt_processing",
"receipt_hash": "CEm3NNaNdu9cijh9NvZMM1srbtEYSsBVwGbZxFQYKt5B"
},
"type": "contract_code_update",
"change": {
"account_id": "dev-1602714453032-7566969",
"code_base64": "AGFzbQEAAAABpAM3YAF/AGAAAX9gAn9+AGADf35+AGAEf35+fgF+YAZ/fn5+fn4BfmADf35+AX5gAn9+AX5gAn9/AX9gAn9/AGADf39/AX9gAX8BfmACfn4AYAF+AX5gAX4AYAABfmADfn5+AGAAAGAIfn5+fn5+fn4BfmAJfn5+fn5+fn5+AX5gAn5+AX5gA35+fgF+YAd+fn5+fn5+AGAEfn5+fgBgCX5+fn5+fn5+fgBgBX5+fn5+AX5gA39/fwBgAX8Bf2ACf3wAYAR/f39+AGAFf39/fn8AYAV/f39/fwBgBH9/f38AYAN/f38BfmADf39+AGACf38BfmAFf39/f38Bf2AEf39/fwF/YAZ/f39/f38AYAV/f35/fwBgBH9+f38Bf2ACf34Bf2AHf35+f39+fwBgBX9/f39+AGAEf35+fgBgCX9+fn5+fn5+fgF+YAp/fn5+fn5+fn5+AX5gCH9+fn5+fn5+AGAFf35+fn4AYAp/fn5+fn5+fn5+AGAHf39/f39/fwBgBH98f38Bf2AGf39/f39..."
}
}
]
},
"id": "dontcare"
}
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.
Call a contract function
Calls a contract method as a view function.
Parameters
-
id(integer; required): a request ID; unlike other chains, NEAR "dontcare" about a number you use (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request —query. -
params(array; required):request_type:call_functionfinality/block_idaccount_id:"example.testnet"method_name:name_of_a_example.testnet_method(example:viewmethods)args_base64:method_arguments_base_64_encoded
Request example (get_num)
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "dev-1588039999690",
"method_name": "get_num",
"args_base64": "e30="
}
}'
Request example (get_account_staked_balance)
The args_base64 in this example is decoded as {"account_id":"dev-1588039999690"}. The account_id would likely be the validator and not the same account for this particular view function.
curl -X POST https://rpc.ankr.com/near/YOUR_ANKR_API_KEY \
-H "content-type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "dev-1588039999690",
"method_name": "get_account_staked_balance",
"args_base64": "eyJhY2NvdW50X2lkIjoiZGV2LTE1ODgwMzk5OTk2OTAifQ=="
}
}'
Response example
{
"jsonrpc": "2.0",
"result": {
"result": [48],
"logs": [],
"block_height": 17817336,
"block_hash": "4qkA4sUUG8opjH5Q9bL5mWJTnfR4ech879Db1BZXbx6P"
},
"id": "dontcare"
}
Note: [48] is an array of bytes, to be specific it is an ASCII code of 0. near-sdk-rs and near-sdk-js return JSON-serialized results.
For understanding what could go wrong and the error codes involved, refer to corresponding NEAR docs section.