> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inco.org/llms.txt
> Use this file to discover all available pages before exploring further.

# RainbowKit

> Set up RainbowKit wallet integration with Inco

## Scaffold

<CodeGroup>
  ```bash npm theme={null}
  npx create-inco-app@latest my-app --wallet rainbowkit --framework hardhat --chain evm --yes
  ```

  ```bash pnpm theme={null}
  pnpm create inco-app@latest my-app --wallet rainbowkit --framework hardhat --chain evm --yes
  ```

  ```bash yarn theme={null}
  yarn create inco-app my-app --wallet rainbowkit --framework hardhat --chain evm --yes
  ```

  ```bash bun theme={null}
  bunx create-inco-app@latest my-app --wallet rainbowkit --framework hardhat --chain evm --yes
  ```
</CodeGroup>

This scaffolds the full monorepo with RainbowKit as the wallet provider. For just the frontend, add `--template frontend`.

## Environment Setup

Get a WalletConnect Project ID from [cloud.walletconnect.com](https://cloud.walletconnect.com) and set it in `frontend/.env`:

```bash frontend/.env theme={null}
# Base network: "testnet" (Base Sepolia, default) or "mainnet" (Base Mainnet)
NEXT_PUBLIC_NETWORK=testnet

NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id_here

# Your deployed contract address
NEXT_PUBLIC_CONFLOTTERY_ADDRESS=<deployed_contract_address>
```

<Note>
  Without a Project ID, the template falls back to an injected-wallet-only config (no WalletConnect), so it still runs locally.
</Note>

## Provider Setup

RainbowKit wraps your app with `WagmiProvider` + `RainbowKitProvider`. The chain comes from `activeChain` in `lib/network.ts`, which follows `NEXT_PUBLIC_NETWORK` — no per-provider chain edits needed.

```tsx components/Providers.tsx theme={null}
"use client";

import { ReactNode, useState, useEffect } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { WagmiProvider, createConfig, http } from "wagmi";
import {
  getDefaultConfig,
  RainbowKitProvider,
  darkTheme,
  lightTheme,
} from "@rainbow-me/rainbowkit";
import { ThemeProvider, useTheme } from "next-themes";
import { activeChain } from "@/lib/network";

const queryClient = new QueryClient();

const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID || "";

const config = projectId
  ? getDefaultConfig({
      appName: "inco confidential lottery",
      projectId,
      chains: [activeChain],
      ssr: true,
    })
  : createConfig({
      chains: [activeChain],
      transports: {
        [activeChain.id]: http(),
      },
      ssr: true,
    });

// Inner provider that uses theme context
const RainbowKitWithTheme = ({ children }: { children: ReactNode }) => {
  const { resolvedTheme } = useTheme();
  const [mounted, setMounted] = useState(false);

  useEffect(() => {
    setMounted(true);
  }, []);

  const rainbowTheme =
    mounted && resolvedTheme === "light"
      ? lightTheme({ accentColor: "#262626", accentColorForeground: "#fafafa", borderRadius: "none" })
      : darkTheme({ accentColor: "#d4d4d4", accentColorForeground: "#0a0a0a", borderRadius: "none" });

  return (
    <RainbowKitProvider theme={rainbowTheme}>{children}</RainbowKitProvider>
  );
};

const Providers = ({ children }: { children: ReactNode }) => {
  if (!projectId) {
    console.warn(
      "Missing NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID. Get one at https://cloud.walletconnect.com/"
    );
  }

  return (
    <ThemeProvider attribute="class" defaultTheme="dark" enableSystem>
      <WagmiProvider config={config}>
        <QueryClientProvider client={queryClient}>
          <RainbowKitWithTheme>{children}</RainbowKitWithTheme>
        </QueryClientProvider>
      </WagmiProvider>
    </ThemeProvider>
  );
};

export { Providers };
```

**Provider hierarchy:** `ThemeProvider` → `WagmiProvider` → `QueryClientProvider` → `RainbowKitProvider`

## Inco SDK Integration

The Inco SDK works with the `walletClient` provided by wagmi (which RainbowKit supplies). The network-aware client comes from `lib/network.ts`:

```tsx hooks/useConfLottery.ts theme={null}
import { getIncoLightning } from "@/lib/network";
import { handleTypes } from "@inco/lightning-js";
import { useAccount, useWalletClient } from "wagmi";
import { parseEther } from "viem";

const { address } = useAccount();
const { data: walletClient } = useWalletClient();

// Network (Base Sepolia / Mainnet) is selected centrally in lib/network.ts via NEXT_PUBLIC_NETWORK.
const zap = await getIncoLightning();

// Encrypt a value before sending on-chain
const ciphertext = await zap.encrypt(parseEther(amount), {
  accountAddress: address,
  dappAddress: LOTTERY_ADDRESS,
  handleType: handleTypes.euint256,
});

// Decrypt a handle with attestation (e.g. check if the user won)
const [result] = await zap.attestedDecrypt(walletClient, [encryptedHandle]);
const isWinner = result.plaintext.value; // boolean for an ebool handle
```

## Dependencies

| Package                  | Purpose                     |
| ------------------------ | --------------------------- |
| `@rainbow-me/rainbowkit` | RainbowKit wallet connector |
| `@inco/lightning-js`     | Inco encryption/decryption  |
| `wagmi`                  | EVM wallet hooks            |
| `viem`                   | Ethereum utilities          |
