Install the package
Prerequisites
Before initializing the client, make sure you have:- A SocketFi account and a registered application in the Developer Portal
- Your application’s Client ID (found on the application detail page)
- React 18 or later installed in your project
- TypeScript configured (recommended)
Set up environment variables
Store your Client ID in an environment variable rather than hard-coding it. The variable name you use depends on your build tool.- Vite
- Next.js
Add the following to your Access it in your code with:
.env file:Initialize the SocketFi client
Create a dedicated file (e.g.lib/socketfi.ts) that exports a single shared client instance. Import this instance wherever you need SDK functionality.
lib/socketfi.ts
Configuration options
string
required
Your SocketFi application Client ID, obtained from the Developer Portal. This value identifies your app during hosted authentication and transaction approval flows.
"TESTNET" | "MAINNET"
required
The Stellar/Soroban network to target. Use
"TESTNET" during development and "MAINNET" for production. Defaults to "TESTNET".string
The name of your application. Displayed on hosted authentication, sign-up, and transaction approval screens.
string
A hex color code (e.g.
"#4F46E5") used as the primary accent color across hosted SocketFi screens.(session: Session) => void
A global callback invoked after every successful authentication. Useful for updating application-level state without coupling the callback to a specific component.
(error: Error) => void
A global callback invoked when any SDK flow fails. You should still use
try/catch around individual calls for component-level error handling.Full configuration example
lib/socketfi.ts
Minimal working example
With the client initialized, you can authenticate a user from any component:App.tsx