【发布时间】:2018-07-06 14:20:06
【问题描述】:
我的 MetaMask 已启用,但在控制台中我看到空数组 image here,当我尝试 console.log(web3.eth.accounts[0]) 时,它返回 undefined。
但是当我使用console.log(web3.eth) 时,我会在控制台中看到所有数据image here
有人知道为什么web3.eth.accounts[0] 或web3.eth.accounts 不起作用吗?
<html>
<head>
<title>TEST</title>
</head>
<body>
<script>
window.addEventListener('load', function(){
if( typeof web3 !='undefined'){
console.log('web3 detected');
web3 = new Web3(web3.currentProvider);
console.log(web3.eth.accounts);
}else{
alert("please install MetaMask");
}
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript ethereum web3js web3 metamask