Particle Network를 dApp에 통합하기
소개
Particle Network provides Wallet Abstraction services to simplify user onboarding.
The Particle Connect SDK supports EVM-compatible chains, including Kaia and its testnet. It allows for 2-click onboarding with social and Web3 login options, all within a single modal.
With Particle Network, developers on Kaia can embed social logins for the Kaia Mainnet and testnet, allowing users to generate and use a wallet within your application using only their Google, email, X, etc.
This page offers an overview and tutorial for implementing Particle Connect within a Kaia-based application, to help you start the integration process.
전제 조건
- A Next.js project set up with TypeScript and Tailwind CSS
- You can create this by running:
npx create-next-app@latest
- You can create this by running:
- A Project ID, Client Key, and App ID from the Particle Dashboard.
설치
디앱에서 Particle Network, 특히 Particle 커넥트를 활용하려면 먼저 필요한 라이브러리를 설치해야 합니다. The Particle Connect SDK streamlines wallet creation, user login, and blockchain interactions with one interface. It supports both social and Web3 logins for easy access.
To install the SDK, along with Viem (backend for Connect) and ethers (demonstrating EIP-1193 providers), run:
yarn add @particle-network/connectkit viem@^2 ethers
Initializing Particle Connect
To begin with, we’ll set up Particle Connect, Particle's flagship authentication SDK. Create a new file called ConnectKit.tsx
in the root directory of your project. This file will house the ParticleConnectKit
component, a wrapper for the configured ConnectKitProvider
instance that serves as the primary interface for the configuration of Particle Connect (we'll go over what this looks like programmatically in a moment).
Next, head over to the Particle dashboard to create a new web application project and obtain the following essential API keys:
projectId
– a unique identifier for your project.clientKey
– a key specific to your client.appId
– the ID for your application.
Store these API keys in a .env
file as follows:
NEXT_PUBLIC_PROJECT_ID='PROJECT_ID'NEXT_PUBLIC_CLIENT_KEY='CLIENT_KEY'NEXT_PUBLIC_APP_ID='APP_ID'
Now, add the following code to your ConnectKit.tsx
file:
"use client";import React from "react";import { ConnectKitProvider, createConfig } from "@particle-network/connectkit";import { authWalletConnectors } from "@particle-network/connectkit/auth";import { defineChain } from "@particle-network/connectkit/chains";import { wallet, EntryPosition } from "@particle-network/connectkit/wallet";const kaiaMainnet = defineChain({ id: 8217, name: "Kaia", nativeCurrency: { decimals: 18, name: "KAIA", symbol: "KAIA", }, rpcUrls: { default: { http: ["https://public-en.node.kaia.io"], }, }, blockExplorers: { default: { name: "Explorer", url: "https://kaiascope.com/" }, }, testnet: false,});const kaiaTestnet = defineChain({ id: 1001, name: "Kaia Testnet", nativeCurrency: { decimals: 18, name: "KAIA", symbol: "KAIA", }, rpcUrls: { default: { http: ["https://public-en-kairos.node.kaia.io"], }, }, blockExplorers: { default: { name: "Explorer", url: "https://kairos.kaiascope.com/" }, }, testnet: true,});const config = createConfig({ projectId: process.env.NEXT_PUBLIC_PROJECT_ID!, clientKey: process.env.NEXT_PUBLIC_CLIENT_KEY!, appId: process.env.NEXT_PUBLIC_APP_ID!, walletConnectors: [authWalletConnectors({})], plugins: [ wallet({ entryPosition: EntryPosition.BR, // Positions the modal button at the bottom right on login visible: true, // Determines if the wallet modal is displayed }), ], chains: [kaiaMainnet, kaiaTestnet],});export const ParticleConnectkit = ({ children }: React.PropsWithChildren) => { return <ConnectKitProvider config={config}>{children}</ConnectKitProvider>;};
Virtually every property of this component can be configured, from the different login types you support to the visual appearance of the modal; to explore these various options, head over to Particle's documentation.
Integrate Particle Connect into Your App
Now that the configuration is complete, wrap your application with the ParticleConnectKit
component to enable global access to the Particle Connect SDK. To achieve this, modify your layout.tsx
file in the src
directory as follows:
import { ParticleConnectkit } from '@/connectkit';import type { Metadata } from 'next';import { Inter } from 'next/font/google';import './globals.css';const inter = Inter({ subsets: ['latin'] });export const metadata: Metadata = { title: 'Particle Connectkit App', description: 'Generated by create next app',};export default function RootLayout({ children,}: { children: React.ReactNode;}) { return ( <html lang="en"> <body className={inter.className}> <ParticleConnectkit>{children}</ParticleConnectkit> </body> </html> );}