zkevm_batchNumberByBlockNumber | zkEVM

Polygon zkEVM API method that returns the batch number associated with a given block number in the zkEVM chain.

In the zkEVM chain, multiple transactions are grouped together and verified as a single batch using zero-knowledge proofs. At the time of writing, the Polygon zkEVM works such that all individual transactions of a particular batch are processed as a separate block so that multiple blocks can be associated with a single batch of transactions.

Parameters

  • blockNumber — a hexadecimal string representing a block number in the Polygon zkEVM chain.

Response

  • result — a string representing the batch number of the specified block number in the zkEVM chain.

zkevm_batchNumberByBlockNumber code examples

const Web3 = require("web3");
const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT";
const web3 = new Web3(NODE_URL);

web3.extend({
    property: 'zkEVM',
    methods: [{
      name: 'batchNumberByBlockNumber',
      call: 'zkevm_batchNumberByBlockNumber',
      params: 1,
      inputFormatter: null,
      outputFormatter: null
    }]
  });

async function batchNumberByBlockNumber(blockId) {
  const output = await web3.zkEVM.batchNumberByBlockNumber(blockId)
  console.log(output)
}

batchNumberByBlockNumber("0xD65B");

const ethers = require('ethers');
const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT";
const provider = new ethers.JsonRpcProvider(NODE_URL);

const batchNumberByBlockNumber = async (blockNumber) => {

    // This will return the value in Hex
 const batchNumber = await provider.send("zkevm_batchNumberByBlockNumber", [blockNumber]);
    console.log(`Batch Number: ${batchNumber}`);
  };

// replace the hexadecimal block number with the one you want to query
batchNumberByBlockNumber("0xD65B");

from web3 import Web3
node_url = "YOUR_CHAINSTACK_ENDPOINT"
web3 = Web3(Web3.HTTPProvider(node_url))
output = web3.provider.make_request('zkevm_batchNumberByBlockNumber', ["0xD65B"])
print(output)

Try the zkevm_batchNumberByBlockNumber RPC method yourself

Language
Click Try It! to start a request and see the response here!