Except for one unanswered question from last November, I cannot find anything . . . .

I am revamping some typescript code (in Visual Studio) for the Metamask January change. Previously, I was using web3. Now I am just trying to use window.ethereum.

I cannot find a DefinitelyTyped (or any other types) file with type declarations.

I fear that this is really something simple/stupid but I'm totally at a loss.

  • What's your code? In any case you can inject your own copy of web3 in your project, you shouldn't depend on Metamask for web3. – Ismael Mar 10 at 2:25
  • any solution, my window is null – Braian Mellor yesterday

You can try adding the following line at the beginning:

declare let window: any;

Then, you can do stuff like this:

import Web3 from 'web3';


   let web3: Web3;
   if (window.ethereum) {
      web3 = new Web3(window.ethereum);
      // Ask User permission to connect to Metamask
      await window.ethereum.enable();

Use (window as any).ethereum.request to get around type checking.

(I did try this initially but it looked like it wasn't working and even mentioned this fact in my original question before I edited it out for this answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.