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

Replace Ethers with @metamask/eth-query #59

Draft
wants to merge 1 commit into
base: narrow-provider-type
Choose a base branch
from

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Nov 22, 2023

It seems that a recent change to switch from ethjs-query to Ethers has caused a regression: when the network is switched, this.web3 still points to the previous network. This happens because Web3Provider saves a copy of the sendAsync method on the given provider, so even if nonce-tracker is given a provider proxy, this.web3 still has a reference to the sendAsync method from the previous provider object.

This is a common problem with Ethers. Although Ethers has some nice features, we don't need to pull it in here, and we can use @metamask/eth-query (which provides TypeScript support, unlike @metamask/ethjs-query) instead. We do lose one feature of Ethers, which is that it automatically converts response data for requests to the appropriate types, but we can make use of @metamask/utils to help with this.

Fixes #58.

It seems that a recent change to switch from `ethjs-query` to Ethers has
caused a regression: when the network is switched, `this.web3` still
points to the previous network. This happens because Web3Provider saves
a copy of the `sendAsync` method on the given provider, so even if
`nonce-tracker` is given a provider proxy, `this.web3` still has a
reference to the `sendAsync` method from the previous provider object.

This is a common problem with Ethers. Although Ethers has some nice
features, we don't need to pull it in here, and we can use
`@metamask/eth-query` (which provides TypeScript support, unlike
`@metamask/ethjs-query`) instead. We do lose one feature of Ethers,
which is that it automatically converts response data for requests to
the appropriate types, but we can make use of `@metamask/utils` to help
with this.
`nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`,
);
const baseCountAsHex = await new Promise<string>((resolve, reject) => {
this.ethQuery.sendAsync<string[], string>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We could drop ethQuery here and call the provider directly:

Suggested change
this.ethQuery.sendAsync<string[], string>(
this.provider.sendAsync<string[], string>(

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

Successfully merging this pull request may close these issues.

2 participants