1

I'm deploying a contract to my private chain and try to call the contract's function.

After I got in the geth console and finished deploy contract, I called the function but it doesn't work correctly.

pragma solidity ^0.5.6;

contract SimpleBank {
 uint256 storedData;
 function set(uint256 data) public{
  storedData = data;
 }
function get() public view returns (uint256){
    return storedData;
  }
}

// I tried to call contract’s function like this in the geth console:

storage.set.sendTransaction(42,{from:eth.accounts[0],gas:10000000})

// After mining like this:

miner.start(1);admin.sleepBlocks(1);miner.stop();

// I called the get() function:

storage.get.call()

It should return storedData’s value 42 But it returns 0

And I tried to use other available contract on the web:

pragma solidity 0.5.1;

contract MyContract {
enum State { Waiting, Ready, Active }
State public state;

constructor() public {
    state = State.Waiting;
}

function activate() public {
    state = State.Active;
}

function isActive() public view returns(bool) {
    return state == State.Active;
}
}

// I called activate() first :

storage.activate.call()

//And I called isActivete():

storage.isActivate.call()

It should return true, but it return false

if the function’s return type is uint256, it always returns 0 And when the return type is Boolean, it always returns false

It seems like function do not actually work so it returns the default value

  • Can you check if the transactions was effectively mined? After creation it should return a <hash>, you can check the hash was mined with eth.getTransaction(<hash>), and verify block is a valid number. Also 10M as gas is too large try 100k as more reasonable, make sure the block gas limit in your chain is larger than the used. – Ismael Apr 25 at 16:05
  • AFAIK, it should be func().call(), not func.call(). – goodvibration Apr 26 at 8:33

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.