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

deps: switch from ethjs-query to @ethersproject/providers #39

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write"
},
"dependencies": {
"async-mutex": "^0.3.1",
"ethjs-query": "^0.3.8"
"@ethersproject/providers": "^5.7.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming version 6.x isn't going to work with the types that already exist in this project right?

Copy link
Contributor Author

@legobeat legobeat Jul 20, 2023

Choose a reason for hiding this comment

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

Pondering if it's meaningful and worth it going straight to 6, skipping 5.Noting that 5 is what's in use in metamask-extension today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Considering v5 is also used in https://github.com/MetaMask/smart-transactions-controller as of now, it seems like the conservative choice for now - so yes, I think it makes sense that this would not consider ethers v6 compatibility. Sounds OK?

"async-mutex": "^0.3.1"
},
"devDependencies": {
"@metamask/eslint-config": "^10.0.0",
Expand Down
9 changes: 4 additions & 5 deletions src/NonceTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'assert';
import { Mutex } from 'async-mutex';

// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const EthQuery = require('ethjs-query');
const { Web3Provider } = require('@ethersproject/providers');
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const BlockTracker = require('eth-block-tracker');

Expand Down Expand Up @@ -94,7 +94,7 @@ export class NonceTracker {

private blockTracker: typeof BlockTracker;

private ethQuery: typeof EthQuery;
private web3: typeof Web3Provider;

private getPendingTransactions: (address: string) => Transaction[];

Expand All @@ -105,7 +105,7 @@ export class NonceTracker {
constructor(opts: NonceTrackerOptions) {
this.provider = opts.provider;
this.blockTracker = opts.blockTracker;
this.ethQuery = new EthQuery(opts.provider);
this.web3 = new Web3Provider(opts.provider);
this.getPendingTransactions = opts.getPendingTransactions;
this.getConfirmedTransactions = opts.getConfirmedTransactions;
this.lockMap = {};
Expand Down Expand Up @@ -210,11 +210,10 @@ export class NonceTracker {
// we need to make sure our base count
// and pending count are from the same block
const blockNumber: string = await this.blockTracker.getLatestBlock();
const baseCountBN = await this.ethQuery.getTransactionCount(
const baseCount: number = await this.web3.getTransactionCount(
address,
blockNumber,
);
const baseCount: number = baseCountBN.toNumber();
assert(
Number.isInteger(baseCount),
`nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`,
Expand Down
Loading