Overview
The ZKScore React SDK provides a comprehensive set of hooks for integrating ZKScore functionality into your React applications. All hooks support both ZKS IDs and wallet addresses with automatic resolution.
All hooks automatically handle ZKS ID resolution, so you can use either ZKS IDs (like alice.zks) or wallet addresses in your components. The SDK will resolve them to the appropriate format.
Core Hooks
useScore
Get current score data for an identity.
Options:
chainId (number): Blockchain network ID
includeBreakdown (boolean): Include detailed breakdown
realTime (boolean): Enable real-time updates
enabled (boolean): Enable/disable the hook
Returns:
data: Score data object
loading: Loading state
error: Error object
refetch: Function to refetch data
useIdentity
Get identity information for a ZKS ID or wallet address.
Options:
chainId (number): Blockchain network ID
includeMetadata (boolean): Include metadata
Returns:
data: Identity data object
loading: Loading state
error: Error object
useAchievements
Get achievements for an identity.
Options:
category (string): Filter by category
status (string): Filter by status
limit (number): Number of results
offset (number): Pagination offset
Returns:
data: Achievements data object
loading: Loading state
error: Error object
useScoreHistory
Get historical score data for an identity.
Options:
timeframe (string): Time period (1d, 7d, 30d, 90d, 1y, all)
interval (string): Data interval (hourly, daily, weekly, monthly)
chainId (number): Blockchain network ID
includeBreakdown (boolean): Include breakdown data
Returns:
data: Array of historical score points
loading: Loading state
error: Error object
useTrustScore
Get trust score data for an identity.
Options:
realTime (boolean): Enable real-time updates
includeAttestations (boolean): Include attestation data
Returns:
data: Trust score data object
loading: Loading state
error: Error object
Advanced Hooks
useScoreBreakdown
Get detailed score breakdown for an identity.
useAchievementProgress
Get progress for a specific achievement.
useLeaderboard
Get leaderboard data.
Utility Hooks
useZKScoreContext
Access the ZKScore context and configuration.
useZKScoreSDK
Access the underlying SDK instance.
Hook Options
Common Options
All hooks support these common options:
Real-time Options
Caching Options
Error Handling
Error Types
Common Error Codes
NETWORK_ERROR: Network connection failed
RATE_LIMIT_EXCEEDED: Rate limit exceeded
INVALID_API_KEY: Invalid API key
IDENTITY_NOT_FOUND: Identity not found
SCORE_NOT_FOUND: Score not found
ACHIEVEMENT_NOT_FOUND: Achievement not found
Error Handling Example
1. Conditional Rendering
2. Memoization
3. Debounced Updates
TypeScript Support
Type Definitions
Best Practices
1. Hook Composition
2. Error Boundaries
3. Custom Hooks