Skip to main content

Scaffold

npx create-inco-app@latest my-app --wallet privy --framework hardhat --chain evm --yes
This scaffolds the full monorepo with Privy as the wallet provider. For just the frontend, add --template frontend.

Environment Setup

Get your App ID from dashboard.privy.io and set it in frontend/.env:
frontend/.env
# Base network: "testnet" (Base Sepolia, default) or "mainnet" (Base Mainnet)
NEXT_PUBLIC_NETWORK=testnet

NEXT_PUBLIC_PRIVY_APP_ID=your_app_id_here

# Your deployed contract address
NEXT_PUBLIC_CONFLOTTERY_ADDRESS=<deployed_contract_address>

Provider Setup

Privy wraps your app with PrivyProvider and Privy’s wagmi connector (@privy-io/wagmi), giving you email, social, and embedded-wallet login. The chain comes from activeChain in lib/network.ts, which follows NEXT_PUBLIC_NETWORK — no per-provider chain edits needed.
components/Providers.tsx
"use client";

import { ReactNode } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { PrivyProvider } from "@privy-io/react-auth";
import { WagmiProvider, createConfig } from "@privy-io/wagmi";
import { http } from "wagmi";
import { ThemeProvider } from "next-themes";
import { activeChain } from "@/lib/network";

const queryClient = new QueryClient();

const appId = process.env.NEXT_PUBLIC_PRIVY_APP_ID || "";

const config = createConfig({
  chains: [activeChain],
  transports: {
    [activeChain.id]: http(),
  },
  ssr: true,
});

const Providers = ({ children }: { children: ReactNode }) => {
  if (!appId) {
    console.warn(
      "Missing NEXT_PUBLIC_PRIVY_APP_ID. Get one at https://dashboard.privy.io/"
    );
  }

  return (
    <ThemeProvider attribute="class" defaultTheme="dark" enableSystem>
      <PrivyProvider
        appId={appId}
        config={{
          appearance: {
            theme: "dark",
          },
          embeddedWallets: {
            createOnLogin: "users-without-wallets",
          },
          defaultChain: activeChain,
          supportedChains: [activeChain],
        }}
      >
        <QueryClientProvider client={queryClient}>
          <WagmiProvider config={config}>{children}</WagmiProvider>
        </QueryClientProvider>
      </PrivyProvider>
    </ThemeProvider>
  );
};

export { Providers };
Provider hierarchy: ThemeProviderPrivyProviderQueryClientProviderWagmiProvider Note the wagmi createConfig is imported from @privy-io/wagmi (not wagmi), so Privy’s embedded wallets connect through wagmi automatically.

Inco SDK Integration

The Inco SDK works with the walletClient provided by wagmi (which Privy supplies). The network-aware client comes from lib/network.ts:
hooks/useConfLottery.ts
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

PackagePurpose
@privy-io/react-authPrivy authentication & embedded wallets
@privy-io/wagmiPrivy ↔ wagmi connector
@inco/lightning-jsInco encryption/decryption
wagmiEVM wallet hooks
viemEthereum utilities