Overview
TheuseWalletProtocols hook provides a React-friendly interface to detect which DeFi protocols a connected wallet has active positions in. It automatically fetches and updates when the wallet address changes.
Location: src/hooks/useWalletProtocols.js
Import
Signature
Parameters
Stacks wallet address to analyze. Pass
null or empty string when wallet is disconnected.Example: SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7Return Values
Array of detected protocol positions
true while fetching wallet data, false once completeError message if detection failed, otherwise
nullUsage Examples
Features
Auto-Update
Automatically re-scans when wallet address changes
Empty State
Returns empty array when no address provided (graceful handling)
Error Recovery
Captures API errors without crashing the component
Two-Factor Detection
Checks both token balances AND transaction history for accuracy
Behavior
Address Changes
The hook automatically re-runs detection when theaddress parameter changes:
No Address Provided
Whenaddress is null, undefined, or empty string:
- Returns
[]forwalletProtocols - Sets
loadingtofalse - No API calls made
Loading States
- Initial:
loading = false,walletProtocols = [] - Fetching:
loading = true - Success:
loading = false,walletProtocols = [...] - Error:
loading = false,error = "message"
Detection Methods
Token Balance Check
Scans wallet for protocol-specific LP or receipt tokens:confidence = "confirmed"
Transaction History Check
Analyzes last 50 transactions for protocol contract interactions:confidence = "likely"
Implementation Details
Source Code
Supported Protocols
The hook can detect positions in these Stacks DeFi protocols:StackingDAO (stSTX)
StackingDAO (stSTX)
Type: Stacking
Token: stSTX (liquid staking receipt)
Contract:
Token: stSTX (liquid staking receipt)
Contract:
SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-tokenZest Protocol (zsBTC)
Zest Protocol (zsBTC)
Type: Lending
Token: zsBTC (lending position)
Contract:
Token: zsBTC (lending position)
Contract:
SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zest-reward-distALEX Lab (atALEX)
ALEX Lab (atALEX)
Type: DEX / Yield
Token: atALEX (auto-compounding)
Contract:
Token: atALEX (auto-compounding)
Contract:
SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.auto-alex-v3Bitflow (stxSTX-LP)
Bitflow (stxSTX-LP)
Type: DEX LP
Token: stxSTX-LP (liquidity pool)
Contract:
Token: stxSTX-LP (liquidity pool)
Contract:
STTWD9SPRQVD3P733V89SV0P8EP8QSB5B00ZBZQ.stxstx-lp-token-v-1-2Hermetica (USDh)
Hermetica (USDh)
Type: Yield
Token: USDh (yield-bearing stablecoin)
Contract:
Token: USDh (yield-bearing stablecoin)
Contract:
SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1N.token-usdhVelar (WELSH-LP)
Velar (WELSH-LP)
Type: DEX LP
Token: WELSH-LP (liquidity pool)
Contract:
Token: WELSH-LP (liquidity pool)
Contract:
SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.wstx-welsh-lp-tokenGranite (sBTC Collateral)
Granite (sBTC Collateral)
Type: Borrowing
Token: sBTC Collateral
Contract:
Token: sBTC Collateral
Contract:
SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1N.granite-vaultPerformance
Initial Detection: ~1-2s for parallel API calls (balances + transactions)
Subsequent Updates: Triggered only when
No Auto-Refresh: Hook does not poll for updates (call with new address to refresh)
Subsequent Updates: Triggered only when
address changesNo Auto-Refresh: Hook does not poll for updates (call with new address to refresh)
Comparison with Service
| Feature | useWalletProtocols Hook | detectWalletProtocols Service |
|---|---|---|
| Usage | React components | Any JavaScript context |
| State Management | Built-in with useState | Manual |
| Address Changes | Auto-detects via useEffect | Manual re-call |
| Error Handling | Exposed as state | Try/catch required |
| Loading State | Built-in | Manual |
Common Patterns
Wallet Connection Integration
Portfolio Value Calculation
Related
Portfolio Protocols Service
Underlying service that detects wallet positions
useProtocolData Hook
Fetch protocol TVL and APY data