Skip to main content

Overview

This document provides a comprehensive reference for all functions available in the ZKScore Achievement Registry contract. Each function includes detailed parameter descriptions, return values, gas estimates, and usage examples.
All functions that modify state require a transaction and will consume gas. View functions are free to call and return data immediately.

Achievement Management Functions

createAchievement

Create a new achievement in the registry.
Parameters:
  • name (string): Achievement name
  • description (string): Achievement description
  • imageURI (string): URI for achievement image/badge
  • category (uint8): Category index (0-7)
  • rarity (Rarity): Rarity level (0-4)
  • points (uint256): Points awarded upon claiming
  • scoreBoost (uint256): Score boost percentage (basis points)
  • requirementType (RequirementType): Type of requirement verification
  • requirementData (bytes): Encoded requirement data
Returns:
  • uint256: The newly created achievement ID
Gas Estimate: ~200,000 gas Requirements:
  • Caller must have CREATOR_ROLE
  • Name cannot be empty
  • Points must be > 0
  • Category must be valid (0-7)
Events Emitted:
  • AchievementCreated(uint256 indexed achievementId, string name, uint8 category, Rarity rarity)
Example Usage:

updateAchievement

Update an existing achievement’s configuration.
Parameters:
  • achievementId (uint256): ID of achievement to update
  • updateData (bytes): Encoded update data
Returns: None Gas Estimate: ~80,000 gas Requirements:
  • Caller must have CREATOR_ROLE
  • Achievement must exist
  • Achievement must be active
Events Emitted:
  • AchievementUpdated(uint256 indexed achievementId, bytes updateData)

deactivateAchievement

Deactivate an achievement (prevent new claims).
Parameters:
  • achievementId (uint256): ID of achievement to deactivate
Returns: None Gas Estimate: ~30,000 gas Requirements:
  • Caller must have ADMIN_ROLE
  • Achievement must exist
Events Emitted:
  • AchievementDeactivated(uint256 indexed achievementId, uint256 timestamp)

Claiming Functions

claimAchievement

Claim an achievement and receive rewards.
Parameters:
  • achievementId (uint256): ID of achievement to claim
  • proof (bytes): Verification proof (if required)
Returns: None Gas Estimate: ~180,000 gas (includes badge minting) Requirements:
  • Achievement must be active
  • User must not have already claimed
  • User must meet requirements
Events Emitted:
  • AchievementClaimed(address indexed user, uint256 indexed achievementId, uint256 timestamp)
  • BadgeMinted(address indexed user, uint256 indexed achievementId, uint256 tokenId)
Example Usage:

batchClaimAchievements

Claim multiple achievements in a single transaction.
Parameters:
  • achievementIds (uint256[]): Array of achievement IDs to claim
  • proofs (bytes[]): Array of corresponding proofs
Returns:
  • uint256[]: Array of minted badge token IDs
Gas Estimate: ~150,000 + (180,000 × number of achievements) Requirements:
  • Arrays must have equal length
  • Each achievement must be claimable

Query Functions

getAchievement

Get detailed information about an achievement.
Parameters:
  • achievementId (uint256): ID of achievement to query
Returns:
  • Achievement: Achievement struct with all details
Gas Estimate: ~5,000 gas (view function) Example Usage:

getUserAchievements

Get all achievements earned by a user.
Parameters:
  • user (address): User address to query
Returns:
  • uint256[]: Array of achievement IDs
Gas Estimate: ~3,000 + (1,000 × number of achievements) (view function)

getProgress

Get user’s progress for a specific achievement.
Parameters:
  • user (address): User address
  • achievementId (uint256): Achievement ID
Returns:
  • Progress: Progress struct with current/required/percentage/canClaim
Gas Estimate: ~4,000 gas (view function) Example Usage:

getAchievementsByCategory

Get all achievements in a specific category.
Parameters:
  • category (uint8): Category index (0-7)
Returns:
  • uint256[]: Array of achievement IDs
Gas Estimate: ~3,000 + (500 × number of achievements) (view function)

getAchievementsByRarity

Get all achievements of a specific rarity.
Parameters:
  • rarity (Rarity): Rarity level (0-4)
Returns:
  • uint256[]: Array of achievement IDs
Gas Estimate: ~3,000 + (500 × number of achievements) (view function)

Progress Management Functions

updateProgress

Update progress for a user (verifier only).
Parameters:
  • user (address): User address
  • achievementId (uint256): Achievement ID
  • progressValue (uint256): New progress value
Returns: None Gas Estimate: ~50,000 gas Requirements:
  • Caller must have VERIFIER_ROLE
  • Achievement must exist
  • User must not have claimed yet
Events Emitted:
  • ProgressUpdated(address indexed user, uint256 indexed achievementId, uint256 progress)

batchUpdateProgress

Update progress for multiple users.
Parameters:
  • users (address[]): Array of user addresses
  • achievementIds (uint256[]): Array of achievement IDs
  • progressValues (uint256[]): Array of progress values
Returns: None Gas Estimate: ~40,000 + (50,000 × number of updates) Requirements:
  • All arrays must have equal length
  • Caller must have VERIFIER_ROLE

Badge Functions

getBadge

Get badge information for a claimed achievement.
Parameters:
  • tokenId (uint256): Badge token ID
Returns:
  • Badge: Badge struct with achievement ID, owner, claim timestamp
Gas Estimate: ~3,000 gas (view function)

getUserBadges

Get all badges owned by a user.
Parameters:
  • user (address): User address
Returns:
  • uint256[]: Array of badge token IDs
Gas Estimate: ~3,000 + (500 × number of badges) (view function)

Verification Functions

canClaim

Check if a user can claim an achievement.
Parameters:
  • user (address): User address
  • achievementId (uint256): Achievement ID
Returns:
  • bool: True if user can claim, false otherwise
Gas Estimate: ~5,000 gas (view function)

hasClaimed

Check if a user has already claimed an achievement.
Parameters:
  • user (address): User address
  • achievementId (uint256): Achievement ID
Returns:
  • bool: True if already claimed, false otherwise
Gas Estimate: ~2,000 gas (view function)

Error Handling

Common Errors

Error Handling Examples

Gas Optimization Tips

Batch Operations

Query Optimization