Incompatible types `MetaMaskInpageProvider` and `ethers.providers.Web3Provider()`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 268
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Description
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:
```ts
import { ethers } from 'ethers'
import type { MetaMaskInpageProvider } from '@metamask/providers'
const setWalletProvider = async (newWalletProvider: MetaMaskInpageProvider): Promise => {
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, callback: (error: Error, result?: JsonRpcResponse) => 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': 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!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100