1

I have the following contract:

pragma solidity ^0.4.24;

contract MyContract {
    address public owner;
    bool public unlocked;

    constructor() public {
        owner = msg.sender;
        unlocked = true;
    }

    function lock() external {
        require(owner == msg.sender);
        unlocked = false;
    }
}

I run Ganache v6.1.0 configured with --gasLimit=0xfffffffffff and --port=8545.

Then, I upload this contract and try to invoke the lock method via web3 v1.0.0-beta.34:

let fs = require("fs");
let Web3 = require("web3");

let web3 = new Web3("http://localhost:8545");

async function deploy(contractName) {
    let abi = fs.readFileSync(contractName + ".abi").toString();
    let bin = fs.readFileSync(contractName + ".bin").toString();
    let contract = new web3.eth.Contract(JSON.parse(abi));
    let handle = await send(contract.deploy({data: "0x" + bin}));
    return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
}

async function send(transaction) {
    let gas = await transaction.estimateGas({from: PUBLIC_KEY});
    let options = {
        to  : transaction._parent._address,
        data: transaction.encodeABI(),
        gas : gas
    };
    let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
    let receipt = await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
    return receipt;
}

async function execute() {
    let myContract = await deploy("MyContract");
    let transaction = myContract.methods.lock();
    await send(transaction);
}

execute();

Calling execute() --> send(transaction) --> web3.eth.sendSignedTransaction(...) yields:

base fee exceeds gas limit

Any idea what's causing this?

The only observation that I've found useful so far, is that this specific transaction requires a very small amount of gas (around 13000) in comparison with at least twice for any other transaction executed in my script.

By the way, this problem does not occur when I use Parity instead of Ganache.

Perhaps this is another hint.

Thank you!

  • Side note for future readers: the problem seems to be resolved when using "ganache-cli": "6.1.8". – goodvibration Sep 13 '18 at 21:02
1

I believe this is a ganache bug in eth_estimateGas relating to how gas refunds are calculated. (13000 is less than the minimum transaction cost of 21000.)

Incidentally, it looks like perhaps the bug was just fixed? See https://github.com/trufflesuite/ganache-core/issues/26.

It might be worth grabbing the latest source from GitHub and testing against that.

  • Thank you. I am using Ganache CLI, so I assume that I should grab some JS source file from this repository and copy it into my /node_modules/ganache-cli folder. Am I right? Would you be able to guide me which source file to take from this repository? – goodvibration Aug 17 '18 at 6:20
  • Side note for future readers: the problem seems to be resolved when using "ganache-cli": "6.1.8". – goodvibration Sep 13 '18 at 21:02

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.