GoodDocs
  • Welcome to GoodDocs!
  • GoodDollar Ecosystem Vision
  • About the Protocol
    • Usage
    • Tokenomics
    • Sybil-Resistance
    • Protocol V3 Documentation
      • Architecture & Value Flow
      • System's Elements
      • Core Contracts & API
        • GoodDollar
        • GoodCompoundStaking V2 (DAI)
        • GoodAaveStaking V2 (USDC)
        • GoodReserveCDai
        • GoodFundManager
        • GoodMarketMaker
        • ContributionCalculation
        • UBIScheme
        • Identity
        • FirstClaimPool
        • AdminWallet
        • OneTimePayments
        • DonationsStaking
        • NameService
        • GReputation
        • CompoundVotingMachine
        • StakersDistribution
        • UniswapV2SwapHelper
        • Invites
        • GovernanceStaking
        • ClaimersDistribution
        • CompoundStakingFactory
        • AaveStakingFactory
        • ExchangeHelper
        • FuseFaucet
        • GoodDollarMintBurnWrapper
      • Previous Protocol Versions
        • Protocol V1
          • Architecture & Value Flow
          • Core Contracts & API
        • Protocol V2
          • Architecture & Value Flow
          • System's Elements
            • 1. The token (G$)
            • 2. The Reserve
            • 3. The Trust
            • 4. Staking rewards (APR)
            • 5. The Fund Manager
            • 6. The Distribution Contract (DisCo)
            • 7. Governance (DAO)
          • Core Contracts & API
            • GoodDollar
            • GoodCompoundStaking V2 (DAI)
            • GoodAaveStaking V2 (USDC)
            • GoodReserveCDai
            • GoodFundManager
            • GoodMarketMaker
            • ContributionCalculation
            • UBIScheme
            • Identity
            • FirstClaimPool
            • AdminWallet
            • OneTimePayments
            • DonationsStaking
            • NameService
            • GReputation
            • CompoundVotingMachine
            • StakersDistribution
            • UniswapV2SwapHelper
            • Invites
            • GovernanceStaking
            • ClaimersDistribution
            • CompoundStakingFactory
            • AaveStakingFactory
            • ExchangeHelper
            • FuseFaucet
  • User Guides
    • Buy & Sell G$
    • Stake to create UBI
    • Claim GOOD and G$X
    • Bridge GoodDollars
    • Connect another wallet address to identity
  • Liquidity
  • Wallet and Products
    • GoodWallet
    • GoodDapp
    • New GoodWallet
    • GoodCollective
    • GoodID & GoodOffers
    • 3rd Party Partners and Integrations
  • Frequently Asked Questions
    • Web3 basic knowledge and security tips - by Consensys
    • About GoodDollar
    • GoodDollar Protocol & G$ Token
    • Using GoodDollar
    • GoodDollar Community
    • Troubleshooting
  • For Developers
    • Contributing to GoodDollar
    • GoodDapp Developer Guides
      • Deploy your own GoodDapp UI
    • APIs & SDKs
      • Claim UBI
      • React Hooks Setup
      • Login With GoodDollar
      • Sybil Resistance
        • Identity (Ethers v5 / React)
        • Identity (Viem/Wagmi)
  • Useful Links
    • GoodDollar.org
    • GoodDapp
    • GoodWallet
    • GoodDollar User Guides
    • Statistics Dashboard
    • GoodDollar Whitepaper
    • GoodDollar Litepaper
    • GoodDollar Litepaper - Español
Powered by GitBook
On this page
  • Installation
  • References

Was this helpful?

  1. For Developers
  2. APIs & SDKs
  3. Sybil Resistance

Identity (Viem/Wagmi)

PreviousIdentity (Ethers v5 / React)NextUseful Links

Last updated 1 month ago

Was this helpful?

For a live demo of the identity integration (using development identity contracts), visit:

Installation

To integrate identity-sdk into your project, you can easily install it from npm:

npm install @goodsdks/identity-sdk

or if you prefer using Yarn:

yarn add @goodsdks/identity-sdk

Available Methods in the Identity SDK:

  • getWhitelistedRoot(account: Address): Promise<{ isWhitelisted: boolean; root: Address }>

  • getIdentityExpiryData(account: Address): Promise<IdentityExpiryData>

  • generateFVLink(popupMode?: boolean, callbackUrl?: string, chainId?: number): Promise<string>

  • submitAndWait(params: SimulateContractParameters, onHash?: (hash: 0x${string}) => void): Promise<any>

  • calculateIdentityExpiry(lastAuthenticated: bigint, authPeriod: bigint): IdentityExpiry

Using the Wagmi SDK

The Identity SDK is built on top of Wagmi and provides a React hook for interacting with the Identity smart contracts. It abstracts the complexity of blockchain interactions, making it easier to integrate identity functionalities into your React applications.

Initialization

First, ensure that you have set up Wagmi in your React application. Then, import and use the useIdentitySDK hook as shown below.

import React from 'react';
import { WagmiProvider } from 'wagmi';
import { useIdentitySDK } from '@goodsdks/identity-sdk';

const IdentityComponent = () => {
  const identitySDK = useIdentitySDK('production');

  const checkWhitelistedRoot = async (account: string) => {
    try {
      const { isWhitelisted, root } = await identitySDK.getWhitelistedRoot(account);
      console.log(`Is Whitelisted: ${isWhitelisted}, Root: ${root}`);
    } catch (error) {
      console.error(error);
    }
  };

  return (
    <div>
      <button onClick={() => checkWhitelistedRoot('0xYourEthereumAddress')}>
        Check Whitelisted Root
      </button>
    </div>
  );
};

const App = () => (
  <WagmiProvider>
    <IdentityComponent />
  </WagmiProvider>
);

Using the Viem SDK

The Viem SDK provides a set of utility functions to interact directly with the Identity smart contracts. It is suitable for backend services or environments where React is not used.

Initialization

import { PublicClient, WalletClient } from "viem"
import { initializeIdentityContract, IdentitySDK } from "./viem-sdk"

const publicClient = new PublicClient({
  /* configuration */
})
const walletClient = new WalletClient({
  /* configuration */
})
const contractAddress = "0xYourContractAddress"

const identitySDK = new IdentitySDK(publicClient, walletClient, "production")

References

Demo Identity App
GoodSdks
Viem Documentation
Wagmi Documentation
OpenZeppelin Contracts
IdentityV2 Smart Contract
Live Demo Identity App