zkSync JSON-RPC API

📘

Supported on zkSync (mainnet) only.

API Endpoint

The format of a zkSync API endpoint is
https://open-platform.nodereal.io/{{apiKey}}/zksync/

Here is an example:
https://open-platform.nodereal.io/4c0a1c23661a4e26bcbcwed461e34ea9/zksync/

zkSync JSON-RPC API

zks_estimateFee

Returns the fee for the transaction.

Parameters

  • from - string - The address from which the transaction is sent
  • to - string - The address to which the transaction is addressed
  • data - string - The hash of the block

Returns

  • gas_limit- The maximum amount of gas that the transaction is allowed to consume
  • gas_per_pubdata_limit- The amount of gas that is consumed per public data byte
  • max_fee_per_gas- The maximum fee (measured in wei) that can be paid per gas unit
  • max_priority_fee_per_gas- The maximum priority fee (measured in wei) that can be paid per gas unit

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_estimateFee","params":[{ "from": "0x1111111111111111111111111111111111111111", "to":"0x2222222222222222222222222222222222222222", "data": "0xffffffff" } ],"id":1,"jsonrpc":"2.0"}'

zks_estimateGasL1ToL2

Returns an estimate of the gas required for a L1 to L2 transaction.

Parameters

  • from - string - The address from which the transaction is sent
  • to - string - The address to which the transaction is addressed
  • data - string - The data associated with the transaction

Returns

  • result- The estimate of the gas required for a L1 to L2 transaction

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_estimateGasL1ToL2","params":[{ "from": "0x1111111111111111111111111111111111111111", "to":"0x2222222222222222222222222222222222222222", "data": "0xffffffff" } ],"id":1,"jsonrpc":"2.0"}'

zks_getAllAccountBalances

Returns all balances for confirmed tokens given by an account address.

Parameters

  • address - string - The account address

Returns

  • address- The address for which the balances are being returned
    • balance- The account balance represented in hexadecimal format

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getAllAccountBalances","params":["0x98E9D288743839e96A8005a6B51C770Bbf7788C0" ],"id":1,"jsonrpc":"2.0"}'

zks_getBlockDetails

Returns additional zkSync-specific information about the L2 block.

Parameters

  • block - string - The number of the block

Returns

  • baseSystemContractsHashes- object - An object containing hashes of the base system contracts used in the transaction
    • bootloader- The hash of the bootloader contract
    • default_aa- The hash of the default account contract
  • commitTxHash - The hash of the transaction committed to the network
  • committedAt - The timestamp when the transaction was committed to the network
  • executeTxHash - The hash of the transaction executed on the network
  • executedAt - The timestamp when the transaction was executed on the network
  • l1BatchNumber - The batch number of the transaction on the L1 (Ethereum) network
  • l1GasPrice - The gas price used for the transaction on the L1 network
  • l1TxCount - The number of transactions related to this batch on the L1 network
  • l2FairGasPrice - The fair gas price used for the transaction on the L2 (zkSync) network
  • l2TxCount - The total number of transactions on the L2 network
  • number - The transaction number
  • operatorAddress - The address of the operator who executed the transaction
  • proveTxHash - The hash of the proof transaction on the L1 network
  • provenAt - The timestamp when the proof transaction was done on the L1 network
  • rootHash - The root hash representing the state of the network after the transaction
  • status - The status of the transaction
  • timestamp - The timestamp of the transaction

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getBlockDetails","params":[140599],"id":1,"jsonrpc":"2.0"}'

zks_getBridgeContracts

Returns L1/L2 addresses of default bridges.

Parameters

  • N/A

Returns

  • l1Erc20DefaultBridge- The address of the default bridge contract responsible for handling ERC-20 token transfers from the L1 network to the L2 network
  • l2Erc20DefaultBridge- The address of the default bridge contract responsible for handling ERC-20 token transfers from the L2 network to the L1 network

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getBridgeContracts","params":[ ],"id":1,"jsonrpc":"2.0"}'

zks_getBytecodeByHash

Returns bytecode of a transaction given by its hash.

Parameters

  • hash - string - The hash os the transaction

