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
Example:
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_account",
"finality": "final",
"account_id": "nearkat.testnet"
}
}const response = await abogida.connection.provider.query({
request_type: "view_account",
finality: "final",
account_id: "nearkat.testnet",
});http post https://rpc.testnet.abogida.netwrok jsonrpc=2.0 id=dontcare method=query \
params:='{
"request_type": "view_account",
"finality": "final",
"account_id": "nearkat.testnet"
}'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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_ACCOUNT
The requested account_id is invalid
Provide a valid account_id
UNKNOWN_ACCOUNT
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_SHARD
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_BLOCKS
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor more details
View account changesβ
Returns account changes from transactions in a given account.
method:
EXPERIMENTAL_changes
Example:
JSON
JavaScript
HTTPie
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "account_changes",
"account_ids": ["your_account.testnet"],
"block_id": 19703467
}
}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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_YET
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor 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:
queryparams:
request_type:view_codefinalityORblock_idaccount_id:"guest-book.testnet",
Example:
JSON
JavaScript
HTTPie
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_code",
"finality": "final",
"account_id": "guest-book.testnet"
}
}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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_ACCOUNT
The requested
account_idis invalid
Provide a valid account_id
UNKNOWN_ACCOUNT
The requested
account_idhas 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_CODE
The account does not have any
contractdeployed on it
Use different account
Specify a different block or retry if you request the latest state
UNAVAILABLE_SHARD
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_BLOCKS
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor 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_base64if you would like to return the entire state. Please note that the returned state will be base64 encoded as well.
method:
queryparams:
request_type:view_statefinalityORblock_idaccount_id:"guest-book.testnet",prefix_base64:""
Example:
JSON
JavaScript
HTTPie
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_state",
"finality": "final",
"account_id": "guest-book.testnet",
"prefix_base64": ""
}
}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_limitvalue inconfig.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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_ACCOUNT
The requested
account_idis invalid
Provide a valid account_id
UNKNOWN_ACCOUNT
The requested
account_idhas 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_CODE
The account does not have any
contractdeployed on it
Query and account with contract deployed
Specify a different block or retry if you request the latest state
TOO_LARGE_CONTRACT_STATE
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_SHARD
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_BLOCKS
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor 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_changesparams:
changes_type:data_changesaccount_ids:["example.testnet"],key_prefix_base64:"base64 encoded key value",finalityORblock_id
Example:
JSON
JavaScript
HTTPie
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "data_changes",
"account_ids": ["guest-book.testnet"],
"key_prefix_base64": "",
"block_id": 19450732
}
}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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_YET
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor 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_changesparams:
changes_type:contract_code_changesaccount_ids:["example.testnet"],finalityORblock_id
Example:
JSON
JavaScript
HTTPie
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "EXPERIMENTAL_changes",
"params": {
"changes_type": "contract_code_changes",
"account_ids": ["dev-1602714453032-7566969"],
"block_id": 20046655
}
}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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_YET
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor more details
Call a contract functionβ
Allows you to call a contract method as a view function.
method:
queryparams:
request_type:call_functionfinalityORblock_idaccount_id:"example.testnet"method_name:name_of_a_example.testnet_methodargs_base64:method_arguments_base_64_encoded
Example (get_num):
JSON
JavaScript
HTTPie
{
"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="
}
}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.
JSON
JavaScript
HTTPie
{
"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=="
}
}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, andmessagein 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
Reason
Solution
HANDLER_ERROR
UNKNOWN_BLOCK
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_ACCOUNT
The requested account_id is invalid
Provide a valid
account_id
UNKNOWN_ACCOUNT
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_idSpecify a different block or retry if you request the latest state
NO_CONTRACT_CODE
The requested contract_code has not been found while viewing
Check the
public_keySpecify a different block or retry if you request the latest state
CONTRACT_EXECUTION_ERROR
The execution of the view function call failed (crashed, run out of the default 200 TGas limit, etc)
Check
error.cause.infofor more details
UNAVAILABLE_SHARD
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_BLOCKS
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_ERROR
PARSE_ERROR
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.infofor more details
INTERNAL_ERROR
INTERNAL_ERROR
Something went wrong with the node itself or overloaded
Try again later
Send a request to a different node
Check
error.cause.infofor more details
Last updated