Skip to content

Commit

Permalink
Fix: handle when localNonce not set yet
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Nov 25, 2024
1 parent 804daf3 commit eaec27e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/state/nonces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function getNextNonce({ address, chainId }: { address: string; chai
const latestTxCountRequest = provider.getTransactionCount(address, 'latest');
const [pendingTxCountFromPublicRpc, latestTxCountFromPublicRpc] = await Promise.all([pendingTxCountRequest, latestTxCountRequest]);
const numPendingPublicTx = pendingTxCountFromPublicRpc - latestTxCountFromPublicRpc;
const numPendingLocalTx = localNonce - latestTxCountFromPublicRpc;
const numPendingLocalTx = Math.max(localNonce - latestTxCountFromPublicRpc, 0);
if (numPendingLocalTx === numPendingPublicTx) return pendingTxCountFromPublicRpc; // nothing in private mempool, proceed normally
if (numPendingLocalTx === 0 && numPendingPublicTx > 0) return latestTxCountFromPublicRpc; // catch up with public

Expand Down

0 comments on commit eaec27e

Please sign in to comment.