Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`Property 'ethereum' does not exist on type 'Window & typeof globalThis'` error in React

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?

like image 585
Boris Avatar asked Sep 12 '25 15:09

Boris


2 Answers

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
  }
}
like image 63
Yilmaz Avatar answered Sep 15 '25 04:09

Yilmaz


Create the react-app-env.d.ts file in the src folder with the following script:

/// <reference types="react-scripts" />

interface Window {
    ethereum: any
}
like image 33
Boris Avatar answered Sep 15 '25 04:09

Boris