Skip to content

Handle TRY_AGAIN_LATER and DUPLICATE in the JS payment example - #2978

Merged
ElliotFriend merged 3 commits into
mainfrom
docs-agent/2963-payments-send-statuses
Nov 9, 2026
Merged

ElliotFriend merged 3 commits into
mainfrom
docs-agent/2963-payments-send-statuses

Conversation

@stellar-doxie

@stellar-doxie stellar-doxie Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Automated message from the Stellar Triage Bot.

Closes #2963

Working this because @oceans404 added bot:take. The JS payment example said DUPLICATE and TRY_AGAIN_LATER needed handling, then threw on both. This PR handles them in the code.

What changes

In send-and-receive-payments.mdx:

  • The resend bullets above the code: sending the same signed transaction again is safe, because it can go into a ledger only once. Check the result with getTransaction. An applied transaction sent again returns TRY_AGAIN_LATER for about 10 ledgers, then ERROR (txBAD_SEQ). The old text said RPC returns the saved result, which is false.

In the JavaScript tab:

  • TRY_AGAIN_LATER: wait 2 s and send the same signed transaction again, until maxTime passes. If it is still TRY_AGAIN_LATER then, throw an expiry error.
  • DUPLICATE: treated like PENDING. The example waits for the result.
  • ERROR: look up the hash with getTransaction first. Throw only when it returns NOT_FOUND.
  • "Payment Transaction submitted" is logged only for PENDING and DUPLICATE.
  • Polling: pollTransaction() (default 30 attempts, 1 s apart, then the last NOT_FOUND) is replaced by a getTransaction loop. It stops at SUCCESS or FAILED, or when a ledger closes after maxTime. The old code reported a slow ledger as a failed payment after about 30 s, while the transaction stays valid for 180 s. That is the double-pay risk the issue names.

The logic matches the submitTx helper in submit-transaction-wait-js.mdx.

Sources

  • @stellar/stellar-sdk v17.4.0: SendTransactionStatus (rpc/api.ts:515), pollTransaction (rpc/server.ts:1240-1260, default DEFAULT_GET_TRANSACTION_TIMEOUT = 30 at :114, BasicSleepStrategy 1000 ms at :231).
  • stellar-core TransactionQueue.cpp: meanings of DUPLICATE and TRY_AGAIN_LATER. removeApplied bans an applied transaction's hash, and isBanned returns TRY_AGAIN_LATER. The ban lasts TRANSACTION_QUEUE_BAN_LEDGERS = 10 (HerderImpl.cpp).
  • stellar-core TransactionFrame::isTooLate: a transaction is too late when maxTime is earlier than the ledger close time.
  • Live testnet getTransaction: latestLedgerCloseTime is a string, so the code wraps it in Number().

Checks

  • pnpm is not available in this environment, so pnpm format:mdx, pnpm check and pnpm check:links did not run here. The CI checks job is the format gate.
  • I did not run the example against testnet. I checked it against the SDK and stellar-core source.

Not changed (follow-ups)

  • The Java and Go tabs have the same pattern: Java throws on anything but PENDING, and Go gives up after 5 polls.

The example threw on every send status but PENDING. It now resends the same signed transaction on TRY_AGAIN_LATER, treats DUPLICATE as pending, and polls getTransaction until a ledger closes past the time bound, so a slow ledger no longer reads as a failed payment.
@mintlify

mintlify Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
stellar-docs 🟢 Ready View Preview Nov 9, 2026, 5:32 PM

@stellar-doxie

stellar-doxie Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated message from the Stellar Triage Bot.

Reviewing because this is my own PR for #2963, which @oceans404 called me in on.

Verified: the statuses, response fields and maxTime stop rule match SDK v17.4.0 and stellar-core. The preview renders the new code and all checks pass. Ready to merge.

@ElliotFriend ElliotFriend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The status handling is a big improvement, and the TRY_AGAIN_LATER and NOT_FOUND loops match the submitTx helper from #2977. Three things before this can merge:

  1. The resend bullet above the code is now wrong. It says that if the transaction was already applied, "RPC will simply return the saved result and not attempt to submit the transaction again." That isn't what happens, and it contradicts this PR's own code and the submitTx guide: sending a transaction again after it's in a ledger returns TRY_AGAIN_LATER for about 10 ledgers, then ERROR (txBAD_SEQ). Please rewrite that bullet (and the one after it) to say that resending the same signed transaction is safe because it can only go into a ledger once, and that you check the result with getTransaction.

  2. Look up the hash before throwing on ERROR. Because of point 1, an ERROR reply can mean the payment already succeeded on an earlier send. Do what the submitTx helper does: call getTransaction(hash), and only throw when it returns NOT_FOUND.

  3. Don't log "submitted" when the transaction was never accepted. If the TRY_AGAIN_LATER loop stops because a ledger closed after maxTime, the status is still TRY_AGAIN_LATER, but the code logs "Payment Transaction submitted" before it eventually throws the expiry error. Please only log that for PENDING and DUPLICATE. You could also throw right after the loop when the status is still TRY_AGAIN_LATER.

@stellar-doxie

stellar-doxie Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated message from the Stellar Triage Bot.

Back on this because @ElliotFriend requested changes. All three are done in 23525a9:

  1. The resend bullets now say a resend is safe (one ledger only) and to check getTransaction. They name TRY_AGAIN_LATER for about 10 ledgers, then ERROR (txBAD_SEQ), per stellar-core removeApplied and TRANSACTION_QUEUE_BAN_LEDGERS = 10.
  2. On ERROR, the code calls getTransaction(hash) and throws only on NOT_FOUND, like submitTx.
  3. "submitted" is logged only for PENDING and DUPLICATE. A TRY_AGAIN_LATER that outlives maxTime now throws right after the loop.

I also merged main. Checks pass and the preview shows the new code. Ready to merge once your review is cleared.

@ElliotFriend ElliotFriend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All three addressed. Thanks.

@ElliotFriend
ElliotFriend merged commit e32c1c4 into main Nov 9, 2026
8 checks passed
@ElliotFriend
ElliotFriend deleted the docs-agent/2963-payments-send-statuses branch November 9, 2026 17:44

This branch was successfully deployed

1 active deployment
staging — 23525a9b Deployed Nov 9, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:ready-to-merge Bot verified and approved; waiting for a maintainer to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send and receive payments: handle TRY_AGAIN_LATER and DUPLICATE in the RPC example

1 participant