0

我正在尝试检查我的合约中是否有任何资金,并且该功能在混音中运行良好。solidity 函数实际上只是返回 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 按钮调用此函数时,我的控制台中出现错误:

在此处输入图像描述

如果有人有解决方法让我在我的控制台中获取我的 this.balance() 值,那就太棒了。谢谢你。

4

1 回答 1

0

您需要传递一个回调:

web3.eth.getBalance('...', function (err, result) { console.log(result); });
于 2018-05-07T14:56:39.860 回答