remix Gas estimation failed

 使用remix调用合约的approve方法给予授权,第一次没啥问题,之后都提示Gas estimation failed,以为gas给少了。 搞了一下午,后面注意到还有两个方法decreaseApproval,increaseApproval,发现使用后授权量有改变... 

这个帖子给了点提示【Solidity】Gas estimation failed-Gas estimation errored with the following message 

是不是代码有问题。。。

然后去看合约代码(都是网上直接复制的合约代码...)

  function approve(address _spender, uint256 _value) public returns (bool) {

    // To change the approve amount you first have to reduce the addresses`
    //  allowance to zero by calling `approve(_spender, 0)` if it is not
    //  already 0 to mitigate the race condition described here:
    //  https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
    require((_value == 0) || (allowed[msg.sender][_spender] == 0));

    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);
    return true;
  }

solidity语言还不是很懂,上面的require 猜测是value等于0或者是该sender没有设置过授权额度。

测试效果是也确实是这样, 要么调用另外两个方法去增加减少,否则就调用一次(addr,0)进行复位, 然后再次设置所想要的值!

猜你喜欢

转载自blog.csdn.net/zgf1991/article/details/90676486
gas