Skip to main content
Every time a user wants to change on-chain state — send tokens, stake assets, vote on a proposal, deposit into a DeFi protocol — your application calls socketfi.requestTransaction(). The SDK takes care of constructing the transaction, presenting an approval UI so the user can review what they are signing, collecting the passkey authorization, and submitting the transaction to the Stellar network. Your app simply waits for the result. This guide covers when to use requestTransaction(), how to build the request object, how to handle the user approval flow, fee handling, loading states, practical examples across common DeFi operations, and thorough error handling.

When to use requestTransaction()

Use requestTransaction() for any operation that modifies on-chain state:
  • Token transfers and approvals
  • DeFi deposits, withdrawals, and claims
  • Staking and unstaking
  • Governance voting
  • NFT minting, transfers, and burns
  • Smart wallet policy updates
Use readContract() instead for any read-only query — balances, metadata, protocol state — that does not need to change anything. Read operations are free, instant, and require no user approval.

Building the transaction request

Every call to requestTransaction() takes three fields:
Keep your contract IDs in environment variables so you can swap between testnet and mainnet without code changes:
.env

The approval flow

When you call requestTransaction(), the SDK opens the SocketFi approval UI — a modal or browser sheet depending on the platform. The user sees:
  • Contract — the Soroban contract address
  • Method — the function being called
  • Arguments — the parameters in human-readable form
  • Assets involved — tokens being moved and amounts
  • Fees — estimated network and protocol fees
The user either approves (the transaction is signed, submitted, and the promise resolves) or rejects (the promise rejects with a cancellation error). Your app never handles the raw passkey signature — the SDK manages that entirely.

Fee handling overview

Every transaction passes through SocketFi’s fee engine before execution. Depending on your plan and the transaction type, the outcome is one of: Your application does not need to build fee logic. If the fee engine blocks a transaction, requestTransaction() rejects with a descriptive error message you can surface to the user.

Loading states and UI feedback

Transactions take time — the approval UI, passkey prompt, and network submission all happen before the promise resolves. Always disable interactive elements and show a progress indicator while a transaction is in flight.
src/hooks/useTransaction.ts

Practical examples

Token transfer

src/services/token.ts
Use it in a component:
src/components/SendForm.tsx

Staking

src/services/staking.ts

DeFi vault deposit

src/services/vault.ts

Governance vote

src/services/governance.ts

Error handling

Always wrap requestTransaction() in try/catch. The promise rejects for several distinct reasons; your UI should handle each one differently.

Error reference

Tracking transactions after submission

Store the transactionHash returned on success. You can use it to:
  • Display activity history in your app
  • Link to a block explorer (stellar.expert)
  • Build receipts or confirmations
  • Power support workflows
src/services/activityLog.ts

Production tips

  • Validate inputs before calling the SDK. Check wallet addresses, amounts, and any user-provided data before they reach requestTransaction(). A revert from bad inputs still costs the user time and potentially fees.
  • Never assume success. Network conditions, contract logic, and policies can all cause failures. Always handle the error path.
  • Show clear intent. Before calling requestTransaction(), display a confirmation screen in your own UI that explains what the transaction does, who it affects, and the amounts involved. The SocketFi approval UI is a second line of defence, not a replacement for good UX in your app.
  • Store transaction hashes. They are your audit trail for debugging, support, and activity feeds.