Skip to main content

Overview

This document provides a comprehensive reference for all functions available in the ZKScore Identity SBT 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.

Core Functions

mint

Mint a new identity token for a user.
Parameters:
  • to (address): The address to mint the token to
  • name (string): The ZKS ID name (e.g., “alice.zks”)
  • metadataURI (string): URI pointing to the token metadata
Returns:
  • tokenId (uint256): The ID of the newly minted token
Gas Estimate: ~150,000 gas Requirements:
  • Caller must have MINTER_ROLE
  • to cannot be the zero address
  • name must be unique and valid
  • metadataURI must be a valid URI
Events Emitted:
  • IdentityMinted(address indexed to, uint256 indexed tokenId, string name)
Example Usage:

activate

Activate an identity token, making it soulbound.
Parameters:
  • tokenId (uint256): The ID of the token to activate
Returns: None Gas Estimate: ~50,000 gas Requirements:
  • Caller must be the owner of the token
  • Token must not already be activated
  • Token must exist
Events Emitted:
  • IdentityActivated(uint256 indexed tokenId, address indexed owner)
Example Usage:

View Functions

balanceOf

Get the number of tokens owned by an address.
Parameters:
  • owner (address): The address to query
Returns:
  • uint256: The number of tokens owned by the address
Gas Estimate: ~2,000 gas Example Usage:

ownerOf

Get the owner of a specific token.
Parameters:
  • tokenId (uint256): The ID of the token
Returns:
  • address: The owner of the token
Gas Estimate: ~2,000 gas Requirements:
  • Token must exist
Example Usage:

isActivated

Check if a token is activated (soulbound).
Parameters:
  • tokenId (uint256): The ID of the token
Returns:
  • bool: True if the token is activated, false otherwise
Gas Estimate: ~2,000 gas Example Usage:

isSoulbound

Check if a token is soulbound (cannot be transferred).
Parameters:
  • tokenId (uint256): The ID of the token
Returns:
  • bool: True if the token is soulbound, false otherwise
Gas Estimate: ~2,000 gas Note: This function returns the same value as isActivated() since activation makes a token soulbound.

tokenURI

Get the metadata URI for a token.
Parameters:
  • tokenId (uint256): The ID of the token
Returns:
  • string: The metadata URI for the token
Gas Estimate: ~3,000 gas Example Usage:

Metadata Functions

setTokenURI

Update the metadata URI for a token.
Parameters:
  • tokenId (uint256): The ID of the token
  • newURI (string): The new metadata URI
Returns: None Gas Estimate: ~30,000 gas Requirements:
  • Caller must have METADATA_ROLE or be the token owner
  • Token must exist
  • Token must not be activated (metadata is immutable after activation)
Events Emitted:
  • MetadataUpdated(uint256 indexed tokenId, string newURI)
Example Usage:

Access Control Functions

grantRole

Grant a role to an address.
Parameters:
  • role (bytes32): The role to grant
  • account (address): The address to grant the role to
Returns: None Gas Estimate: ~50,000 gas Requirements:
  • Caller must have the admin role for the specified role
Example Usage:

revokeRole

Revoke a role from an address.
Parameters:
  • role (bytes32): The role to revoke
  • account (address): The address to revoke the role from
Returns: None Gas Estimate: ~50,000 gas Requirements:
  • Caller must have the admin role for the specified role

hasRole

Check if an address has a specific role.
Parameters:
  • role (bytes32): The role to check
  • account (address): The address to check
Returns:
  • bool: True if the address has the role, false otherwise
Gas Estimate: ~2,000 gas

Transfer Functions

transferFrom

Transfer a token from one address to another.
Parameters:
  • from (address): The current owner of the token
  • to (address): The new owner of the token
  • tokenId (uint256): The ID of the token to transfer
Returns: None Gas Estimate: ~80,000 gas (before activation), reverts (after activation) Requirements:
  • Token must not be activated (soulbound)
  • Caller must be authorized to transfer the token
  • to cannot be the zero address
Note: This function will revert if the token is activated (soulbound).

safeTransferFrom

Safely transfer a token from one address to another.
Parameters:
  • from (address): The current owner of the token
  • to (address): The new owner of the token
  • tokenId (uint256): The ID of the token to transfer
  • data (bytes, optional): Additional data to send with the transfer
Returns: None Gas Estimate: ~80,000 gas (before activation), reverts (after activation) Requirements:
  • Token must not be activated (soulbound)
  • Caller must be authorized to transfer the token
  • to cannot be the zero address
Note: This function will revert if the token is activated (soulbound).

Approval Functions

approve

Approve an address to transfer a specific token.
Parameters:
  • to (address): The address to approve
  • tokenId (uint256): The ID of the token to approve
Returns: None Gas Estimate: ~50,000 gas (before activation), reverts (after activation) Requirements:
  • Caller must be the owner of the token
  • Token must not be activated (soulbound)
Note: This function will revert if the token is activated (soulbound).

getApproved

Get the approved address for a specific token.
Parameters:
  • tokenId (uint256): The ID of the token
Returns:
  • address: The approved address (zero address if none)
Gas Estimate: ~2,000 gas

setApprovalForAll

Approve or revoke approval for all tokens.
Parameters:
  • operator (address): The address to approve or revoke
  • approved (bool): True to approve, false to revoke
Returns: None Gas Estimate: ~50,000 gas Note: This function works for all tokens, but individual transfers will still revert if the token is activated.

isApprovedForAll

Check if an operator is approved for all tokens.
Parameters:
  • owner (address): The owner of the tokens
  • operator (address): The operator to check
Returns:
  • bool: True if the operator is approved, false otherwise
Gas Estimate: ~2,000 gas

Error Handling

Common Errors

Error Handling Examples

Gas Optimization Tips

Batch Operations

Gas Estimation