Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible types MetaMaskInpageProvider and ethers.providers.Web3Provider() #200

Open
microHoffman opened this issue Mar 6, 2022 · 5 comments

Comments

@microHoffman
Copy link

microHoffman commented Mar 6, 2022

Hello, I installed the typings for Metamask provider from this @metamask/providers package. Since we allow multiple providers to be used, we wrap the provider into standardized Web3Provider from ethers package. However, I am unable to pass the MetaMaskInpageProvider to Web3Provider constructor like this:

import { ethers } from 'ethers'
import type { MetaMaskInpageProvider } from '@metamask/providers'
  
const setWalletProvider = async (newWalletProvider: MetaMaskInpageProvider): Promise<void> => {
    walletProvider.value = new ethers.providers.Web3Provider(newWalletProvider) // this throws
}

Error is following:

Argument of type 'MetaMaskInpageProvider' is not assignable to parameter of type 'ExternalProvider | JsonRpcFetchFunc'.   
Type 'MetaMaskInpageProvider' is not assignable to type 'ExternalProvider'.     
Types of property 'sendAsync' are incompatible.       
Type '(payload: JsonRpcRequest<unknown>, callback: (error: Error, result?: JsonRpcResponse<unknown>) => void) => void' is not assignable to type '(request: { method: string; params?: any[]; }, callback: (error: any, response: any) => void) => void'.         
Types of parameters 'payload' and 'request' are incompatible.           
Type '{ method: string; params?: any[]; }' is missing the following properties from type 'JsonRpcRequest<unknown>': jsonrpc, id

I can easily surpress the error by @ts-ignore, but do you think it would be possible to make the MetaMaskInpageProvider compatible with the ethers.providers.Web3Provider? Or should I rather post an issue to the ethers? Thanks!

@mcmire mcmire self-assigned this Apr 29, 2022
@wbt
Copy link

wbt commented Sep 23, 2022

Any updates on this?

@mcmire
Copy link
Contributor

mcmire commented Sep 26, 2022

This is still on our roadmap, but no updates so far, sorry.

@mcmire mcmire removed their assignment Dec 1, 2022
@dhapoer
Copy link

dhapoer commented Mar 15, 2023

Hi @mcmire, any update on this?

@mcmire
Copy link
Contributor

mcmire commented Mar 18, 2023

@dhapoer No, sorry, no updates. Now that I look at this again I'm actually wondering whether this might be an issue with Ethers. Our type is more strict and requires the request object to be a JSON-RPC request object. I can look into this further.

@mcmire
Copy link
Contributor

mcmire commented Mar 18, 2023

Okay, I've just done a quick check on a codesandbox, and it appears that this may be fixed in Ethers v6 if you use BrowserProvider instead of Web3Provider:

import { BrowserProvider } from 'ethers'
import type { MetaMaskInpageProvider } from '@metamask/providers'
  
const setWalletProvider = async (newWalletProvider: MetaMaskInpageProvider): Promise<void> => {
  walletProvider.value = new BrowserProvider(newWalletProvider)
}

Can you give that a shot and let me know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
@mcmire @desi @wbt @dhapoer @microHoffman and others