X Layer supports JSON-RPC methods that are compatible with Ethereum, and ZKEVM RPC methods for zkEVM.
RPC:
RPC:
Before you begin using RPC endpoints on X Layer, it’s important to read the relevant articles for guidance:
To start the HTTP JSON-RPC, curl method is recommended:
# mainnet
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" https://rpc.xlayer.tech
# testnet
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" https://testrpc.xlayer.tech
There are two types of RPC methods on X Layer, one is Ethereum compatible RPC, and the other one is ZKEVM RPC. Each RPC offers specific functionalities.
Here you will find the list of all supported JSON RPC endpoints and the differences between them in comparison to the default behavior of an Ethereum node. If a specific endpoint is not in the list below, it means that this specific endpoint is not supported yet. You can find more details in Ethereum’s JSON-RPC doc.
Method | Namespace | Notes |
---|---|---|
web3_clientVersion | Web3 | Get the Web3 client version |
web3_sha3 | Web3 | Returns keccak-256 (not the standardized SHA3-256) of the given data |
net_version | Net | Returns the current network ID |
eth_protocolVersion | ETH | Response is always 'zero' |
eth_syncing | ETH | Returns an object with data about the sync status or false |
eth_gasPrice | ETH | Returns the current Gas price in OKB |
eth_blockNumber | ETH | Returns the current block height |
eth_chainId | ETH | Returns the chain’s identifier in hex format |
eth_getBalance | ETH | Returns the account balance for a given account address and block number |
eth_getStorageAt | ETH | Returns the storage address for a given account address |
eth_getTransactionCount | ETH | Returns the total transaction for a given account address and block number |
eth_getBlockTransactionCountByNumber | ETH | Returns the total transaction count for a given block number |
eth_getBlockTransactionCountByHash | ETH | Returns the total transaction count for a given block hash |
eth_getCode | ETH | Returns the code for a given account address and block number |
eth_sign | ETH | The sign method calculates an Ethereum specific signature |
eth_sendTransaction | ETH | Sends transaction from given account to a given account |
eth_sendRawTransaction | ETH | Creates a new message call transaction or a contract creation for signed transactions |
eth_call | ETH | Executes a new message call immediately without creating a transaction on the blockchain |
eth_estimateGas | ETH | Returns an estimated value of the Gas required to send the transaction |
eth_getBlockByNumber | ETH | Returns information about a block by block number |
eth_getBlockByHash | ETH | Returns the block info given the hash found in the command above and a bool |
eth_getTransactionByHash | ETH | Returns transaction details from a transaction hash |
eth_getTransactionByBlockHashAndIndex | ETH | Returns transaction details given the block hash and the transaction index |
eth_getTransactionReceipt | ETH | Returns the receipt of a transaction by transaction hash |
eth_newFilter | ETH | Creates a new filter using topics of some kind |
eth_newBlockFilter | ETH | Creates a filter in the node, to notify when a new block arrives |
eth_uninstallFilter | ETH | Removes the filter with the given filter ID |
eth_getFilterChanges | ETH | Polling method for a filter, which returns an array of logs which occurred since the last poll |
eth_getLogs | ETH | Returns an array of all logs matching a given filter object |
eth_getFilterLogs | ETH | Returns an array of all logs matching filters with the given ID |
eth_getTransactionbyBlockNumberAndIndex | ETH | Returns transaction details by block height and block index |
eth_getCompilers | ETH | Response is always empty |
eth_getUncleCountByBlockHash | ETH | Response is always empty |
eth_getUncleCountByBlockNumber | ETH | Response is always empty |
eth_getUncleByBlockHashAndIndex | ETH | Response is always empty |
eth_getUncleByBlockNumberAndIndex | ETH | Response is always empty |
eth_subscribe | WebSocket | Subscribe using JSON-RPC notifications |
eth_unsubscribe | WebSocket | Unsubscribe from an event using the subscription ID |
debug_traceBlockByHash | Debug | Returns the possible tracing result number by executing all transactions in the block specified by the block hash with a tracer |
debug_traceBlockByNumber | Debug | Returns the tracing result by executing all transactions in the block specified by number with a tracer (trace mode required) |
debug_traceTransaction | Debug | Returns all traces of a given transaction |
txpool_content | Txpool | Response is always empty |
You can use the following RPC methods to execute specific ZKEVM functionalities:
Method name | Summary |
---|---|
zkevm_batchNumber | Returns the latest batch number |
zkevm_batchNumberByBlockNumber | Returns the batch number connected to the block |
zkevm_consolidatedBlockNumber | Returns the latest block number connected to the latest verified batch |
zkevm_getBatchByNumber | Gets a batch for a given number |
zkevm_isBlockVirtualized | Returns 'true' if the provided block number is already connected to a batch that was virtualized, otherwise false |
zkevm_isBlockConsolidated | Returns true if the provided block number is already connected to a batch that was verified, otherwise false |
zkevm_virtualBatchNumber | Returns the latest virtual batch number |
zkevm_verifiedBatchNumber | Returns the latest verified batch number |
Returns the latest batch number
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_batchNumber",
"params": [],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x82"
}
Returns the batch number of the batch connected to the block
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_batchNumberByBlockNumber",
"params": ["0x2"],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":"0x4"}
Returns the latest block number that is connected to the latest batch verified
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_consolidatedBlockNumber",
"params": [],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":"0x84"}
Gets a batch for a given number
Parameters
The optional batch height descriptions are:
latest
- This is the most recent batch in the canonical chain observed by the client. This batch may be re-orged out of the canonical chain even under healthy/normal conditions.earliest
- This is the lowest-numbered batch the client has available. Intuitively, you can think of this as the first batch created.Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_getBatchByNumber",
"params": ["0x2"],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":{"number":"0x2","coinbase":"0xcec3f45ca495d89a37ff680c087df91741aa9ef6","stateRoot":"0xe683502473ee45ab47f55ea254bb8637f5324250e758e391476b15388f818617","globalExitRoot":"0xe95ee03593d34c4ff03c2e5369cf6eaef4e3e19fc66ab1c93d512fcccbc33f41","mainnetExitRoot":"0x2c352238d75ce63aa81d466c6d17aa41bc12dce33c954a10d6752f6863e42511","rollupExitRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","localExitRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","accInputHash":"0xb36f9860fd62baa2ecbf52ed337a0e9686bce2441909c80f541b98c88601c84c","timestamp":"0x64f5d7a1","sendSequencesTxHash":"0x77f311f450e7d1075b4c5e51e2ac727c74082eed7494d5e7d74fa40f4ff6b071","verifyBatchTxHash":"0x519da5b4a2f6ce344f749e5e553588b61b661280a9d8dfd0cc6b03cab74cb0da","transactions":["0x5e33e1eb2064e3bad97b3734b2aa25882ecd88f9f91da81d1526dbbc90a531b8"]}}
Returns true
if the provided block number is already connected to a batch that was already verified, otherwise false
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_isBlockConsolidated",
"params": ["0x1"],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":true}
Returns true
if the provided block number is already connected to a batch that was already virtualized, otherwise false
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_isBlockVirtualized",
"params": ["0x12"],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":true}
Returns the latest verified batch number
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_verifiedBatchNumber",
"params": [],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":"0x81"}
Returns the latest virtual batch number
Parameters
Returns
Example
// Request
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "zkevm_virtualBatchNumber",
"params": [],
"id": 1
}' -H "Content-Type: application/json" https://xlayertestrpc.okx.com/
// Response
{"jsonrpc":"2.0","id":1,"result":"0x81"}
Public RPCs may have rate limits or traffic restrictions. For dedicated free RPC URLs, consider the following providers: