Skip to content

Commit

Permalink
Refactor nonce handling in increment-page-view API
Browse files Browse the repository at this point in the history
  • Loading branch information
iammatthias committed Apr 6, 2024
1 parent 414bd0d commit 1a36d33
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/pages/api/increment-page-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ export async function POST({ request }) {
account,
});

// If nonce is null, get the current transaction count
if (nonce === null) {
nonce = await publicClient.getTransactionCount({
address: account.address,
});
} else {
nonce++; // Increment the nonce for each subsequent transaction
}
// Always fetch the latest nonce from the blockchain
const nonce = await publicClient.getTransactionCount({
address: account.address,
});

// Add the nonce to the transaction
contractRequest.nonce = nonce;
Expand Down

0 comments on commit 1a36d33

Please sign in to comment.