Skip to content

What's the correct way to avoid Typescript errors with BrowserProvider typings? #4270

Discussion options

You must be logged in to vote

I did try the const provider = new BrowserProvider(window.ethereum as EIP1193Provider) but I got even more errors. I have to be honest I have only recently started to use typescript in my projects. This way did what I needed it to do.

After a bit of digging, you could try to extend type EthereumProvider type to include the missing properties required by Eip1193Provider.

interface ExtendedEthereumProvider extends ethers.providers.EthereumProvider {
 request?: (args: ethers.providers.JsonRpcRequest) => Promise<any>;
 // Include other missing properties here...
}

const provider = new ethers.providers.BrowserProvider(window.ethereum as ExtendedEthereumProvider);

Note this is just a suggestio…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@bloodylupin
Comment options

@SimSimButDifferent
Comment options

Answer selected by bloodylupin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants