【问题标题】:Solidity function returning true in remix but false in web3 function callSolidity 函数在 remix 中返回 true,但在 web3 函数调用中返回 false
【发布时间】:2020-10-25 23:47:51
【问题描述】:

我有这个 Solidity 函数,它在 remix IDE 中调用时返回正确答案,但在 web3 调用中,它总是返回 false

function checkSubscribed() public view returns(bool){
        if(block.timestamp>subscriptionPeriod[msg.sender]){
            return false;
        }
        else{
             return true;
        }
     
    }

我的web3调用函数(1.2.9版)

myContract.methods.checkSubscribed().call({from:userAccount},(err,status)=>{
   console.log(status);

});

部署在 kovan 测试网上

【问题讨论】:

    标签: blockchain ethereum solidity web3js remix


    【解决方案1】:

    检查subscriptionPeriod[msg.sender]block.timestamp

    如果你不知道在哪里看timestamp的值,只需在合约中添加一个调试方法即可:

    function timestamp() external view returns (uint256) {
      return block.timestamp;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多