I am getting the
Property 'ethereum' does not exist on type 'Window & typeof globalThis'
error in React. This is the line generating the issue:
import { ethers } from 'ethers'
const provider = new ethers.providers.Web3Provider(window.ethereum);
Any idea of what could be happening?
Using any
as a type is cheating. Using “any” will just remove the error but it wont show you the available properties.
import { MetaMaskInpageProvider } from "@metamask/providers";
declare global {
interface Window{
ethereum?:MetaMaskInpageProvider
}
}
Create the react-app-env.d.ts
file in the src
folder with the following script:
/// <reference types="react-scripts" />
interface Window {
ethereum: any
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With