Incorrect nonce set while building transaction with makeUnsignedContractCall #1489
Labels
enhancement
Iterations/refactor on existing features/infrastructure/tests
Milestone
What version of Stacks.js are you using?
v6.5.0
Describe the bug
Nonce set by stacks.js is wrong, resulting in a
BadNonce
error on broadcast.How to reproduce
Assuming we have a fresh account with funds and nonce = 0.
1- Build a contract call transaction for any contract without setting the nonce in txOptions
2- broadcast the transaction.
3- Wait 3-5 mins
4- Build another contract call transaction with same account again without setting the nonce in txOptions.
5- broadcast 2nd tx.
6- BadNonce/ConflictingNonceInMempool error gets thrown.
Expected behavior
Possible next nonce should be used and the broadcast should complete without an error.
Investigation
getNonce
fn.getNonce
uses thegetAccountApiUrl
fn to get the nonce.stacks.js/packages/transactions/src/builders.ts
Line 87 in c9e420e
getAccountApiUrl
fn uses this endpoint: https://stacks-node-api.testnet.stacks.co/v2/accounts/ST3QJKVMNZJ897FBDJT7YRQR0AJAS77C6N04SVV51?proof=0.Instead I think the possible next nonce value should be fetched from this endpoint: https://api.testnet.hiro.so/extended/v1/address/ST3QJKVMNZJ897FBDJT7YRQR0AJAS77C6N04SVV51/nonces.
As this endpoint takes into consideration both on-chain data and txs in mempool.
Furthermore, this change needs to be reflected across all builder fns including
sponsorTransaction
fnThe text was updated successfully, but these errors were encountered: