> For the complete documentation index, see [llms.txt](https://docs.haven1.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.haven1.org/build/provable-identity-applications/implementing-identity-checks-in-smart-contracts.md).

# Implementing Identity Checks in Smart Contracts

1. **Contract Setup**: Start by defining the `OPERATOR_ROLE` in your contract, which is crucial for managing permissions within your smart contract. Ensure that your contract correctly initializes and interacts with the Proof of Identity contract.
2. **Issuing Identity with** `issueIdentity`:
   * Understand and implement the `issueIdentity` function. This is a critical function for creating a Proof of Identity NFT for verified users.
   * Parameters like `primaryID`, `countryCode`, `userType`, and `expiries` need to be correctly set based on the user’s verified information.
   * The `uri` parameter can link to additional information about the user, stored off-chain for privacy.
3. **Attribute Management**:
   * Utilize attribute-related functions such as `setStringAttribute` and `setBoolAttribute` to assign specific characteristics to a user's profile.
   * These attributes could range from basic personal information to more complex data relevant to your application, like accreditation status or membership details.<br>

<mark style="background-color:green;">**Implementing Identity Verification in Smart Contracts**</mark>

1. **Fetching and Validating Token IDs**:
   * Leverage `tokenID(address account)` to retrieve the token ID linked to a user's identity. This ID is fundamental for verifying if a user has undergone the necessary identity checks.
   * Implement logic to handle scenarios where a token ID might not exist or be invalid.
2. **Utilizing Identity Attributes in Contract Logic**:
   * **Country Code Validation**: Employ `getCountryCode` for geo-specific logic, such as restricting or allowing transactions based on the user's location.
   * **User Competency**: Integrate `getCompetencyRating` to evaluate if a user meets certain skill or competency criteria, essential in specialized applications.
   * **User Type Differentiation**: Use `getUserType` to categorize users into different groups like retail or institutional, and modify the contract's behavior accordingly.
3. **Integrating Attribute-Based Access Control**:
   * Design your smart contract functions to check for specific attributes before allowing transaction execution. This ensures that only qualified or authorized users can perform certain actions within your contract.
   * Use events like `AttributeSet` and `IdentityIssued` to keep track of changes in user attributes and identities.

\ <mark style="background-color:blue;">**Advanced Contract Features**</mark>

1. **Handling Token URI Updates**:
   * Implement the `setTokenURI` function to update the metadata or information linked to a user’s Proof of Identity NFT.
   * This allows for dynamic updates to a user's profile or identity information while maintaining the integrity of the NFT.
2. **Custom Attribute Integration**:
   * Go beyond the standard attributes and implement custom attributes relevant to your application. This could include user preferences, historical transaction data, or other relevant information.
   * Use functions like `setU256Attribute` or `setBytesAttribute` for custom data types.
3. **Error Handling and Security**:
   * Ensure your contract properly handles potential errors such as `ProofOfIdentity__InvalidAttribute` or `ProofOfIdentity__AlreadyVerified`.
   * Implement security measures to protect against unauthorized access or manipulation of user identity information.
