0

So, I got a problem when interacting with a smart contract in geth. I have this very simple contract:

pragma solidity^0.6.1;

contract Simple{
  uint256 public number = 1;

    constructor() public {
    }

    function setNumber(uint256  another) public {
      number = another;
    }

    function getNumber() public view returns (uint256){
      return number;
    }

    function add(uint256 x, uint256 y) public pure returns (uint256){
      return  x+y;
    }
}

I declare it in geth using: var simple = eth.contract(<abi>)

and deploy with:

var simpleInstance = simple.new({from : eth.coinbase, data : '0x<bytecode>'})

When I try to call any of its methods I get the error: Error: gas required exceeds allowance (7097935660) or always failing transaction.

For example, when I try to call simpleInstance.add(1,2) I get the error, even though the gas estimate for this method is 21656.

I get 0 when I call in this form simpleInstance.add.call(1,2), which is obviously incorrect.

Surprisingly, I can't even estimate how gas the operation costs if I specify that the recipient address is the contract address, but I can if I specify another address or none. For example:

I get the error when :

> eth.estimateGas({from : eth.coinbase , to : simpleInstance.address , data : simpleInstance.add.getData(1,2)})

I get no error when:

> eth.estimateGas({from : eth.accounts[0] , to : eth.accounts[1] , data : simpleInstance.add.getData(1,2)})

I tried increasing the gas limit in the genesis block but that didn't solve the problem, also I tried multiple genesis files but that didn't solve the problem. I am calling my geth instance like this:

geth --datadir=./data/ --networkid 4560 console

I tried to call the method in the pre-configured --dev network, initiated geth console like this :

geth --dev console

and it worked! So, there are some missing configurations in my first geth instance that didn't allow the method call. Any ideas what these might be?

Any info will help!

Cheers!

  • Function add is pure, and therefore gas is not an issue here (calling this function is not a transaction execution, and you don't even need to pass it when you call the function). Despite the rather confusing error-message, your problem is not related to gas. – goodvibration Feb 13 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.