Skip to main content

JSON RPC Overview

JSON-RPC Conformance Reference

Type and data information for validation and conformance.

Validation and Types

Below type description can also be found in EIP-1474

Quantity

Values of a field of QUANTITY type MUST be encoded as a hexadecimal string with a 0x prefix and the leading 0s stripped (except for the case of encoding the value 0) matching the regular expression

^0x(?:0|(?:[a-fA-F1-9][a-fA-F0-9]*))
  • A Quantity value MUST be hex-encoded.
  • A Quantity value MUST be "0x"-prefixed.
  • A Quantity value MUST be expressed using the fewest possible hex digits per byte.
  • A Quantity value MUST express zero as "0x0".

Data

Values of a field of DATA type MUST be encoded as a hexadecimal string with a 0x prefix matching the regular expression `

^0x(?:[a-fA-F0-9]{2})*
  • A Data value MUST be hex-encoded.
  • A Data value MUST be “0x”-prefixed.
  • A Data value MUST be expressed using two hex digits per byte.

What is the difference between DATA and QUANTITY?

The difference between the types “DATA” and “QUANTITY” is that “DATA” always comes specified with a required length (ex: 20 Bytes), so you'll need to make sure the string you pass in is the right length. In contrast, QUANTITY does not have length requirements.

For example given a parameter type: “DATA, 20 Bytes”, a valid input would be:

"0x0000000000000000000000000000000000000003"

note: every two hex characters make one byte, so that string is 0x followed by forty hex characters

However, if this were a QUANTITY, a valid input would be:

"0x3"

Block Identifier

Since there is no way to clearly distinguish between a Data parameter and a Quantity parameter, EIP-1898 provides a format to specify a block either using the block hash or block number. The block identifier is a JSON object with the following fields:

PositionNameTypeDescription
0AblockNumberQuantityThe block in the canonical chain with this number
0BblockHashDataThe block uniquely identified by this hash. The blockNumber and blockHash properties are mutually exclusive; exactly one of them must be set.
1BrequireCanonicalboolean(optional) Whether to throw an error if the block is not in the canonical chain as described below. Only allowed in conjunction with the blockHash tag. Defaults to false.

If the block is not found, the callee SHOULD raise a JSON-RPC error (the recommended error code is -32001: Resource not found. If the tag is blockHash and requireCanonical is true, the callee SHOULD additionally raise a JSON-RPC error if the block is not in the canonical chain (the recommended error code is -32000: Invalid input and in any case should be different than the error code for the block not found case so that the caller can distinguish the cases). The block-not-found check SHOULD take precedence over the block-is-canonical check, so that if the block is not found the callee raises block-not-found rather than block-not-canonical.

Errors

The list of error codes introduced by this specification can be found below.

CodeMessageMeaning
-32700Parse errorInvalid JSON was received by the server.
-32600Invalid RequestThe JSON sent is not a valid Request object.
-32601Method not foundThe method does not exist / is not available.
-32602Invalid paramsInvalid method parameter(s).
-32603Internal errorInternal JSON-RPC error.
-32000Server errorGeneric client error while processing request.
-38001Unknown payloadPayload does not exist / is not available.
-38002Invalid payload attributesPayload attributes are invalid / inconsistent.

Each error returns a null data value, except -32000 which returns the data object with a err member that explains the error encountered.

Authorization Error Codes

CodePossible Return messageDescription
1UnauthorizedShould be used when some action is not authorized, e.g. sending from a locked account.
2Action not allowedShould be used when some action is not allowed, e.g. preventing an action, while another depending action is processing on, like sending again when a confirmation popup is shown to the user (?).
3Execution errorWill contain a subset of custom errors in the data field. See below.

Ethereum Error Codes

Custom error 3 can contain custom error(s) to further explain what went wrong.
They will be contained in the data field of the RPC error message as follows:

CodePossible Return messageDescription
100X doesn’t existShould be used when something which should be there is not found. (Doesn’t apply to eth_getTransactionBy_ and eth_getBlock_. They return a success with value null)
101Requires etherShould be used for actions which require something else, e.g. gas or a value.
102Gas too lowShould be used when a to low value of gas was given.
103Gas limits exceededShould be used when a limit is exceeded, e.g. for the gas limit in a block.
104RejectedShould be used when an action was rejected, e.g. because of its content (too long contract code, containing wrong characters ?, should differ from -32602 - Invalid params).
105Ether too lowShould be used when a to low value of Ether was given.

Ethereum Generic Codes

CodePossible Return messageDescription
106TimeoutShould be used when an action timedout.
107ConflictShould be used when an action conflicts with another (ongoing?) action.