A minimal React example for @satsterminal-sdk/earn: connect wallet, setup session, list pools, create a deposit, and check deposit status.
When this repo lives next to satsterminal-sdk, package.json points at the local SDK packages (file:../satsterminal-sdk/packages/...). Build the SDK once with cd ../satsterminal-sdk && npm run build, then run the example. If you clone only earn-sdk-example, switch those dependencies to @satsterminal-sdk/earn and @satsterminal-sdk/core from npm.
-
Install dependencies:
npm install
-
Copy env and add your API key:
cp .env.example .env
Set
VITE_API_KEY=your-api-key-herein.env.
# Development
npm run dev
# Production build
npm run build
# Preview production build
npm run preview- Connect – Connect UniSat or Xverse.
- Setup – Click “Setup earn session” and sign with your wallet. This derives your smart account and authorizes the session.
- Pools – Click “Refresh” to load earn pools. Select a pool.
- Deposit – Enter amount and tokens, then “Create deposit”. The created transaction ID is stored for the Status tab.
- Status – Open the “Status” tab and click the refresh button to fetch deposit status for the last transaction (or paste any transaction ID).
The app uses a single provider/hook, useEarnSDK, which wraps the Earn SDK and wallet connection:
import { EarnSDKProvider, useEarnSDK } from '@/hooks/useEarnSDK'
// Wrap app
<EarnSDKProvider>
<App />
</EarnSDKProvider>
// In components
const {
isConnected,
btcAddress,
connect,
disconnect,
setupDone,
setup,
pools,
poolsLoading,
fetchPools,
createDeposit,
lastDepositTxId,
depositStatus,
depositStatusLoading,
fetchDepositStatus,
} = useEarnSDK()- connect('unisat' | 'xverse') – Connect wallet.
- setup() – Derive smart account and authorize session; required before pools/deposit.
- fetchPools(params?) – Load pools (optional
collateralToken,chain). - createDeposit({ poolId, depositAmount, depositToken, collateralToken }) – Create deposit; returns transaction ID.
- fetchDepositStatus(transactionId) – Load status for a deposit.
- No withdrawal flow.
- Deposit form uses simple text inputs; production apps would validate and format amounts/tokens per pool.
- React 19, TypeScript, Vite
- Tailwind CSS, Radix UI (Label, Slot, Toast)
- sats-connect (Xverse)
- @satsterminal-sdk/earn, @satsterminal-sdk/core