Tengo una aplicación de reacción en la que intento conectarme a la extensión metamask a través de web3. En mi thunk.ts , estoy llamando a las funciones requeridas pero recibo un error de tipo que no puedo leer las propiedades de undefined (leyendo 'ethereum'). Aquí está el código que estoy usando
if (window.ethereum) {//the error line window.web3 = new Web3(window.ethereum); try { await window.ethereum.enable(); updateAddress(dispatch); } catch (err) { alert("Something went wrong."); } } else if (window.web3) { window.web3 = new Web3(window.web3.currentProvider); updateAddress(dispatch); } else { alert("You have to install MetaMask !"); } };Lo resolví usando el siguiente código.
declare global { interface Window { ethereum?: any; web3?:any } }