I am running in a private ethereum network which I init with a genesis.json file that contains "gasLimit": "31415926" Now I am wondering how I can read that via web3, any suggestions? (I want to make sure the limit is set correctly).


Asking for the last block mined, it will return the gasLimit of the block https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgetblock

var block = web3.eth.getBlock("latest");
console.log("gasLimit: " + block.gasLimit);
  • 2
    The gas limit I am getting from this is absurdly high (For an individual transaction), but this is the gas limit for the whole block though, correct? If so, then to estimate the gas I should use on an individual transaction, do I just divide by the number of transactions in said block? Or is it safe to just always use the gasLimit minimum of 21000? – Albert Renshaw Dec 12 '18 at 1:28

Here is the exact answer:

var block = await web3js.eth.getBlock("latest");
var gasLimit = block.gasLimit/block.transactions.length;
  • The block gasLimit total is always about 30000000, but the number of transactions is variable in each block. Sometimes 1, sometimes 6..... the gasLimit is so different in each case if I take your division by the trx length – JTConsulta Apr 26 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.