I am implementing the code in angular to connect with crypto wallet on button click, I have also installed the web3 but I don't know how to remove the error and use the code init.
connectWallet(){
let web3;
let ethereum = window.ethereum;
if (typeof window.web3 !== 'undefined') {
web3 = new Web3(window.web3.currentProvider);
} else {
web3 = new Web3.providers.HttpProvider(localprovide);
}
// ethereum = new Web3(window.ethereum);
ethereum.enable().then(async (accounts) => {
// console.log('transfer called.........', accounts[0]);
localStorage.setItem('account', accounts[0]);
});
if (window.web3) {
// Subscription register
ethereum.on('accountsChanged', async (accounts) => {
// Reload to avoid MetaMask bug: "MetaMask - RPC Error: Internal JSON-RPC"
window.location.reload();
});
window.ethereum.on('networkChanged', async (network) => {
window.location.reload();
});
}
}