Skip to main content
requestTransaction() is the primary method for executing state-changing blockchain operations through SocketFi. When your application calls it, the SDK constructs the transaction, presents an approval screen to the user, routes it through smart wallet authorization and policy enforcement, submits it to Soroban, and returns the result — all without you needing to manage keys, sign transactions, or handle network submission directly.

Method signature

TransactionRequest

TransactionResult

transactionHash is included in the response when success is true. You can use this hash to display a confirmation link, store it for auditing, or look up the transaction in a Stellar explorer.

Practical examples

Send tokens from the user’s wallet to another address.
Approve a protocol contract to spend tokens on the user’s behalf.
Stake tokens in a staking contract.
Deposit assets into a lending pool, vault, or other DeFi protocol.
Claim accumulated rewards from a rewards contract.
Cast a governance vote on an active proposal.
Mint a new NFT by calling the mint method on a collectible contract.

The approval flow

Every call to requestTransaction() enters an approval phase before any on-chain action occurs. The SocketFi approval screen shows the user exactly what they’re authorizing: the action being performed, which assets are involved, the destination address or protocol, and the estimated fee.
Your application’s UI should communicate intent in user-facing language, not blockchain mechanics. Prefer “Deposit 100 USDC into Lending Pool” over “Invoke deposit(100)” — the approval screen reinforces this context, but your app should set it up clearly beforehand.

Error handling

Always wrap requestTransaction() in a try/catch block. The promise rejects on certain failure conditions such as popup blocking or token expiry, and it resolves with success: false when the user cancels or a transaction-level failure occurs.
Never update your application’s state (balance displays, position data, UI flags) based solely on the fact that requestTransaction() was called. Only update state after confirming result.success === true. A resolved promise without a truthy success field means no on-chain state changed.

UI state management

A well-designed transaction UI guides the user through each phase of the workflow. The recommended state progression is:
Here’s a React example that implements this state machine:
When the state is awaiting_approval, disable the trigger button and show a spinner or status message. The SocketFi approval popup is open and waiting for user input — triggering a second call at this point will cause unexpected behavior.

When to use readContract() instead

requestTransaction() is for state-changing operations only. If you need to query contract state without modifying anything — checking a balance, reading a price, fetching governance data — use readContract() instead. Read-only queries don’t require user approval and resolve immediately.