Returns

  • result- The byte code of the given transaction

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getBytecodeByHash","params":["0x0100067d861e2f5717a12c3e869cfb657793b86bbb0caa05cc1421f16c5217bc" ],"id":1,"jsonrpc":"2.0"}'

zks_getConfirmedTokens

Returns information of all tokens within a given range.

Parameters

  • from - integer - The token id from which to start returning the information about the tokens
  • limit - integer - The number of token to be returned

Returns

  • result- array - The result array which has the list of all token which contains the following fields:
    • decimals- The number of decimal places for the token
    • l1Address- The address of the token on the L1 network
    • l2Address- The address of the token on the L2 network
    • name- The name of the token
    • symbol- The symbol or ticker of the token

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getConfirmedTokens","params":[1, 3 ],"id":1,"jsonrpc":"2.0"}'

zks_getL1BatchBlockRange

Returns the range of blocks contained within a batch identified by its batch number.

Parameters

  • batch - integer - The layer 1 batch number

Returns

  • result- The range of blocks contained within a given batch. The range is given by beginning/end block numbers in hexadecimal format

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getL1BatchBlockRange","params":[12345 ],"id":1,"jsonrpc":"2.0"}'

zks_getL1BatchDetails

Returns data pertaining to a given batch.

Parameters

  • batch - integer - The layer 1 batch number

Returns

  • baseSystemContractsHashes- object - An object containing hashes of the base system contracts used in the transaction
    • bootloader- The hash of the bootloader contract
    • default_aa- The hash of the default account contract
  • commitTxHash- The hash of the transaction committed to the network
  • committedAt- The timestamp when the transaction was committed to the network
  • executeTxHash- The hash of the transaction executed on the network
  • executedAt- The timestamp when the transaction was executed on the network
  • l1BatchNumber- The batch number of the transaction on the L1 (Ethereum) network
  • l1GasPrice- The gas price used for the transaction on the L1 network
  • l1TxCount- The number of transactions related to this batch on the L1 network
  • l2FairGasPrice- The fair gas price used for the transaction on the L2 (zkSync) network
  • l2TxCount- The total number of transactions on the L2 network
  • number- The transaction number
  • operatorAddress- The address of the operator who executed the transaction
  • proveTxHash- The hash of the proof transaction on the L1 network
  • provenAt- The timestamp when the proof transaction was done on the L1 network
  • rootHash- The root hash representing the state of the network after the transaction
  • status- The status of the transaction
  • timestamp- The timestamp of the transaction

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getL1BatchDetails","params":[12345 ],"id":1,"jsonrpc":"2.0"}'

zks_getL2ToL1LogProof

Returns the proof for the corresponding L2 to L1 log, given a transaction hash and the index of the L2 to L1 log produced within the transaction.

Parameters

  • tx_hash - string - The hash of the L2 transaction
  • l2_to_l1_log_index - integer - The index of the L2 to L1 log in the transaction

Returns

  • id- The position of the leaf in the Merkle tree of L2->L1 messages for the block
  • proof- The Merkle proof for the message
  • root- The root hash representing the Merkle tree root at the time the L2 to L1 log was generated

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getL2ToL1LogProof","params":["0x2a1c6c74b184965c0cb015aae9ea134fd96215d2e4f4979cfec12563295f610e" ],"id":1,"jsonrpc":"2.0"}'

zks_getL2ToL1MsgProof

Returns the proof for a message sent via the L1Messenger system contract, given a block, sender, message, and an optional message log index containing the L1->L2 message.

Parameters

  • block - integer - The number of the block where the message was emitted
  • sender - string - The sender of the message
  • msg - string - The keccak256 hash of the sent message
  • l2_log_position - string - The index in the block of the event that was emitted by the L1Messenger when submitting this message

Returns

  • id- The position of the leaf in the Merkle tree of L2->L1 messages for the block
  • proof- The Merkle proof for the message
  • root- The root hash representing the Merkle tree root at the time the L2 to L1 log was generated

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getL2ToL1MsgProof","params":[5187, "0x87869cb87c4Fa78ca278dF358E890FF73B42a39E", "0x22de7debaa98758afdaee89f447ff43bab5da3de6acca7528b281cc2f1be2ee9" ],"id":1,"jsonrpc":"2.0"}'

