Privy is an embedded wallet provider that offers a seamless user experience by creating wallets automatically upon login. It supports various login methods, including email and SMS, making it easy for users to interact with blockchain applications. In this section, we'll configure Privy as a wallet provider alongside the JustWeb3 Widget for ENS management and decentralized identity features.
Installing Required Dependencies
To get started, install the required packages for Privy, JustWeb3, wagmi, and react-query:
Note you might need to additionly install the @solana/web3.js as the @privy-io/react-auth package requires it
Initial Code Setup
In your main file (e.g., App.tsx or Providers.tsx), import the necessary components from Privy, wagmi, and JustWeb3.
import "@rainbow-me/rainbowkit/styles.css";
import '@justweb3/widget/styles.css';
import React from "react";
import { JustWeb3Provider, JustWeb3ProviderConfig, JustWeb3Button } from "@justweb3/widget";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { http } from "wagmi";
import { mainnet, sepolia } from "wagmi/chains";
import { createConfig, WagmiProvider } from "@privy-io/wagmi";
import { PrivyProvider, usePrivy } from "@privy-io/react-auth";
import { useEnsAuth } from "@justaname.id/react";
Configuration
In this setup, you can define the configuration for both Privy and JustWeb3. The PrivyProvider manages user authentication and wallet creation, while the JustWeb3Provider handles ENS-based authentication and identity management.
The embeddedWallets option in Privy’s config specifies how and when wallets should be created.
The loginMethods array defines the available login methods, such as email and SMS.
The JustWeb3 configuration includes customization for ENS management and color theming.
For additional configuration settings, please refer to the Privy Documentation
Using Privy for Authentication
The Connect component handles the authentication flow using Privy. It displays a login button, and if the user is authenticated, it shows the user object and ENS information.