Check Proof of Identity (POI) Status
This guide provides an example of how to check if a user is POI active by verifying that the user's ProofOfIdentity balance is more than 0 and that the user is not suspended.
Example Code
import { ProofOfIdentityContract as ProofOfIdentityContractSDK } from '@haven1/blockchain-sdk/contract';
import { useReadContracts } from 'wagmi';
import { Address } from 'viem';
type CheckPOIStatusParameters = {
address: Address;
contractAddress: Address;
chainId: number;
};
export const checkPOIStatus = async ({
address,
contractAddress,
chainId,
}: CheckPOIStatusParameters) => {
const { data: poiResult, isLoading, isError } = useReadContracts({
contracts: [
{
address: contractAddress,
chainId,
abi: ProofOfIdentityContractSDK.abi,
functionName: 'balanceOf',
args: [address],
},
{
address: contractAddress,
chainId,
abi: ProofOfIdentityContractSDK.abi,
functionName: 'isSuspended',
args: [address],
},
],
});
if (isLoading) {
console.log('Loading POI status...');
return;
}
if (isError) {
console.error('Error fetching POI status');
return;
}
const balance = poiResult?.[0]?.result;
const isSuspended = poiResult?.[1]?.result;
if (balance > 0 && !isSuspended) {
console.log('User is POI active');
} else {
console.log('User is not POI active');
}
};Usage
This example demonstrates how to use the checkPOIStatus function to verify if a user is POI active by checking their balance and suspension status.
Example Code using ProofOfIdentity wagmi wrap Contract hook
Usage
This example demonstrates how to use the useProofOfIdentity hook to verify if a user is POI active by checking their balance and suspension status.
Contract Addresses
Here are the contract addresses for different environments:
Proof of identity V1
devnet:
0xd635521BA9c5694a2237EA94f2455aBfdDF41ef9testnet:
0xDb5ecc06e7C82d3ed4dBA699b8E8D0433A3ED729
Proof of identity V2
devnet:
0x89B63B0698b03B01F7b75f0e1973DE6270D89dA5testnet:
N/A
Last updated