> For the complete documentation index, see [llms.txt](https://docs.gooddollar.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gooddollar.org/for-developers/apis-and-sdks/sybil-resistance/identity-viem-wagmi.md).

# Identity (Viem/Wagmi)

For a live demo of the identity integration (using development identity contracts), visit: [Demo Identity App](https://demo-identity-app.vercel.app/)

#### Contracts

```javascript
    production: {
      celo: "https://celoscan.io/address/0xC361A6E67822a0EDc17D899227dd9FC50BD62F42",
      fuse: "https://explorer.fuse.io/address/0x2F9C28de9e6d44b71B91b8BA337A5D82e308E7BE",
    },
    staging: {
      celo: "https://celoscan.io/address/0x0108BBc09772973aC27983Fc17c7D82D8e87ef4D",
      fuse: "https://explorer.fuse.io/address/0xb0cD4828Cc90C5BC28f4920Adf2Fd8F025003D7E",
    },
    development: {
      celo: "https://celoscan.io/address/0xF25fA0D4896271228193E782831F6f3CFCcF169C",
      fuse: "https://explorer.fuse.io/address/0x1e006225cff7d37411db28f652e0Da9D20325eBb",
    }
```

### Installation

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

```bash
npm install @goodsdks/citizen-sdk
```

or if you prefer using Yarn:

```bash
yarn add @goodsdks/citizen-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.

```typescript
import React from 'react';
import { WagmiProvider } from 'wagmi';
import { useIdentitySDK } from '@goodsdks/citizen-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**

```typescript
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

* [GoodSdks](https://github.com/GoodDollar/GoodSdks)
* [Viem Documentation](https://viem.sh/)
* [Wagmi Documentation](https://wagmi.sh/)
* [OpenZeppelin Contracts](https://docs.openzeppelin.com/contracts/)
* [IdentityV2 Smart Contract](https://github.com/GoodDollar/GoodProtocol/blob/master/contracts/identity/IdentityV2.sol)
* [Live Demo Identity App](https://demo-identity-app.vercel.app/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gooddollar.org/for-developers/apis-and-sdks/sybil-resistance/identity-viem-wagmi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
