Tutorial: Implementing Particle Connect on Celo
The Particle Connect SDK simplifies wallet creation, user login, and blockchain interactions through a single interface. It supports both social logins and traditional Web3 wallets, making Web3 more accessible to users of all experience levels. To install this library, alongside Viem, which is used in the backend by Connect and ethers, which is used to demonstrate how to use any EIP-1193 provider, run the following command at the root of your project:1. Set Up Particle Connect
To start, we’ll configure and initialize Particle Connect (Particle’s flagship authentication SDK). Begin by creating a new file calledConnectKit.tsx
in your project’s root directory, where we’ll set up the ParticleConnectKit
component as the main interface for configuration.
Before proceeding, create a new project with a web app on the Particle dashboard and retrieve the following API keys:
projectId
– your project’s unique ID.clientKey
– your client-specific key.appId
– your application ID.
.env
file in the following format:
ConnectKit.tsx
file:
ParticleConnectKit
component—a wrapper for the configured ConnectKitProvider
instance—using your project keys and defining essential SDK settings. These settings include supported blockchain networks (Celo and Alfajores), wallet positioning, and visibility options for an optimal user experience.
For further customization options, refer to the Particle Connect documentation.
2. Integrate the ParticleConnectKit
Component in Your App
With the configuration complete, wrap your application with the ParticleConnectKit
component to provide global access to the Particle Connect SDK. To do this, update your layout.tsx
file located in src
as shown below:
ParticleConnectKit
, you make the Particle Connect SDK available globally within your app. This setup in layout.tsx
ensures all components have access to the SDK, enabling features like social logins and wallet generation across your app.
3. Set Up Key Hooks in page.tsx
With Particle Connect configured, you can use the SDK for social logins and wallet interactions within your application. In this example, we’ll set up several essential hooks in page.tsx
to manage user connection, retrieve data, and perform blockchain interactions.
For this example, we’ll use five hooks from @particle-network/connectkit
:
ConnectButton
: Displays a connect button, transforming into an embedded widget once logged in.useAccount
: Retrieves the user’s wallet address and connection state.useWallets
: Provides the connected wallet, allowing interactions with the blockchain.usePublicClient
: You can fetch data from the chain, like balances, using Viem.useDisconnect
: Lets you set up custom disconnect functionality.
page.tsx
, showcasing how to use these hooks to connect via social logins, retrieve user data, and display it: