Comprehensive tutorial diving into the process of using Particle Network’s Auth Core and AA SDK on ZetaChain.
SimpleAccount
. Thus, developers building Omnichain dApps on ZetaChain can leverage end-to-end account abstraction either directly or hand-in-hand with consumer-ready onboarding and interaction through Smart Wallet-as-a-Service. The intersection of these technologies (Omnichain dApps and Smart Wallet-as-a-Service) results in a next-generation user experience.
This document will outline how you can begin building with Particle Network’s Smart Wallet-as-a-Service on ZetaChain, or alternatively, use Particle’s AA infrastructure directly (independent from Smart Wallet-as-a-Service).
@particle-network/auth-core-modal
), which is Particle Network’s flagship SDK facilitating implementation of its Smart Wallet-as-a-Service. Additionally, we’ll also be leveraging Particle’s AA SDK (@particle-network/aa
). These two SDKs will be used in tandem to facilitate social logins and, in this example, the execution of a sample gasless transaction (a burn of 0.001 ZETA), sent through the Particle Bundler and Omnichain Paymaster.
To begin, you’ll need to install a few different libraries, as mentioned above. Specifically, you’ll need to install the following libraries:
@particle-network/auth-core-modal
, for social logins and the associated embedded wallet modal.@particle-network/aa
, to handle account abstraction, such as defining a specific smart account, custom EIP-1193 provider, etc.@particle-network/chains
, for the ZetaChainTestnet
chain object to be used in the configuration process.ethers
, to facilitate Web3 interaction.react
and ReactDOM
, for this specific example (React demo application).index.tsx
— this is where we’ll be configuring Particle Auth Core. At the top of index.tsx
, import the following objects:
index.tsx
should be used for configuring Particle Auth Core and initializing the @particle-network/auth-core-modal
SDK. Thus, to do this, you’ll be defining various parameters within AuthCoreContextProvider
, as shown below:
AuthCoreContextProvider
, beginning with projectId
, clientKey
, and appId
. These values are required for the initialization of every major SDK offered by Particle Network, as they fundamentally link your application (instance of Particle Auth Core) with the Particle Network dashboard, thus allowing for user tracking, UI customization, etc.
To fetch these values, head over to https://dashboard.particle.network and either create or log into an account, then spin up a new project. Within this new project, you’ll need to create an application –in this example, we’re building a web app, so you can select “Web.” Next, you’ll be prompted for an application name and URL; if you don’t have a deployed application yet in which to use the SDK, feel free to fill in the URL parameter with any filler domain, as it won’t affect usage. With this set up, you can copy the Project ID, Client Key, and App ID, and paste these into the corresponding environment variables within your project.
Beyond the projectId
, clientKey
, and appId
parameters, you’ll also need to set erc4337
, which dictates the account abstraction state (or lack thereof) of the embedded wallet modal. In this case, we’re using a SimpleAccount
implementation (our only currently supported smart account implementation on ZetaChain), which we can dictate by setting name
to "SIMPLE"
. Additionally, version
should be set to "1.0.0"
.
Finally, you can also set custom wallet modal styling and settings through wallet
, where we’re setting visible
to true
, indicating that the wallet modal will be shown upon login (through a Particle logo popup on the bottom right corner of the application). customStyle
can also be set for more targeted settings, restricting supportChains
to ZetaChainTestnet
and resulting in the wallet modal being exclusively bound to the ZetaChain testnet.
For more information on configuring Particle Auth Core, head over to the “Configuring Particle Auth Core” sample.
At this point, your index.tsx
file should look something like the snippet below:
AuthCoreContextProvider
within index.tsx
, we’re ready to build our demo and dive into the specific utilization process of Particle’s Smart Wallet-as-a-Service. To begin, head over to App.tsx
(or its equivalent within your project); this is where the primary components of this application will be hosted.
Before jumping into App.tsx
, let’s establish some context as to what will be built within App.tsx
. As mentioned, the goal here is to have a user log in with one of their social accounts (in this example, we can use Google or Twitter), and send a sponsored transaction (a burn of 0.001 ZETA). More advanced functionalities, such as the usage of session keys, are also possible, as outlined here. However, for this demo specifically, we’ll stick to one of the most used functions of account abstraction –gasless transactions. You’ll be able to apply the same flow covered here to your own application on ZetaChain.
index.tsx
, you’ll need to import a few specific objects from the libraries installed a moment ago. Ensure the first few lines follows the structure of the snippet below:
ethers
.
Kicking it off, you’ll need to define a few functions from the aforementioned hooks, specifically provider
, connect
, disconnect
, and userInfo
(of these, only provider
and connect
are required).
SmartAccount
, the master object for Particle Network’s AA SDK. Configuring SmartAccount
can be explained in two halves: The first half is standard Particle SDK configuration (defining projectId
, clientKey
, and appId
), while the second will be choosing a smart account implementation to be used within the SDK (as covered earlier, this’ll be SimpleAccount
, or in SmartAccount
, represented as simple
).
ethers
provider object can be constructed through AAWrapProvider
, which will initiate a new provider through the constructed SmartAccount
object. Requests sent through this provider (transaction execution, message signing, etc.) will be directed to an AA-enabled embedded wallet (through Particle Auth Core). Additionally, within AAWrapProvider
, we can pass in SendTransactionMode.Gasless
, which will automatically request a signature from the Particle Omnichain Paymaster upon transaction execution. For Testnets, this’ll be automatically sponsored free of charge, although, for Mainnets, you’ll need to recharge the Paymaster on the Particle dashboard.
smartAccount
and calling a standard balance retrieval function upon a state shift within userInfo
. This isn’t required to useParticle Auth Core, but was included here for demonstration.
connect
. Although, within our corresponding handleLogin
function, we’ll be connecting to a specified social login provider (through authType
/ socialType
) on the condition that userInfo
is not populated, indicating that the user has not been logged in. This is shown in the snippet below.
customProvider
(with SendTransactionMode.Gasless
), it’ll be sponsored. The executeUserOp
function in this example will be quite standard, including retrieval of the signer object with ethers (customProvider.getSigner
), then the construction and execution of a small transaction object, following the same structure as any typical EOA transaction.
SimpleAccount
implementation, then executed a gasless transaction. Thus, your App.tsx
file should look something like this snippet:
https://bundler.particle.network
(or natively through Particle’s AA SDK), supporting every standard ERC-4337 Bundler method, such as eth_sendUserOperation
, eth_estimateUserOperationGas
, eth_getUserOperationByHash
, etc. For a complete list of supported methods, the parameters they take, and some query examples, head over to the Particle Bundler RPC reference.
Additionally, take a look at the open-source repository for the Particle Bundler, found at https://github.com/Particle-Network/particle-bundler-server.
true
or false
value based upon whether or not a given UserOperation should be sponsored.
Using the Particle Omnichain Paymaster can be done either through the Particle AA SDK, in which the Paymaster is set by default or, alternatively, you can use its associated RPC, https://paymaster.particle.network. This RPC supports two methods, pm_paymasterBalance
and pm_sponsorUserOperation
.
Learn more about working with Particle Network’s Paymaster.
SmartAccount
). This can facilitate the same simple, 5-line smart account setup and initialization process, with interaction happening either directly with SmartAccount
or through a custom Ethers/Web3.js/viem object.
By default, Particle’s AA SDK uses the Particle Bundler and the Particle Omnichain Paymaster, although, through a fundamental focus on modularity, you can also either plug in a Biconomy Paymaster (through the SmartAccount
configuration) or use any other Bundler/Paymaster pair independently, just leaving the account management and UserOperation construction to @particle-network/aa
, handling sponsorship and execution externally.
To learn more about using Particle Network’s AA SDK, head over to the AA quickstart guide.