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
      • How to integrate the G$ token
      • Use G$ streaming
      • Ethers V5/useDapp Context Setup
    • APIs & SDKs
      • UBI
        • Claim UBI (Ethers v5/ React)
        • Claim UBI (Viem/Wagmi)
        • Claim UBI (Web-components)
      • 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
  • Available Methods
  • Using the Wagmi SDK
  • Using the Viem SDK
  • References

Was this helpful?

  1. For Developers
  2. APIs & SDKs
  3. UBI

Claim UBI (Viem/Wagmi)

The Claim SDK enables developers to integrate Universal Basic Income (UBI) claiming functionality into their applications, allowing users to claim GoodDollars (G$) on supported blockchain networks like Celo and Fuse. Built to work seamlessly with the GoodDollar protocol, it relies on the Identity SDK for whitelisting checks and supports both Wagmi (for React) and Viem (for non-React) environments.

Installation

To use the Claim SDK, install the @goodsdks/citizen-sdk package, which includes the necessary components:

npm install @goodsdks/citizen-sdk

Or with Yarn:

yarn add @goodsdks/citizen-sdk

Available Methods

The ClaimSDK class provides the following methods:

  • checkEntitlement(pClient?: PublicClient): Promise<bigint>

  • claim(): Promise<TransactionReceipt | any>

  • nextClaimTime(): Promise<Date>

  • getDailyStats(): Promise<{ claimers: bigint; amount: bigint }>

Refer to the package documentation for detailed information on each method, including parameters and return types. <todo: add link after PR merge>

Using the Wagmi SDK

The Claim SDK integrates with Wagmi for React applications, leveraging the useIdentitySDK hook for easy setup. Below is an example of initializing the SDK and performing basic operations like checking eligibility and claiming UBI.

import { useAccount, usePublicClient, useWalletClient } from 'wagmi';
import { useIdentitySDK } from '@goodsdks/identity-sdk/wagmi-sdk';
import { ClaimSDK } from '@goodsdks/identity-sdk/viem-claim-sdk';

const ClaimComponent = () => {
  const { address } = useAccount();
  const publicClient = usePublicClient();
  const { data: walletClient } = useWalletClient();
  const identitySDK = useIdentitySDK('production');

  if (!address || !publicClient || !walletClient || !identitySDK) {
    return <div>Loading...</div>;
  }

  const claimSDK = new ClaimSDK({
    account: address,
    publicClient,
    walletClient,
    identitySDK,
    env: 'production',
  });

  const checkEntitlement = async () => {
    try {
      const entitlement = await claimSDK.checkEntitlement();
      console.log('Entitlement:', entitlement.toString());
    } catch (error) {
      console.error('Entitlement check failed:', error);
    }
  };

  const claimUBI = async () => {
    try {
      await claimSDK.claim();
      console.log('Claim successful');
    } catch (error) {
      console.error('Claim failed:', error);
    }
  };

  return (
    <div>
      <button onClick={checkEntitlement}>Check Entitlement</button>
      <button onClick={claimUBI}>Claim UBI</button>
    </div>
  );
};

For a more comprehensive example, including state management and user feedback, see <link to demo app>

Using the Viem SDK

For non-React environments or backend services, the Viem-based Claim SDK offers a straightforward way to interact with the UBI Scheme Contract. The ClaimSDK.init the method simplifies initialization.

import { PublicClient, WalletClient } from 'viem';
import { IdentitySDK } from '@goodsdks/identity-sdk/viem-identity-sdk';
import { ClaimSDK } from '@goodsdks/identity-sdk/viem-claim-sdk';

const publicClient = new PublicClient({ /* configuration */ });
const walletClient = new WalletClient({ /* configuration */ });
const identitySDK = new IdentitySDK(publicClient, walletClient, 'production');

const claimSDK = await ClaimSDK.init({
  publicClient,
  walletClient,
  identitySDK,
  env: 'production',
});

try {
  const entitlement = await claimSDK.checkEntitlement();
  console.log('Entitlement:', entitlement.toString());
} catch (error) {
  console.error('Entitlement check failed:', error);
}

try {
  await claimSDK.claim();
  console.log('Claim successful');
} catch (error) {
  console.error('Claim failed:', error);
}

References

PreviousClaim UBI (Ethers v5/ React)NextClaim UBI (Web-components)

Last updated 18 days ago

Was this helpful?

Additional methods like nextClaimTime and getDailyStats are detailed in the .

GitHub README
Viem Documentation
Wagmi Documentation
OpenZeppelin Contracts
UBISchemeV2 Contract