I made my first contract tested on Goerli, and everything appears to work fine.

I've deployed to Goerli testnet without issue using no where close to the gas limit I set, however, deploying to Mainnet, I receive the following response:

body={ "jsonrpc": "2.0", "id":43, "error":{ "code":-32000, "message": "exceeds block gas limit" } }

The uncompiled contract itself is not particularly large, 4kb in total, but it extends ERC721Enumerable.

I've tried setting both the gasLimit in my deployment script as well as in the hardhat.config.js, but nothing appears to fix this issue


task("deploy", "Deploys the contract").setAction(async function (taskArguments, hre) {
    const nftContractFactory = await hre.ethers.getContractFactory( "MyContract", getAccount() );
        const nft = await nftContractFactory.deploy({ gasLimit: 339_477_658 });
        console.log( `Contract deployed to address: ${ nft.address }` );
    } catch( err ){
        console.log( err );


module.exports = {
    solidity: "0.8.17",
    defaultNetwork: NETWORK,
    networks: {
        hardhat: {},
        goerli: {
            url: `https://eth-goerli.alchemyapi.io/v2/${ API_KEY }`,
            accounts: [`0x${ PRIVATE_KEY }`]
        mainnet: {
            allowUnlimitedContractSize: false,
            blockGasLimit: 339_477_658,
            chainId: 1,
            url: `https://eth-mainnet.alchemyapi.io/v2/${ API_KEY }`,
            accounts: [`0x${ PRIVATE_KEY }`]
    etherscan: {
        apiKey: API_KEY_ETHERSCAN

I did a test deploy also on remix, which also has relatively low gas usage

status              true Transaction mined and execution succeed
transaction hash    0xad69c9fc5eeb0620589ffaf412fb2913917760b9ed3e3effda0fd4e92615f6d7
from                0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
gas                 3716021 gas
transaction cost    3231322 gas 
execution cost      3231322 gas 
input               0x608...70033

I'm getting into the territory of a large amount to lose (for me) so I don't want to screw this up. Not sure what I'm doing wrong.

  • 1
    Why have you manually specified block gas limit for mainnet? Or is that part of you testing different things? It's best to just remove that. You can also try the Hardhat "hardhat-contract-sizer" plugin and see what size it shows. Commented Jan 15, 2023 at 20:02
  • @LauriPeltonen yes, I only specified block gas limit for troubleshooting. contract sizer is saying i'm at 14.5kb (yikes), doesn't show size warning for exceeding size limit Commented Jan 15, 2023 at 20:23
  • 1
    well that's odd. Everything should be fine. Maybe try with a local forked mainnet? Or maybe try with a different provider? Commented Jan 15, 2023 at 20:33
  • Am I just under estimating what the gas limit should be? I saw somewhere that the cost would equate to contract size in KBs * 0.064 ETH, is that accurate? Will it actually cost ~0.928 ETH to deploy this contract at 14.5kb? Commented Jan 15, 2023 at 20:47
  • 1
    Please post a new question if you have a new question, or browse existing answers. Quick googling gave for example this: medium.com/scrappy-squirrels/… Commented Jan 15, 2023 at 20:49

1 Answer 1


I was just able to deploy to mainnet. The issue was in nftContractFactory.deploy({ gasLimit: 339_477_658 }) from ethers.js. For whatever reason, removing the gasLimit here fixed the -32000 exceeds block gas limit error

Removing gasLimit and adding a gasPrice corrected the issue and very quickly

  • You cannot have a gasLimit higher than the block gas limite, which is 30M for Ethereum mainnet.
    – Ismael
    Commented Jan 21, 2023 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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