Overview
The ZKScore React SDK provides a comprehensive set of hooks that make it easy to integrate reputation scores, identities, achievements, and more into your React applications.Installation
Provider Setup
Wrap your app with the ZKScoreProvider:Provider Props
string
required
Your ZKScore API key
string
Network to use:
'mainnet' or 'testnet' (default: 'mainnet')number
Cache duration in milliseconds (default: 300000 - 5 minutes)
number
Number of retry attempts for failed requests (default: 3)
Available Hooks
Identity Hooks
useIdentity
Get identity information for an address
useMintIdentity
Mint a new ZKScore identity
useCheckUsername
Check username availability
Score Hooks
useScore
Get reputation score for an address
useScoreBreakdown
Get detailed score breakdown
useScoreHistory
Get historical score data
useLeaderboard
Get score leaderboard
Achievement Hooks
useAchievements
List all available achievements
useUserAchievements
Get user’s earned achievements
useAchievementProgress
Track achievement progress
useClaimAchievement
Claim an achievement
Trading Hooks
useTradingStats
Get trading statistics
useTradingHistory
Get trading history
useTradingLeaderboard
Get trading leaderboard
Trust Layer Hooks
useAttestations
Get attestations for an address
useCreateAttestation
Create new attestations
useTrustPolicy
Evaluate trust policies
Hook Patterns
Basic Usage
With Auto-Refresh
Conditional Fetching
Error Handling
Multiple Hooks
Common Hook Options
Most hooks accept these common options:boolean
Enable/disable the query (default:
true)number
Auto-refresh interval in milliseconds
number
Number of retry attempts (default: 3)
number
Delay between retries in milliseconds (default: 1000)
number
How long to cache data in milliseconds
number
Time until data is considered stale in milliseconds
function
Callback when query succeeds
function
Callback when query fails
Common Return Values
All hooks return an object with these common properties:any
The fetched data (e.g.,
score, identity, achievements)boolean
Whether the data is currently being fetched
Error | null
Error object if the request failed
function
Function to manually refetch the data
boolean
Whether the cached data is stale
Advanced Patterns
Prefetching Data
Mutations
Optimistic Updates
Dependent Queries
Pagination
TypeScript Support
All hooks are fully typed for TypeScript:Performance Tips
- Use Appropriate Cache Times: Set longer cache times for rarely-changing data
- Disable Auto-Refetch: For static data, set
refreshInterval: 0 - Enable Suspense: Use React Suspense for better loading states
- Prefetch: Prefetch data on hover or route changes
- Batch Requests: Use multiple hooks to fetch related data in parallel
Next Steps
useIdentity
Learn about identity hooks
useScore
Learn about score hooks
useAchievements
Learn about achievement hooks
Components
Pre-built React components