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()
UserequestTransaction() 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
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 torequestTransaction() takes three fields:
.env
The approval flow
When you callrequestTransaction(), 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
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
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 wraprequestTransaction() in try/catch. The promise rejects for several distinct reasons; your UI should handle each one differently.
Error reference
Tracking transactions after submission
Store thetransactionHash 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.