Skip to content

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.

3 participants