Conventions
Hex value encoding
Two key data types get passed over JSON: unformatted byte arrays and quantities. Both are passed with a hex encoding but with different requirements for formatting.
Quantities
When encoding quantities (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0").
Here are some examples:
- 0x41 (65 in decimal)
- 0x400 (1024 in decimal)
- WRONG: 0x (should always have at least one digit - zero is "0x0")
- WRONG: 0x0400 (no leading zeroes allowed)
- WRONG: ff (must be prefixed 0x)
Unformatted data
When encoding unformatted data (byte arrays, account addresses, hashes, bytecode arrays): encode as hex, prefix with "0x", two hex digits per byte.
Here are some examples:
- 0x41 (size 1, "A")
- 0x004200 (size 3, "\0B\0")
- 0x (size 0, "")
- WRONG: 0xf0f0f (must be even number of digits)
- WRONG: 004200 (must be prefixed 0x)
Error Codes
Category | Error Code | Message | Description |
---|---|---|---|
Standard | -32700 | Parse error | The JSON payload could not be parsed due to invalid syntax. |
Standard | -32600 | Invalid request | The JSON object is not a valid request structure. |
Standard | -32601 | Method not found | The requested method does not exist or is not available. |
Standard | -32602 | Invalid params | The parameters provided to the method are invalid or malformed. |
Standard | -32603 | Internal error | An unspecified internal error occurred within the JSON-RPC framework. |
The default block parameter
When requests are made that act on the state of Ethereum, the last default block parameter determines the height of the block.
The following options are possible for the defaultBlock parameter:
- HEX String - an integer block number
- String "earliest" for the earliest/genesis block
- String "latest" - for the latest mined block
- String "safe" - for the latest safe head block
- String "finalized" - for the latest finalized block
- String "pending" - for the pending state/transactions
Overview
Explore the comprehensive guide to the ZKsync Era JSON-RPC API, offering seamless Ethereum integration and advanced Layer 2 functionalities for developers.
ZKs JSON-RPC API
Overview of the JSON-RPC API methods specific to ZKsync Era, detailing operations and functionalities within the ZKsync Era ecosystem.