I need a bit of help with my code here. Maybe someone more experienced can eye the bug, I've have to give up and ask here. So, I am trying to deploy to Sepolia and I am getting this error and I've tried many things but can't find a solution. enter image description here

I can deploy with no issues with Remix or to Hardhat local node, which means that my contract logic should be ok. I guess there is some kind of issue with setting up for Sepolia, but can't figure out what.

I am posting my project repo here: https://github.com/MihaiHng/CreteToken


1 Answer 1


For some reason, Hardhat isn't properly estimating the gas required for this contract deployment transaction to complete. It takes about 1475000 gas.

If you set the gas limit manually eg to 1500000 in deploy.js here: const creteToken = await CreteToken.deploy(10000000, 50, { gasLimit: 1500000 });, it'll go through.

Here's the full deployment script.

const path = require("path");

async function main() {
  // This is just a convenience check
  if (network.name === "hardhat") {
      "You are trying to deploy a contract to the Hardhat Network, which " +
        "gets automatically created and destroyed every time. Use the Hardhat" +
        " option '--network localhost'"

  // ethers is available in the global scope
  const [deployer] = await ethers.getSigners();
  const accountBalance = await deployer.provider.getBalance(deployer.address); 
    "Deploying the contracts with the account:",
    await deployer.getAddress()

  console.log("Account balance:", accountBalance.toString());

  const CreteToken = await ethers.getContractFactory("CreteToken");
  const creteToken = await CreteToken.deploy(10000000, 50, { gasLimit: 1500000 }); //Set the gas limit here manually
  await creteToken.waitForDeployment();

  console.log("CreteToken address:", creteToken.target);

  // We also save the contract's artifacts and address in the frontend directory

function saveFrontendFiles(creteToken) {
  const fs = require("fs");
  const contractsDir = path.join(__dirname, "..", "frontend", "src", "contracts");

  if (!fs.existsSync(contractsDir)) {

    path.join(contractsDir, "contract-address.json"),
    JSON.stringify({ CreteToken: creteToken.address }, undefined, 2)

  const TokenArtifact = artifacts.readArtifactSync("CreteToken");

    path.join(contractsDir, "CreteToken.json"),
    JSON.stringify(TokenArtifact, null, 2)

  .then(() => process.exit(0))
  .catch((error) => {

  • Thank you, appreciate your your help, have a few questions to this. Where can I check what hardhat's gas estimation is and what is the default gas if you don't specify in the deployment script?
    – mhanga
    Jan 14 at 11:01

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.