Ethereum contract is deploying, but giving simultaneously an error

28 views Asked by At

I'm using Ganache and Ethers Version 6.9.10, Solc version 0.8.7-fixed and every time I try to deploy the contract it gives an error, but I can see the transaction as contract creation in Ganache.

My code:

const { ethers, JsonRpcProvider } = require("ethers");
const fs = require("fs-extra");

async function main() {
  const provider = new JsonRpcProvider("http://127.0.0.1:7545");
  const wallet = new ethers.Wallet(
    "0x1a83cdf7bdb809ff11a5d7c0c0d857fa12edaead582f3b348c6ba417dcb9c6ca",
    provider
  );

  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
  const binary = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin");
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);

  const contract = await contractFactory.deploy({
    gasLimit: 20000000000,
  });

}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.log(error);
    process.exit(1);
  });

If I don't add the gasLimit in deploy I'm also getting an error, which is odd because normally it is not required to add the gasLimit. The error:

invocation: null,
  revert: null,
  shortMessage: 'missing revert data',
  info: {
    error: {
      message: 'VM Exception while processing transaction: out of gas',
      stack: 'RuntimeError: VM Exception while processing transaction: out of gas\n' +
        '    at exactimate (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:182136)',
      code: -32000,
      name: 'RuntimeError',
      data: [Object]
    },
    payload: {
      method: 'eth_estimateGas',
      params: [Array],
      id: 3,
      jsonrpc: '2.0'
    }
  }

And after adding the gasLimit the contract is deployed on Ganache I can see it, but I'm getting an error on the console and everything after that does not get executed. I can't even console.log the contract details. The error:

...
  code: 'UNKNOWN_ERROR',
  error: {
    message: 'VM Exception while processing transaction: out of gas',
    stack: 'RuntimeError: VM Exception while processing transaction: out of gas\n' +
      '    at EIP1559FeeMarketTransaction.fillFromResult (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:12745)\n' +
      '    at Miner.<anonymous> (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:36703)\n' +
      '    at async Miner.<anonymous> (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:35116)\n' +
      '    at async Miner.mine (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:39680)\n' +
      '    at async Blockchain.mine (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:60063)\n' +
      '    at async Promise.all (index 0)\n' +
      '    at async TransactionPool.emit (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/node_modules/emittery/index.js:303:3)',
    code: -32000,
    name: 'RuntimeError',
    data: {
      hash: '0xa0dd74d719ff5cf789de05abe7e9be61dbe6208603861eddd75c2b95a935a9a8',
      programCounter: 37,
      result: '0xa0dd74d719ff5cf789de05abe7e9be61dbe6208603861eddd75c2b95a935a9a8',
      reason: null,
      message: 'out of gas'
    }
  },
  payload: {
    method: 'eth_sendRawTransaction',
...

I'm following a video on Youtube and because of that error I cannot move forward. I tried to downgrade both ethers and solc and tried almost every combination, but it is always the same error which comes.

0

There are 0 answers