这篇文章日期:2018-10-27。
dapp唤起metamask登录(类似以太猫)。
matemask钱包是浏览器插件钱包,近期因为存在安全问题,系统进一步升级。
在11月2日钱包将更新开发”隐私模式“设置,用户设置隐私模式后,需要授权某站点才可获取到web3js对象。
官方公告地址:
https://medium.com/metamask/https-medium-com-metamask-breaking-change-injecting-web3-7722797916a8
当前测试自定义钱包安装:
/https://medium.com/metamask/https-medium-com-metamask-breaking-change-injecting-web3-7722797916a8
<script>
window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(ethereum);
try {
// Request account access if needed
await ethereum.enable();
alert(web3.eth.coinbase);
// Acccounts now exposed
web3.eth.sendTransaction({/* ... */ });
} catch (error) {
console.log(error);
// User denied account access...
}
}
// Legacy dapp browsers...
else if (window.web3) {
window.web3 = new Web3(web3.currentProvider);
// Acccounts always exposed
web3.eth.sendTransaction({/* ... */ });
}
// Non-dapp browsers...
else {
console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
}
});
//pulp globe banana memory dismiss ramp mosquito kite swarm property impact mirror
</script>