我有一个dApp,它可以在本地Ganache网络上运行,但不能在部署在Heroku上的Rinkeby上运行
我在App.js中有以下代码:
// Load account data
web3.eth.getCoinbase(function(err, account) {
if (err === null) {
App.account = account;
$("#accountAddress").html("Your Account: " + account);
}
});
但这就是我得到的您的帐户:零
下面是文件:https://github.com/Louvivien/filmproductiondapp/blob/master/src/js/app.js
你知道我能做什么吗?
5条答案
按热度按时间3qpi33ja1#
默认情况下,Metamask可能不启用连接。请尝试以下操作:
Metamask将弃用web3js支持,转而支持ethereumProvider。使用ethereumProvider的替代方案:
根据MetaMask文档,返回的帐户对象已被保存为未来扩展的列表,尽管它只服务于一个帐户。
另一种使用MetaMask获取所选地址的快捷方式:
6qfn3psc2#
检查元掩码扩展的设置。设置-〉连接-〉添加'本地主机'就是它。它对我有用希望它有用。
llycmphe3#
我花了几个小时想明白,最后我得到了:
只需在metamsk设置中添加连接http://localhost:3000
mwkjh3gx4#
元掩码不支持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()返回挖矿奖励的账户。
getAccounts()[0]返回您创建的第一个帐户(索引0)
请尝试:变量帐户= web3.eth.getAccounts()[0];
quhf5bfb5#
似乎一切都已经改变了。现在的位置菜单,在那里你可以连接MetaMask到您的销售网站是在这里: