Incompatible types `MetaMaskInpageProvider` and `ethers.providers.Web3Provider()`

Open
#200 5 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
typescript
Domain
api

Research direction

No source file or test is named. Start by reviewing the provider type definitions and the external-provider interface expected by ethers, then determine whether the incompatibility can be addressed in this package. Done would require a compatible public type or a documented conclusion that the change belongs in ethers.

Written by the indexing model from the issue text.

Description

team-wallet-framework

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!

Dominant language
TypeScript
Stars
268
Forks
130
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MetaMask/providers

All issues in MetaMask/providers

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.