This guide explains how to integrate with the Humanity Protocol's VC and Rewards contracts in your own applications.
Basic Integration Concepts
Interacting with Humanity Protocol typically involves two key aspects:
Verifying a user's humanity via the VC contract
Managing rewards via the Rewards contract
VC Contract Integration
Checking User Verification
The most common integration is checking if a user is verified before allowing them to access your services:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { IVC } from "./interfaces/IVC.sol";
contract YourApplication {
IVC private vcContract;
constructor(address vcContractAddress) {
vcContract = IVC(vcContractAddress);
}
modifier onlyVerifiedHuman() {
require(vcContract.isVerified(msg.sender), "User not verified on Humanity Protocol");
_;
}
function protectedFunction() external onlyVerifiedHuman {
// Logic that requires verified humanity
}
function getReferrers(address user) external view returns (address[] memory) {
return vcContract.getReferrersTree(user);
}
}
Getting Referral Information
You can also use referral data to build custom rewards in your own application:
function implementReferralBonus(address user) external {
address[] memory referrers = vcContract.getReferrersTree(user);
if (referrers.length > 0) {
// Provide bonus to the first referrer
_grantBonus(referrers[0]);
}
}
Rewards Contract Integration
Checking Reward Eligibility
You might want to check if a user has claimed their reward before offering additional features:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { IRewards } from "./interfaces/IRewards.sol";
contract YourRewardsExtension {
IRewards private rewardsContract;
constructor(address rewardsContractAddress) {
rewardsContract = IRewards(rewardsContractAddress);
}
function checkDailyClaimStatus(address user) public view returns (bool hasClaimed) {
uint256 currentEpoch = rewardsContract.currentEpoch();
IRewards.UserClaim memory claim = rewardsContract.userClaimStatus(user, currentEpoch);
return claim.claimStatus;
}
function offerBonus() external {
require(!checkDailyClaimStatus(msg.sender), "Already claimed today");
// Offer bonus only to users who haven't claimed their daily reward
}
}
Listening for Reward Events
You can also listen for reward events to trigger actions in your application: