无法履行合同

时间:2018-05-07 01:40:37

标签: javascript ethereum solidity web3 remix

我试图检查我的合同是否有任何资金,并且具有在混音中工作正常的可靠性功能。 solidity func字面上只返回this.balance();这就是我真正需要的。

function checkBalance() public view returns (uint) {
    return this.balance;
}

我试图在web3中以编程方式调用此函数,而这里我遇到了麻烦。我使用web3 func eth.getBalance试图获得合同的当前余额。

checkBalance: function() {
    App.contracts.HackathonDapp.deployed().then(function (instance) {
        return instance.checkBalance.call() 
    }).then(function (balance) {
        return web3.fromWei(web3.eth.getBalance('0xeec918d74c746167564401103096d45bbd494b74'));
    }).then (function (contractBalance) {
        console.log(contractBAlance);
    });
},

然而,当我按下HTML按钮来调用此函数时,我的控制台出现错误:

enter image description here

如果有人为我提供解决方法,只需在我的控制台中获取我的this.balance()值即可。谢谢。

1 个答案:

答案 0 :(得分:0)

您需要传递回调:

web3.eth.getBalance('...', function (err, result) { console.log(result); });
相关问题