Leveraging Particle Connect within web applications.
projectId
, clientKey
, and appId
from the Particle dashboard.
These are required values, and you’ll need in the coming configuration process; they’ll authenticate your instance of Particle Connect.
ConnectKitProvider
component to apply customizations and insert the aforementioned keys.
Here, you’ll configure the following core parameters:
projectId
, clientKey
, and appId
— required values from the Particle dashboard.chains
— the supported chains for your dApp; these are viem-originating objects imported from @particle-network/connectkit/chains
.walletConnectors
— an array of connectors representing the wallets you’d like to support within your dApp.plugins
— plugins enabling Particle’s embedded wallet interface or implementing account abstraction.appearance
— deep customization options affecting the login modal.ConnectKitProvider
, using the parameters above.
Create a new component named connectkit.tsx
and follow the template to set up your configuration.
"use client"
directive at the beginning of the file.ParticleConnectKit
component (representing ConnectKitProvider
) and wrap your application with it in your index
or layout
file. Here’s an example of a layout.tsx
file:
@particle-network/connectkit/chains
.
You can also integrate additional EVM-compatible chains by defining custom chain objects that extend the Chain
type if you are connecting to a standard wallet (without using an embedded wallet or social login features).
defineChain
will only work with supported chain IDs (those listed in Network
Coverage), as such, this function is primarily for using custom RPCs, explorers, symbols,
etc.index
file and into your main App
component, you’ll need to include the Connect button (ConnectButton
from @particle-network/connectkit
) to facilitate the utilization of Particle Connect.
You can then use isConnected
from useAccount()
to handle your frontend post-connection.
ConnectButton
component turns into an embedded widget that displays a chain selector on one side and address/account information on the other after the user logs in.
If you want to remove the chain selector portion of the widget, you can do it by adding the following styles to your global.css
file:
.sc-dUMaFF.iLJvQa
and .sc-dKGrn.cHiobV
) match the generated CSS in your project. These names may vary depending on your library or framework, so inspect your component’s rendered DOM if the provided selectors do not work.appearance
property allows you to customize the modal’s style, including changing the accent color, border radius, primary button color, font, and more.
You can try it in the Particle Demo and export the configuration.
light
or dark
if you customize the background or foreground.
Your custom theme will override the current mode’s default values (light
, dark
, auto
).email
, phone
, and various social logins (Google, X, and so on).
passkeySmartWallet
from "@particle-network/connectkit/evm"
and include it in the evmWalletConnectors
object.
injected
method to support additional extension-based wallets that inject a provider.
Particle Connect supports the following EVM wallets by default:
walletConnectors
(within your ConnectKitProvider
config).
injected
method to customize support for specific wallets.
Particle Connect supports the following Solana wallets by default:
walletConnectors
(within your ConnectKitProvider
config) to enable these options.
wallet
plugin to plugins
(within your ConnectKitProvider
config).
widgetIntegration: 'embedded'
. This allows you to have complete control over the wallet component’s visibility and placement.
Use the provided methods to append the wallet iframe to your desired location and listen for specific events (e.g., closing the wallet) to customize the user experience.
aa
plugin.
This plugin leverages Particle’s Account Abstraction SDK to use ERC-4337 features in your application.
Particle Network offers support for several smart account implementations, including:
aa
plugin to the plugins
section of your ConnectKitProvider
configuration:
useSmartAccount
hook for constructing and sending UserOperations
(transactions); these methods are available directly on the useSmartAccount
instance.
Alternatively, this instance can be plugged into AAWrapProvider
(generates an 1193-compatible provider) from @particle-network/aa
to leverage the smart account through a standard library, such as Ethers.
useSmartAccount
hook, you can easily obtain the account’s address with the getAddress
method.
This is particularly useful for fetching and displaying balances or showing the address within your application’s UI. Importantly, the typical hooks used for retrieving user addresses will not reflect the correct address in this case; they’ll return the EOA; the only way to retrieve the user’s smart account address is through {instance of useSmartAccount}.getAddress
.
Below is an example using useEffect
to achieve this:
isConnected
from the useAccount
hook (isConnected
will be truthy automatically upon connection).
useAccount
to get the address and status
, or useAddress
to get the address.
useAccount
only returns the EOA address. useAddress
returns the smart account’s address when Account Abstraction
(AA) is enabled and the EOA address when AA is disabled.useSwitchChain
imported from @particle-network/connectkit
.
When calling the switch network method, the SDK will request the user to confirm the network switch or add the network if it was not previously set.
chain
object, which is available through the useAccount()
hook.
chain?.name
. You can access various other properties of the chain
object to retrieve more detailed information about the active chain.
Available Fields in `chain`
id
name
nativeCurrency
rpcUrls
blockExplorers
contracts
sourceId
testnet
custom
fees
formatters
serializers
WalletClient
, refer to the Viem documentation.usePublicClient()
hook, eliminating the need for a separate provider.
usePublicClient
returns a Connection
type (imported from @solana/web3.js
).
useParticleAuth()
hook to retrieve userinfo
(which includes details about the method they used to connect, when the account was created, etc.) and other relevant details from Particle Auth.
userInfo
object is provided by Particle AuthKit. For a detailed breakdown of its structure and available
properties, refer to the Handling User Information
section in the Particle AuthKit documentation.@particle-network/connectkit
provides several React Hooks for interacting with both Particle Connect and Particle Auth. These include:
useWallets
- Returns all connected wallets.useAccount
- Retrieves the currently active account (address) and its status.useDisconnect
- Disconnects a wallet.useModal
- Opens the connect modal (setOpen
) without using ConnectButton
.usePublicClient
- A Public Client interface for accessing external JSON-RPC API methods, allowing you to retrieve block numbers, fetch transactions, and read data from smart contracts.useSwitchChain
- Switches and retrieves the current primary chain.useSmartAccount
- Provides ERC-4337 smart account functionality; requires implementation of the aa
plugin.useParticleAuth
- Interfaces for Particle Auth.useEmbeddedWallet
- Manages the embedded wallet; requires implementation of the wallet
plugin.