Browser transaction tutorial#
Run a complete browser host from an authorized checkout with installed dependencies:
node scripts/docs_examples.mjs --build-browser --serve-browser
Open http://127.0.0.1:4174. The build bundles packages/core/examples/15-browser-trading.ts and serves browser-demo.html. No published SDK package or private hooks package is required.
Connect and read#
Supply the RPC URL, expected genesis hash, program, market, and your settlement, YES, and NO token accounts. Use a funded native market without a maker spline. The sandbox guide describes deployment setup.
Select a Wallet Standard wallet and connect. The wallet must support solana:signTransaction for native version 0 transactions and the selected chain. The tutorial needs signed bytes before dispatch so it can persist the signature and recovery state. A wallet that only offers sign-and-send cannot use this host.
The browser must grant persistent storage. The IndexedDB adapter uses atomic transactions across tabs and requests strict durability. Denied storage permission stops the connection before signing. Keep this browser profile and origin for recovery; deleting its storage deletes the journal.
Read balances. The reader verifies the genesis hash, account owners, market and related PDAs, token mints, token owners, and referral binding. Wallet token balances and free or locked trader-ledger balances are separate fields. These are separate confirmed reads, not an atomic snapshot.
Review and sign#
Choose YES or NO, BUY or SELL, a price in basis points for that outcome, and a quantity in share atoms. Select Review order. Check the market, amounts, minimum fill, quote limits, fee policy, referral decision, and expiration. Then select Sign reviewed order and approve the wallet prompt.
Changing an input clears its review. The session checks the wallet, deployment, fresh trading constraints, and exact signed message before it persists and dispatches. Orders use wallet funds and immediate-or-cancel execution. Sell only tokens held in the selected wallet account.
A returned signature means submission, not finalization. Select Reconcile attempts until the attempt is finalized or failed. Unknown attempts block conflicting replacements. Read balances after finalization.
Cancel, withdraw, and redeem#
The maintenance section supports cancellation and withdrawals of free quote, YES, or NO ledger balances. Give each approved action a stable identifier. Review the exact action and amount before signing. Withdrawal review checks the free balance; locked amounts require cancellation or settlement first.
For redemption, enter an action identifier, explicit YES and/or NO amounts, and a page budget. Review and approve the plan. Advance or resume redemption advances at most one page per selection. A pending signature is reconciled before any next page. Repeat after finalization until the saved plan reports complete.
After a reload, reconnect with the same deployment, wallet, and browser origin. Show saved redemption displays the original plan and approval. Resume that plan; do not rebuild it from changed holdings. The journal preserves the completed instruction prefix, pending signature, and page budget together. Missing finalized return data blocks further progress. See recovery.
Evidence and limits#
The example has TypeScript and browser-bundle checks. Run node scripts/docs_examples.mjs --build-browser --smoke-browser with the repository's Playwright Chromium installed to check actual module loading and the connection guard. This smoke check does not use an RPC or sign.
Deterministic tests exercise IndexedDB updates across connections, restart, mutation failure, corrupt storage, permission denial, disconnected wallets, and unsupported signing. These tests do not establish real-wallet approval, RPC availability, or funded-chain completion. Recorded execution evidence belongs in the example catalog and release evidence.
A separate Chromium fixture completed a finalized YES buy and sell on the local simulator. It checked exact token changes, two Wallet Standard signing requests, active IndexedDB persistence, and no page errors. The fixture key stayed in Node. The harness granted persistent-storage permission for its test origin. See the recorded browser result for identities, hashes, and limits. Installed-wallet approval and production execution remain separate signoffs.
Source files: packages/core/examples/15-browser-trading.ts, browser-journal.ts, native-tutorial.ts, tutorial-session.ts, and 14-resumable-redemption.ts. The Node host uses the same native reader and signing session.