Skip to content

Particle-Network/upgrade-to-authkit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@particle-network/authkit @particle-network/aa Demo Application

Migrating from auth-core-modal to AuthKit

This repository demonstrates how to upgrade from the deprecated auth-core-modal package to the new @particle-network/authkit SDK.
It includes a working Next.js demo showing you:

  • How to replace your existing auth-core-modal setup with AuthKit.
  • How to configure social logins, chain support, and smart accounts.
  • How to send transactions using the @particle-network/aa SDK with ethers v6.

By following this guide, you’ll learn the exact changes needed to modernize your project and fully adopt AuthKit.


🔑 Particle AuthKit

Particle AuthKit enables application-embedded onboarding into an MPC-TSS/AA wallet via social login (Google, GitHub, email, phone number, etc.).

👉 Learn more about Particle Auth.

🪪 Account Abstraction SDK

Particle Network provides native support for ERC-4337 account abstraction. The AA SDK allows you to construct, sponsor, and send UserOperations, deploy smart accounts, retrieve fee quotes, and more.

On testnets, every gasless transaction is automatically sponsored. On mainnet, you’ll need to deposit USDT into Paymaster.

👉 Learn more about the Particle AA SDK.


🛠️ Upgrading to AuthKit

The steps below walk you through migrating this demo (and your own apps) from auth-core-modal to @particle-network/authkit.

Step 1: Install the New Packages

yarn add @particle-network/authkit @particle-network/wallet viem@2

Step 2: Create a New Authkit.tsx Component

In your components directory:

"use client";

import { AuthType } from "@particle-network/auth-core";
import { sepolia, baseSepolia } from "@particle-network/authkit/chains";
import { AuthCoreContextProvider } from "@particle-network/authkit";
import { EntryPosition } from "@particle-network/wallet";

export const ParticleAuthkit = ({ children }: React.PropsWithChildren) => {
  return (
    <AuthCoreContextProvider
      options={{
        projectId: process.env.NEXT_PUBLIC_PROJECT_ID!,
        clientKey: process.env.NEXT_PUBLIC_CLIENT_KEY!,
        appId: process.env.NEXT_PUBLIC_APP_ID!,

        chains: [sepolia, baseSepolia],

        authTypes: [
          AuthType.email,
          AuthType.google,
          AuthType.twitter,
          AuthType.github,
          AuthType.discord,
          AuthType.phone,
        ],
        themeType: "dark",
        fiatCoin: "USD",
        language: "en",

        erc4337: {
          name: "SIMPLE",
          version: "2.0.0",
        },
        wallet: {
          visible: true,
          entryPosition: EntryPosition.TL,
          customStyle: {},
        },
      }}
    >
      {children}
    </AuthCoreContextProvider>
  );
};

🔑 Key change: Chains are now imported as Viem objects instead of the old format.

Step 3: Wrap Your App in layout.tsx

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

import { ParticleAuthkit } from "./components/AuthKit";

export const metadata: Metadata = {
  title: "Particle Auth App",
  description: "An application leveraging Particle Auth for social logins.",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <ParticleAuthkit>{children}</ParticleAuthkit>
      </body>
    </html>
  );
}

Step 4: Update page.tsx

Update hooks and smart account configuration:

import {
  useEthereum,
  useConnect,
  useAuthCore,
} from "@particle-network/authkit";
import { sepolia, baseSepolia } from "@particle-network/authkit/chains";

const smartAccount = new SmartAccount(provider, {
  projectId: process.env.NEXT_PUBLIC_PROJECT_ID!,
  clientKey: process.env.NEXT_PUBLIC_CLIENT_KEY!,
  appId: process.env.NEXT_PUBLIC_APP_ID!,
  aaOptions: {
    accountContracts: {
      SIMPLE: [
        {
          version: "2.0.0",
          chainIds: [sepolia.id, baseSepolia.id],
        },
      ],
    },
  },
});

// UI example
<h3 className="text-lg mb-2 text-gray-400">Chain: {chainInfo.name}</h3>
<TxNotification
  hash={transactionHash}
  blockExplorerUrl={chainInfo.blockExplorers?.default.url}
/>

Configuring Social Logins

Available options:

{
  "email": "email",
  "phone": "phone",
  "facebook": "facebook",
  "google": "google",
  "apple": "apple",
  "twitter": "twitter",
  "discord": "discord",
  "github": "github",
  "twitch": "twitch",
  "microsoft": "microsoft",
  "linkedin": "linkedin",
  "jwt": "jwt"
}

Configuring Smart Accounts (aaOptions)

Examples: • BICONOMY — versions 1.0.0 and 2.0.0 supported. • CYBERCONNECT — currently only 1.0.0. • SIMPLE — supports 1.0.0 and 2.0.0.

import { sepolia, baseSepolia } from "@particle-network/authkit/chains";

const smartAccount = new SmartAccount(provider, {
  projectId: process.env.REACT_APP_PROJECT_ID!,
  clientKey: process.env.REACT_APP_CLIENT_KEY!,
  appId: process.env.REACT_APP_APP_ID!,
  aaOptions: {
    accountContracts: {
      SIMPLE: [
        {
          version: "2.0.0",
          chainIds: [sepolia.id, baseSepolia.id],
        },
      ],
    },
  },
});

// Switch implementation if multiple contracts are defined
// smartAccount.setSmartAccountContract({ name: "SIMPLE", version: "1.0.0" });

Quickstart (Demo App)

  1. Clone the repository
git clone https://github.com/soos3d/particle-auth-aa-demo.git
  1. Move into the app directory
cd particle-aa-nextjs
  1. Install dependencies
yarn install
# or
npm install
  1. Set environment variables

Define the following in .env: • NEXT_PUBLIC_PROJECT_ID — from the Particle dashboard. • NEXT_PUBLIC_CLIENT_KEY — from the dashboard. • NEXT_PUBLIC_APP_ID — from the dashboard.

  1. Start the project
npm run dev
# or
yarn dev

About

Demo app demonstrating how to upgrade the auth-core-modal package to the newer Authkit SDK

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • TypeScript 95.9%
  • CSS 3.0%
  • JavaScript 1.1%