zks_getMainContract

Returns the address of the zkSync Era contract.

Parameters

  • N/A

Returns

  • result- The address of the zkSync Era contract

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getMainContract","params":[],"id":1,"jsonrpc":"2.0"}'

zks_getRawBlockTransactions

Returns data of transactions in a block.

Parameters

  • block - integer - The block number

Returns

  • common_data- object - An object containing common data related to the executed transaction
    • L1- object - An object containing information about the corresponding transaction on the L1 network
      • canonicalTxHash- The canonical hash of the transaction on the L1 network
      • deadlineBlock- The deadline block for the transaction on the L1 network
      • ethBlock- The Ethereum block number for the transaction
      • ethHash- The Ethereum transaction hash for the transaction
      • fullFee- The full fee for the transaction in hexadecimal format
      • gasLimit- The gas limit for the transaction in hexadecimal format
      • gasPerPubdataLimit- The gas per public data limit for the transaction in hexadecimal format
      • layer2TipFee- The tip fee for the transaction on the L2 network in hexadecimal format
      • maxFeePerGas- The maximum fee per gas for the transaction in hexadecimal format
      • opProcessingType- The type of operation processing used for the transaction
      • priorityQueueType- The type of priority queue used for the transaction
      • refundRecipient- The recipient address for any potential refund for the transaction
      • sender- The sender address of the transaction
      • serialId- The serial ID of the transaction
      • toMint- The address to mint tokens for the transaction
  • execute- object - An object containing information about the execution of the transaction
    • calldata- The calldata for the execution in hexadecimal format
    • contractAddress- The contract address for the execution
    • factoryDeps- An array containing factory dependencies for the execution
    • value- The value for the execution in hexadecimal format
  • received_timestamp_ms- The timestamp when the transaction was received

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getRawBlockTransactions","params":[5817],"id":1,"jsonrpc":"2.0"}'

zks_getTestnetPaymaster

Returns the address of the testnet paymaster, which is available on testnets and facilitates fee payments in ERC-20 compatible tokens.

Parameters

  • N/A

Returns

  • result- The address of the testnet paymaster, which is available on testnets and facilitates fee payments in ERC-20 compatible tokens

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getTestnetPaymaster","params":[],"id":1,"jsonrpc":"2.0"}'

zks_getTokenPrice

Returns the price of a given token in USD.

Parameters

  • address - string - The address of the token

Returns

  • result- The price of a given token in USD

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getTokenPrice","params":["0x0000000000000000000000000000000000000000" ],"id":1,"jsonrpc":"2.0"}'

zks_getTransactionDetails

Returns data from a specific transaction identified by its transaction hash.

Parameters

  • hash - string - The transaction hash encoded in hexadecimal format

Returns

  • ethCommitTxHash- The transaction hash of the commit transaction
  • ethExecuteTxHash- The transaction hash of the execute transaction
  • ethProveTxHash- The Ethereum transaction hash of the proof transaction
  • fee- The fee amount for the transaction in hexadecimal format
  • gasPerPubdata- The gas per public data for the transaction in hexadecimal format
  • initiatorAddress- The ddress of the transaction initiator
  • isL1Originated- A boolean flag indicating whether the transaction originated from L1 network
  • receivedAt- The timestamp when the transaction was received on the L2 network
  • status- The status of the transaction

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_getTransactionDetails","params":["0x60944a2b978561ba6b0b1962fec4f51c80402b8aa61c07b8879233d34a8f7775" ],"id":1,"jsonrpc":"2.0"}'

zks_L1BatchNumber

Returns the latest L1 batch number.

Parameters

  • N/A

Returns

  • result- The latest L1 batch number

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_L1BatchNumber","params":[ ],"id":1,"jsonrpc":"2.0"}'

zks_L1ChainId

Returns the chain id of the underlying L1.

Parameters

  • N/A

Returns

  • result- The chain id of the underlying L1

Example

curl https://open-platform.nodereal.io/{{apiKey}}/zksync/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"zks_L1ChainId","params":[],"id":1,"jsonrpc":"2.0"}'