Installation
Install the required dependencies:Setup providers
Wrap your application with the necessary providers:Using the GLAM hook
Access vault data and operations with theuseGlam() hook:
src/react/glam.tsx
Available properties
| Property | Type | Description |
|---|---|---|
glamClient | GlamClient | SDK client instance |
vault | Vault | Vault balances and token accounts |
vaultHoldings | VaultHoldings | Priced positions and total value |
activeGlamState | GlamStateCache | Currently selected vault |
glamStatesList | GlamStateCache[] | All accessible vaults |
delegateAcls | DelegateAcl[] | Delegate permissions |
integrationAcls | IntegrationAcl[] | Protocol permissions |
jupTokenList | JupTokenList | Token metadata from Jupiter |
driftMarketConfigs | DriftMarketConfigs | Drift market data |
wsConnected | boolean | WebSocket connection status |
setActiveGlamState | (state: GlamStateCache) => void | Switch active vault |
refresh | () => Promise<void> | Refresh vault data |
Displaying vault balances
Show token balances with real-time updates:src/react/glam.tsx
- Subscribes to vault account changes via WebSocket
- Falls back to polling if WebSocket is unavailable
- Debounces rapid updates for optimal performance
Managing multiple vaults
Switch between multiple vaults:src/react/glam.tsx
Performing vault operations
Execute transactions from React components:Using cluster provider
Manage network selection:src/react/cluster-provider.tsx
Real-time balance subscriptions
The SDK automatically manages WebSocket subscriptions for real-time updates:src/react/useVaultBalanceSubscription.ts
- Monitors vault and all token accounts (up to 20 accounts)
- Debounces updates to prevent excessive re-renders
- Automatically unsubscribes when component unmounts
- Falls back to polling if WebSocket is disabled or unavailable
Complete example
Here’s a complete vault dashboard:Best practices
- Always check if
activeGlamStateexists before accessing vault data - Use the
refresh()function after mutations to update UI - Handle loading and error states in your components
- Leverage WebSocket subscriptions for real-time updates
- Use React Query’s caching to minimize RPC calls
- Test with different network conditions (polling vs WebSocket)
Next steps
Creating vaults
Learn how to create vaults programmatically
Managing assets
Handle deposits, withdrawals, and transfers