window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
let ethereum = window.ethereum;
window.web3 = new Web3(ethereum);
try {
// Request account access if needed
await ethereum.enable();
// Acccounts now exposed
web3.eth.sendTransaction({/* ... */});
} catch (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!');
}
});
没有找到隐私关闭,只能授权。我是用的react
参考:https://blog.csdn.net/weixin_39421014/article/details/103323245