Skip to content

Frontend guide: use pollTransaction and returnValue in the counter example - #2975

Merged
ElliotFriend merged 3 commits into
mainfrom
docs-agent/2960-frontend-guide-polling
Nov 3, 2026
Merged

ElliotFriend merged 3 commits into
mainfrom
docs-agent/2960-frontend-guide-polling

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 #2960

Working this because @oceans404 added bot:take. The counter example in "Interacting with smart contracts" breaks on @stellar/stellar-sdk v17. This PR takes the issue's minimal option: use the SDK's polling and the parsed return value.

Changes in docs/build/guides/dapps/frontend-guide.mdx:

  • Replace the while loop with server.pollTransaction(hash, { attempts: 30 }).
  • Check the sendTransaction status. TRY_AGAIN_LATER and ERROR stop with a readable error. PENDING and DUPLICATE go on to polling.
  • Read the result from getResponse.returnValue with scValToNative. This removes .v4(), .sorobanMeta() and .u32(), which throw in v17.
  • A failed transaction throws an Error with the status, not raw resultXdr.
  • Fix e.value.u32() in the events snippet on the same page. It throws in v17 too.
  • Link the SDK's "Invoke a Contract" guide for the contract client version.
  • Update the prose that described the old loop.

Verified against v17.4.0 source:

  • TransactionMetaV4Arm.v4 and ScVal u32 are properties now (transaction-meta.ts L228, sc-val.ts L561).
  • pollTransaction exists (rpc/server.ts L1240). returnValue is on the success response (rpc/api.ts L139).
  • scValToNative and rpc.Api are exported. The same calls also work on v16.
  • The docs guestbook frontend uses the same pattern.

Not in this PR:

Checks: pnpm install is not available in this environment, so pnpm format:mdx, pnpm check and pnpm check:links did not run. I kept every added line within prettier's 80 columns and each paragraph on one line. Please rely on the CI checks job. I did not run the example against testnet.

@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 2, 2026, 9:47 PM

@stellar-doxie

stellar-doxie Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated message from the Stellar Triage Bot.

Reviewing my own PR for #2960, which @oceans404 called me in on.

Verified against SDK v17.4.0 source: pollTransaction, returnValue, scValToNative and the send statuses match. The preview renders and all checks pass. I did not run it against testnet. 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.

Thanks! The switch to pollTransaction and returnValue is right for v17. One small change before merge:

  • frontend-guide.mdx:638: when pollTransaction runs out of attempts it returns NOT_FOUND, which means the result is unknown, not that the transaction failed. Right now that case throws "Transaction did not succeed: NOT_FOUND". Please give NOT_FOUND its own message (something like "not confirmed yet, check again before resending") and link Submit a transaction and wait for the full handling. That keeps this page consistent with the warning in #2977.

@ElliotFriend

Copy link
Copy Markdown
Contributor

/triage

@oceans404 oceans404 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.

Ran the counter example on SDK 17.4.0 against a local network: increment returns 1 then 2 as numbers, and the events lookup reads back 2. The current page throws on .v4() and .u32(), so this fixes a real break.


Generated by Claude Code

@stellar-doxie

stellar-doxie Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated message from the Stellar Triage Bot.

Back on this because @ElliotFriend asked with /triage and requested changes.

Done in 1e8a128:

  • NOT_FOUND now has its own error: "Not confirmed yet. Check again before resending."
  • The prose says the result is unknown, not failed, and links Submit a transaction and wait.

I also merged main (bd98545). It brings in the bindings-json link fix from #2952. SDK v17.4.0 pollTransaction returns the last NOT_FOUND when the attempts run out. Ready to merge after you clear your review.

@ElliotFriend
ElliotFriend merged commit 4e3af57 into main Nov 3, 2026
8 checks passed
@ElliotFriend
ElliotFriend deleted the docs-agent/2960-frontend-guide-polling branch November 3, 2026 16:13

This branch was successfully deployed

1 active deployment
staging — bd98545b Deployed Nov 2, 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.

Frontend guide: replace the hand-written send and poll code in "Interacting with smart contracts"

2 participants