我有一个可在我的本地Ganache网络上运行的dApp,但不能在Heroku上部署的Rinkeby上运行
我在App.js中有此代码:
// Load account data
web3.eth.getCoinbase(function(err, account) {
if (err === null) {
App.account = account;
$("#accountAddress").html("Your Account: " + account);
}
});
但是这就是我得到的:您的帐户:null
http://filmproductiondapp.herokuapp.com/这是文件:https://github.com/Louvivien/filmproductiondapp/blob/master/src/js/app.js
你知道我能做什么吗?
Metamask不支持web3.eth.getCoinbase(),因为它是轻客户端https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client
web3.eth.getCoinbase()返回您的采矿奖励所使用的帐户。
web3.eth.getAccounts()[0]返回您创建的第一个帐户(索引0)
尝试:var account = web3.eth.getAccounts()[0];