0

I am learning web3, and a person is using solidity ^0.4.5, and I am adapting his code to solidity ^0.8.9, and I am facing this problem when if I have 1000 here:

factory = await new web3.eth.Contract(compiledFactory.abi)
        .deploy({data: compiledFactory.evm.bytecode.object})
        .send({from: accounts[0], gas: 10000});

the error is Error: base fee exceeds gas limit

if I add extra 0 there:

factory = await new web3.eth.Contract(compiledFactory.abi)
        .deploy({data: compiledFactory.evm.bytecode.object})
        .send({from: accounts[0], gas: 100000});

the error is n: Exceeds block gas limit This is my full code: https://pastebin.com/iQaw0SRx This is my Contract: https://pastebin.com/3GD6CsVq

2 Answers 2

1

Regarding your first question, for Ethereum the minimum gas consumed for a transaction is 21k. Thus having gas limit set to 10k will result in an error.

For the second error on block gas limit, I'm not very sure on this but it seems that in the full code you pasted, you set it to be 80k while attempting to have gas limit set to 100k in your transaction causing the error. Changing the option value to any value >100k should resolve your error.

enter image description here

4
  • It didn't work. I set gasLimit in options to 110k as you suggested, and in .send({from: accounts[0], gas: 100000}); i left gas at 100000, still gives me this error: ` base fee exceeds gas limit`
    – Efim Rubin
    Jul 17, 2022 at 9:52
  • Seems that in the later part of code you use 500k gas as well. Try setting gas to >600k . If that doesn't work perhaps add a larger buffer to 1 000 000. Should fix this error.
    – Brianleect
    Jul 17, 2022 at 15:20
  • nope, nothing seems to work..(
    – Efim Rubin
    Jul 18, 2022 at 10:23
  • Are you still getting the same error? Or has it changed? Changing the gas limit should have fixed it. ethereum.stackexchange.com/questions/46957/… ^ Thread with similar problem. Can you upload the new updated code you are attempting to run as well?
    – Brianleect
    Jul 19, 2022 at 9:31
0

I set gasLimit in options to 10000000 and it works!

const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");

const options = {
  gasLimit: 10000000,
};
const web3 = new Web3(ganache.provider(options));

const compiledFactory = require("../build/CampaignFactory.json");
const compiledCampaign = require("../build/Campaign.json");

let accounts;
let factory;
let campaignAddress;
let campaign;

beforeEach(async () => {
  accounts = await web3.eth.getAccounts();

  factory = await new web3.eth.Contract(compiledFactory.abi)
    .deploy({ data: compiledFactory.evm.bytecode.object })
    .send({ from: accounts[0], gas: "10000000" });

  await factory.methods.createCampaign("100").send({
    from: accounts[0],
    gas: "10000000",
  });

  [campaignAddress] = await factory.methods.getDeployedCampaigns().call();

  campaign = await new web3.eth.Contract(compiledCampaign.abi, campaignAddress);
});

describe("Campaigns", () => {
  it("deploys a factory and a campaign", () => {
    assert.ok(factory.options.address);
    assert.ok(campaign.options.address);
  });
});

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.