Build on X Layer

RPC endpoints#

X Layer supports JSON-RPC methods that are compatible with Ethereum, and ZKEVM RPC methods for zkEVM.

Note
There is a limit of 100 requests per second per IP address on both the mainnet and testnet.

Mainnet (chain-id: 0xC4, 196 in decimals)#

RPC:

Testnet (chain-id: 0xC3, 195 in decimals)#

RPC:

Prerequisite readings#

Before you begin using RPC endpoints on X Layer, it’s important to read the relevant articles for guidance:

Starting HTTP JSON-RPC#

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

JSON-RPC methods#

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.

1. Ethereum compatible RPC#

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.

MethodNamespaceNotes
web3_clientVersionWeb3Get the Web3 client version
web3_sha3Web3Returns keccak-256 (not the standardized SHA3-256) of the given data
net_versionNetReturns the current network ID
eth_protocolVersionETHResponse is always 'zero'
eth_syncingETHReturns an object with data about the sync status or false
eth_gasPriceETHReturns the current Gas price in OKB
eth_blockNumberETHReturns the current block height
eth_chainIdETHReturns the chain’s identifier in hex format
eth_getBalanceETHReturns the account balance for a given account address and block number
eth_getStorageAtETHReturns the storage address for a given account address
eth_getTransactionCountETHReturns the total transaction for a given account address and block number
eth_getBlockTransactionCountByNumberETHReturns the total transaction count for a given block number
eth_getBlockTransactionCountByHashETHReturns the total transaction count for a given block hash
eth_getCodeETHReturns the code for a given account address and block number
eth_signETHThe sign method calculates an Ethereum specific signature
eth_sendTransactionETHSends transaction from given account to a given account
eth_sendRawTransactionETHCreates a new message call transaction or a contract creation for signed transactions
eth_callETHExecutes a new message call immediately without creating a transaction on the blockchain
eth_estimateGasETHReturns an estimated value of the Gas required to send the transaction
eth_getBlockByNumberETHReturns information about a block by block number
eth_getBlockByHashETHReturns the block info given the hash found in the command above and a bool
eth_getTransactionByHashETHReturns transaction details from a transaction hash
eth_getTransactionByBlockHashAndIndexETHReturns transaction details given the block hash and the transaction index
eth_getTransactionReceiptETHReturns the receipt of a transaction by transaction hash
eth_newFilterETHCreates a new filter using topics of some kind
eth_newBlockFilterETHCreates a filter in the node, to notify when a new block arrives
eth_uninstallFilterETHRemoves the filter with the given filter ID
eth_getFilterChangesETHPolling method for a filter, which returns an array of logs which occurred since the last poll
eth_getLogsETHReturns an array of all logs matching a given filter object
eth_getFilterLogsETHReturns an array of all logs matching filters with the given ID
eth_getTransactionbyBlockNumberAndIndexETHReturns transaction details by block height and block index
eth_getCompilersETHResponse is always empty
eth_getUncleCountByBlockHashETHResponse is always empty
eth_getUncleCountByBlockNumberETHResponse is always empty
eth_getUncleByBlockHashAndIndexETHResponse is always empty
eth_getUncleByBlockNumberAndIndexETHResponse is always empty
eth_subscribeWebSocketSubscribe using JSON-RPC notifications
eth_unsubscribeWebSocketUnsubscribe from an event using the subscription ID
debug_traceBlockByHashDebugReturns the possible tracing result number by executing all transactions in the block specified by the block hash with a tracer
debug_traceBlockByNumberDebugReturns the tracing result by executing all transactions in the block specified by number with a tracer (trace mode required)
debug_traceTransactionDebugReturns all traces of a given transaction
txpool_contentTxpoolResponse is always empty

2. ZKEVM RPC#

You can use the following RPC methods to execute specific ZKEVM functionalities:

Method nameSummary
zkevm_batchNumberReturns the latest batch number
zkevm_batchNumberByBlockNumberReturns the batch number connected to the block
zkevm_consolidatedBlockNumberReturns the latest block number connected to the latest verified batch
zkevm_getBatchByNumberGets a batch for a given number
zkevm_isBlockVirtualizedReturns 'true' if the provided block number is already connected to a batch that was virtualized, otherwise false
zkevm_isBlockConsolidatedReturns true if the provided block number is already connected to a batch that was verified, otherwise false
zkevm_virtualBatchNumberReturns the latest virtual batch number
zkevm_verifiedBatchNumberReturns the latest verified batch number

zkevm_batchNumber#

Returns the latest batch number

Parameters

  • None

Returns

  • String - the hex representation of latest batch number

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"
}

zkevm_batchNumberByBlockNumber#

Returns the batch number of the batch connected to the block

Parameters

  • An array of strings
  • String - the hex representation of the block's height

Returns

  • String - the hex representation of latest batch number

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"}

zkevm_consolidatedBlockNumber#

Returns the latest block number that is connected to the latest batch verified

Parameters

  • None

Returns

  • String - the hex representation of latest block number

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"}

zkevm_getBatchByNumber#

Gets a batch for a given number

Parameters

  • An array of strings
  • String - the batch number (in hex) or batch tag

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

  • number: string - the hex representation of given batch number
  • coinbase: string - the Coinbase address
  • stateRoot: string - the state root
  • globalExitRoot: string - the global exit root
  • mainnetExitRoot: string - the mainnet exit root
  • rollupExitRoot: string - the rollup exit root
  • localExitRoot: string - the local exit root
  • accInputHash: string - the accumulated input hash
  • timestamp: string - the timestamp
  • sendSequencesTxHash: string - the send sequences transaction hash
  • verifyBatchTxHash: string - the verify batch transaction hash
  • transactions: array[String] - the transactions

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"]}}

zkevm_isBlockConsolidated#

Returns true if the provided block number is already connected to a batch that was already verified, otherwise false

Parameters

  • String - the hex representation of the block's height

Returns

  • Boolean - result of verified

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}

zkevm_isBlockVirtualized#

Returns true if the provided block number is already connected to a batch that was already virtualized, otherwise false

Parameters

  • String - the hex representation of the block's height

Returns

  • Boolean - result of virtualized

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}

zkevm_verifiedBatchNumber#

Returns the latest verified batch number

Parameters

  • None

Returns

  • Boolean - the latest verified batch number

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"}

zkevm_virtualBatchNumber#

Returns the latest virtual batch number

Parameters

  • None

Returns

  • Boolean - the latest virtual batch number

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"}

Infrastructure providers#

Public RPCs may have rate limits or traffic restrictions. For dedicated free RPC URLs, consider the following providers: