PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 25, 2022

[FIXED] How to find the type for ethereum, provider, and contract

 September 25, 2022     blockchain, ethereum, next.js, typescript     No comments   

Issue

I have this interface

interface IWeb3 {  
  ethereum?: MetaMaskInpageProvider;
  provider?: any;
  contract?: any;
};

I found the type for ethereum from import { MetaMaskInpageProvider } from "@metamask/providers" but could not find others.


Solution

I had to install ethers library

import { MetaMaskInpageProvider } from "@metamask/providers";
import { Contract, providers } from "ethers";

interface IWeb3 {  
  ethereum?: MetaMaskInpageProvider;
  provider?: providers.Web3Provider;
  contract?: Contract;
};

Also to be able to use window.ethereum, I had to set this:

declare global {
  interface Window {
    ethereum: MetaMaskInpageProvider;
  }
}


Answered By - Yilmaz
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing