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!
"ganache-cli": "6.1.8". – goodvibration Sep 13 '18 at 21:02