Skip to main content

RPC Endpoints

Sandbox

heads up

RPC endpoints in this section are only available on the local sandbox node.


Patch State

Patch account, access keys, contract code, or contract state. Only additions and mutations are supported. No deletions. Account, access keys, contract code, and contract states have different formats. See the example for details about their format.

  • method: sandbox_patch_state
  • params:
    • records: an array of state records to patch. Every state record can be one of Account, AccessKey, Contract (for contract code), or Data (for contract state).

Example:

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "sandbox_patch_state",
"params": {
"records": [
{
"Account": {
"account_id": "abcdef.test.near",
"account": {
"amount": "100000000000",
"locked": "0",
"code_hash": "7KoFshMQkdyo5iTx8P2LbLu9jQpxRn24d27FrKShNVXs",
"storage_usage": 200000
}
}
},
{
"Contract": {
"account_id": "abcdef.test.near",
"code": "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="
}
},
{
"AccessKey": {
"account_id": "abcdef.test.near",
"public_key": "ed25519:CngrirkGDwSS75EKczcsUsciRtMmHd9iicrrYxz4uckD",
"access_key": {
"nonce": 0,
"permission": "FullAccess"
}
}
},
{
"Data": {
"account_id": "abcdef.test.near",
"data_key": "U1RBVEU=",
"value": "AwAAAA8AAABhbGljZS50ZXN0Lm5lYXIFAAAAaGVsbG8NAAAAYm9iLnRlc3QubmVhcgUAAAB3b3JsZAoAAABhbGljZS5uZWFyCwAAAGhlbGxvIHdvcmxk"
}
}
]
}
}
Example response:

{
"id": "dontcare",
"jsonrpc": "2.0",
"result": {}
}

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 sandbox_patch_state method:

ERROR_TYPE
error.name
ERROR_CAUSE
error.cause.name
ReasonSolution
REQUEST_VALIDATION_ERRORPARSE_ERRORPassed 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_ERRORSomething 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