This guide uses
@socketfi/react. If you’re building for React Native, swap the import for @socketfi/react-native — the API is identical.1
Install @socketfi/react
Add the React SDK to your project. If you haven’t already set up your Client ID and environment variables, complete the Installation guide first.Add your Client ID to your environment file:
2
Initialise the SocketFi client
Create a single shared
SocketFi instance. Export it from a dedicated module so every part of your application uses the same client without re-initialising.3
Authenticate a user
Call A successful call returns a session object:The
socketfi.authenticate() from a user interaction (a button click). SocketFi opens a secure hosted authentication flow where the user can sign in with an existing passkey or register a new one using Face ID, Touch ID, or Windows Hello.socketfiAccessToken identifies the authenticated user. Store it (for example in React Context or localStorage) to use in subsequent API calls.4
Request a transaction
Once the user is authenticated, call A confirmed transaction returns:Wrap every
requestTransaction() to propose an on-chain operation. SocketFi presents a hosted approval UI showing exactly what the transaction does before the user confirms and signs.requestTransaction() call in a try/catch — users can decline the approval, and network errors can occur.Read contract state
Read-only contract calls do not require user approval and execute immediately. UsereadContract() to query any Soroban contract — for example to fetch a wallet balance before proposing a transfer.
readContract() doesn’t write to the chain, it’s safe to call at any point after initialisation — you don’t need a fully authenticated session for read-only data.
Verify authentication on your backend
Never rely on client-side state alone to gate access to protected resources. Always send thesocketfiAccessToken to your API and verify it with the Server SDK.
Frontend — attach the token to your request
verifyAuth()
verifyAuth() returns both the verified user identity and their associated wallet address, giving you a trustworthy, server-side source of truth for the current user.
Complete working example
Here’s a minimal but complete React component that ties every step together — login, transaction, and contract read.What to do next
You’ve now covered the full integration surface: installation, authentication, contract reads, transactions, and backend verification. From here:- Review the Production Checklist before switching to
MAINNET - Explore the React SDK reference for the full API surface
- Follow the integration guide for patterns like persistent sessions, loading states, and error boundaries