Among all the SDKs for Particle Auth, the Web SDK (@particle-network/authkit) is the most widely used. Thus, it offers extensive support and flexibility in driving onboarding through social logins, facilitating interaction with Particle’s Wallet-as-a-Service.
The Particle Auth SDK is the primary mechanism for configuring and using social logins. Whether you’re starting from scratch or already have an onboarding or authentication flow set up within your application, the Particle Auth Core Web SDK is a simple yet powerful integration.
Configuration is primarily handled by wrapping an application with Particle Auth’s master configuration component, essential for authenticating your project and customizing the optional embedded wallet modal.
No matter which Particle Auth SDK you’re using, you must define your projectId, clientKey, and appId within this configuration object to authenticate your Particle Auth instance properly. Additionally, you can apply customizations to the wallet modal for a tailored user experience.
Follow the quickstart tutorial to set up a project and find the required keys: Create a new
project.
Below is an example of an index.tsx file from a create-react-app project. In this example, the AuthCoreContextProvider component acts as the configuration wrapper for the entire application.
import React from 'react'import ReactDOM from 'react-dom/client'import { AuthType } from '@particle-network/auth-core';import { AuthCoreContextProvider, PromptSettingType } from '@particle-network/authkit';import { mainnet } from '@particle-network/authkit/chains';import App from './App'import('buffer').then(({ Buffer }) => {window.Buffer = Buffer;});ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( <React.StrictMode> <AuthCoreContextProvider options={{ projectId: process.env.REACT_APP_PROJECT_ID!, clientKey: process.env.REACT_APP_CLIENT_KEY!, appId: process.env.REACT_APP_APP_ID!, chains: [mainnet], authTypes: [AuthType.email, AuthType.google, AuthType.twitter], themeType: "dark", // Login modal theme fiatCoin: "USD", language: "en", // optional, ERC4337 erc4337: { name: "SIMPLE", version: "2.0.0", }, // You can prompt the user to set up extra security measure upon login or other interactions promptSettingConfig: { promptPaymentPasswordSettingWhenSign: PromptSettingType.first, promptMasterPasswordSettingWhenLogin: PromptSettingType.first, }, wallet: { themeType: 'dark', // Wallet modal theme visible: true, customStyle: { displayTokenAddresses: ["0x4d224452801ACEd8B2F0aebE155379bb5D594381"], // Display a custom token within the wallet modal priorityTokenAddresses: ["0x4d224452801ACEd8B2F0aebE155379bb5D594381"], }, }, }} > <App /> </AuthCoreContextProvider> </React.StrictMode>)
To interact with a user’s account (wallet), they must first log in using Particle Auth or Particle Connect, similar to how one would enter a password and unlock MetaMask.
Before interactions can occur, the application must either recognize that the user is already logged in or prompt them to complete the login process.
You can use the connect and connected functions from the useConnect() hook to handle the connection logic:
In this example, the handleLogin function initiates the login process by displaying the login modal if the connected status is false, indicating that the user is not currently logged in.
By default, Particle Auth supports email login with an OTP (One Time Password) flow through the login modal. However, you can build a custom UI to request and validate OTPs directly, allowing for greater flexibility and control over the authentication experience.
@particle-network/auth-core is already included as a dependency in @particle-network/authkit, so you don’t need to install it separately.
Step 1: Request an OTP
Use the getConnectCaptcha() function from @particle-network/auth-core to send an OTP to the user’s email.
page.tsx
import { getConnectCaptcha } from "@particle-network/auth-core";// Send an OTP to the emailconst sendOtpRequest = async (email) => { const success = await getConnectCaptcha({ email }); console.log(success ? "OTP sent successfully!" : "Failed to request OTP. Try again.");};
Step 2: Verify OTP & Log In
Once the user receives the OTP, use the connect() function, including OTP and email within loginParams, to verify it and complete the login.
You can use your existing user base or authentication method with Particle Auth through JWT. This way, your users can still log in with their current accounts.
To retrieve the public address linked to a user’s account, when it’s not already obtained through the login via userInfo, you can use the following method:
import { ethers } from "ethers";import { useEthereum } from '@particle-network/authkit';const { provider } = useEthereum();// Assuming Ethers is not already initializedconst ethersProvider = new ethers.BrowserProvider(provider as Eip1193Provider,"any");const accounts = await ethersProvider.listAccounts();const address = accounts[0].address;// Orconst signer = await ethersProvider.getSigner();const address = await signer.getAddress();
Sending transactions using Particle as the Signer/underlying wallet is also quite simple.
If you’re using Ethers.js, you’re already set —as long as a user has logged in with Particle, transactions can be sent as you would with any other wallet.
When a given transaction is sent, and a signature is needed for authentication, a standard confirmation popup (also customizable through the Particle dashboard) will appear directly within the application. Transactions can be sent through the following:
const signer = ethersProvider.getSigner();const executeTx = async () => {const signer = await ethersProvider.getSigner();const tx = {to: recipientAddress,value: ethers.parseEther("0.01"),data: "0x",};const txResponse = await signer.sendTransaction(tx);const txReceipt = await txResponse.wait();// You can log or handle the receipt hereconsole.log(txReceipt);};
To the end-user, sending transactions, regardless of the chosen method, looks like this (depending on
customization outlined in the Particle dashboard).
In cases where you’d like to sign either a raw string (personal) or typed data (eth_signTypedData), the process is quite straightforward.
You can accomplish this using standard libraries like Ethers or leveraging Particle’s native functionality. The examples below illustrate both approaches.
For instance, when sending transactions, the signatures are automatically formatted and presented to the user in a popup request. This ensures a user-friendly experience by displaying the relevant data in UTF-8 format.
To enable blind signatures (signing without a confirmation popup) in Particle Auth, certain conditions must be met when configuring the AuthCoreContextProvider component and setting up the authentication flow.
Blind signing is only supported when the user is authenticated via JWT or Telegram.
Master Password Requirement
Users must either:
Have entered the master password, or
Not have set a master password in the first place.
No Payment Password
Users should not have set a payment password (as this interrupts the signing process).
Disable Payment Password Prompt Setting
Set the promptPaymentPasswordSettingWhenSign parameter to false within AuthCoreContextProvider.
Below is a collection of examples describing the different hooks available with Particle Auth.
These hooks facilitate social login and native application-level interaction (such as message signing, sending transactions, etc.) directly through Particle Auth.
useAuthCore provides additional functionality, such as retrieving userInfo after login, forcing different account menus to open, accessing the on-ramp page, and more.
TypeScript
import { useAuthCore } from '@particle-network/authkit';const { userInfo, // Standard user info, null is returned if not connected needRestoreWallet, // Whether or not a master password is needed from the current user openAccountAndSecurity, // Opens account and security modal openSetMasterPassword, // Opens set master password modal openChangeMasterPassword, // Opens change master password modal openRestoreByMasterPassword, // Opens input master password modal openSetPaymentPassword, // Opens set payment password modal openChangePaymentPassword, // Opens change payment password modal openSetSecurityAccount, // Opens set security account modal openLinkLoginAccount, // Opens link login account modal openWallet, // Opens wallet in iframe getWalletIFrame, // Manages the embedded wallet modal, used for opening the wallet modal in a custom iframe openBuy, // Opens the onramp aggregation page} = useAuthCore();
useCustomize provides several methods for customizing the wallet modal, such as changing the theme type (light or dark), creating a custom style, changing the language, and more.
TypeScript
import { useCustomize } from '@particle-network/authkit';const { setThemeType, // Sets theme type, 'light' or 'dark' setCustomStyle, // Sets custom modal styles setWalletOptions, // Sets wallet modal options setLanguage, // Sets language being used setFiatCoin, // Sets fiat coin being used setERC4337, // Sets whether the modal has ERC-4337 enabled} = useCustomize();
Integrating and leveraging Particle Auth isn’t limited to interfaces provided by Particle Network; instead, it’s built to fit into nearly every implementation scenario. Whether you’re using RainbowKit, Web3Modal, or Solana’s wallet-adapter or would like to have a standalone social login button within your application, Particle Auth can be used.