-
Notifications
You must be signed in to change notification settings - Fork 314
Open
Description
Summary
When making rapid sequential transactions, we observed that /v2/accounts/{address} returns more up-to-date nonce values than /extended/v1/address/{address}/nonces. Preferring /v2/accounts in fetchNonce would improve reliability.
Observed Behavior
# Extended API - returned possible_next_nonce: 4636
curl "https://api.mainnet.hiro.so/extended/v1/address/SPWD5Y6Z7SKANZH6C7BK6A81CRKD6B4G2CG4SQ8W/nonces"
# v2/accounts - returned nonce: 4637 (correct)
curl "https://api.mainnet.hiro.so/v2/accounts/SPWD5Y6Z7SKANZH6C7BK6A81CRKD6B4G2CG4SQ8W"
# Nonce 4636 was already used in a confirmed transactionCurrent Code
fetchNonce tries the extended API first:
export async function fetchNonce(opts) {
try {
return await _getNonceApi(opts); // /extended/v1/.../nonces
} catch (e) {}
// Falls back to /v2/accounts
}Suggestion
Swap the order to prefer /v2/accounts:
export async function fetchNonce(opts) {
try {
const url = `${client.baseUrl}/v2/accounts/${opts.address}?proof=0`;
const response = await client.fetch(url);
const json = await response.json();
return BigInt(json.nonce);
} catch (e) {}
return _getNonceApi(opts); // fallback
}Environment
- @stacks/transactions: 7.x
- Observed on mainnet
Metadata
Metadata
Assignees
Labels
No labels