@particle-network/auth-core-modal
, and Particle’s AA SDK, @particle-network/aa
. This application will replicate the functionality found within the embedded demo above, highlighting the process of:
@particle-network/auth-core-modal
, the central SDK for implementing Particle Auth Core.@particle-network/aa
, to assign a SimpleAccount and generate a custom AA-enabled EIP-1193 provider object to control the smart account with Ethers.@particle-network/chains
, for configuring Particle Auth Core with an object containing Berachain-specific information, (BerachainArtio
).AuthCoreContextProvider
(imported from @particle-network/auth-core-modal
), an object used within your index
file to wrap your primary App
component (or its equivalent). This contains key values authenticating your instance of Particle Auth and enabling core customization of the social login or embedded wallet modals.
Before constructing AuthCoreContextProvider
, you’ll need three values to initialize Particle Auth Core. When configuring any SDK from Particle Network, whether it’s Particle Auth Core, Particle Connect, or Particle’s AA SDK, you’ll need to retrieve a project ID, client key, and app ID from the Particle dashboard. These values link your application with your project on the Particle dashboard, therefore authenticating API requests, tracking users, allowing for no-code modal customization, etc.
With a project and application set up through the Particle dashboard, you’re ready to configure AuthCoreContextProvider
. This is done through the options
parameter, which takes the following values (in this example):
projectId
, clientKey
, and appId
. The aforementioned required values, found on the Particle dashboard.wallet
, an object for customizing the wallet modal containing:
visible
, a Boolean dictating whether or not the Particle Wallet modal is shown after login. Particle Wallet is an embedded interface used for controlling an account generated through social login.customStyle
, an object containing:
supportChains
, an array of chains for the Particle Wallet modal (if visible
is true
) will be locked to. In this case, we’re passing in BerachainArtio
, imported from @particle-network/chains
.erc4337
, to ensure that the modal formerly configured within wallet
shows the smart account you intend to be using, not the EOA. erc4337
contains:
name
, the name of the smart account you’d like to be displayed on the modal. In this example, and because it’s the only supported by Particle on Berachain, you can set this to 'SIMPLE'
.version
, the version of the smart account you intend on using. For SimpleAccount, this will be '1.0.0'
.AuthCoreContextProvider
takes various other optional parameters that can be used for further fine-tuning of the authentication or embedded wallet modal, such as themeType
, fiatCoin
, language
, promptSettingConfig
, authTypes
, etc.
At this point, your index
file should look similar to the example below:
AuthCoreContextProvider
has been configured and Particle Auth Core is initialized, you’re ready to move onto the implementation of your primary application component (in the example above, this was App
). Before you can begin executing transactions, you’ll need to first configure your smart account. In this setup, Particle Auth Core is used to initiate a social login and generate an EOA. Past that point, Particle’s AA SDK (@particle-network/aa
) is responsible for assigning and facilitating interaction with a smart account.
To do this, you’ll need to import a few objects from @particle-network/aa
, including:
SmartAccount
, the core object controlling the underlying smart account (this can be used either directly to construct and execute UserOperations, or within a custom Ethers object, as we’ll be doing here).AAWrapProvider
, for constructing the aforementioned custom Ethers object (which we’ll be using to execute transactions).SendTransactionMode
, used within AAWrapProvider
to determine the method in which fees will be paid. In this case, we’ll be using SendTransactionMode
to ensure transactions are gasless (sponsored).AAWrapProvider
. To set this up, we’ll first need to create an instance of SmartAccount
for configuring the smart account, passing in the following parameters:
provider
, the provider object provided by Particle Auth Core. This can be retrieved from the useEthereum
hook (imported from @particle-network/auth-core-modal
).projectId
, clientKey
, and appId
. The values you previously retrieved from the Particle dashboard for the authentication of AuthCoreContextProvider
.aaOptions
, which contains:
accountContracts
, which will be used for the initialization of various smart account implementations. In this case, only SimpleAccount is supported, so you’ll need to include:
SIMPLE
, an array of objects, with each taking:
chainIds
, BerachainArtio.id
in this case.version
, the version of the smart account you intend to use. Only '1.0.0'
is supported on SimpleAccount.SmartAccount
(smartAccount
in the example above) can then be used directly within AAWrapProvider
to construct an AA-enabled provider object to use within a new instance of ethers.providers.Web3Provider
(or if you’re using v6, ethers.BrowserProvider
).T his same structure can be applied to Web3.js or viem.
Alongside smartAccount
, we’ll also use SendTransactionMode.Gasless
within AAWrapProvider
, ensuring that transactions sent through this provider object will be subject to sponsorship if they pass the conditions we set within the Paymaster (although in this example there are none, so transactions will be sponsored indiscriminately).
Your custom Ethers provider should look like the following:
customProvider
in this case), you’ll be able to facilitate transactions, retrieve balances, message signatures, etc. through Particle. However, before being able to facilitate any of these, you’ll first need to facilitate social login.
Social login with Particle Auth Core is simple, directed by two functions derived from the useConnect
hook, connect
and disconnect
. Upon calling connect
, social login will immediately be initiated and the user will undergo the login process for the specified social login mechanism. Similarly for disconnect
, a user will be removed from their account upon calling.
For this example, we’ll wrap connect
within a function called handleLogin
, which will allow us to conditionally execute connect
, blocking any calls to handleLogin
if the user has already logged in. This condition can be set up by checking the truthy or falsy value of userInfo
, which can be defined through the useAuthCore
hook. Upon logging in, userInfo
will be populated, although beforehand it’ll remain undefined, allowing connect
to be called.
We’ll use the following parameters within connect
:
socialType
, a string dictating the specific authentication type to be used (such as ‘google’, ‘twitter’, etc.) (optional).chain
, the specific chain you’d like to connect to. This should be BerachainArtio
, an object imported from @particle-network/chains
.handleLogin
can be mapped to “Sign in with Google,” “Sign in with X,” and a miscellaneous button on the frontend by purely changing the string passed into socialType
on connect
. An example of this function has been included below:
connect
), transaction requests can be made directly to Particle through its embedded wallet. As mentioned, this will be done directly through methods on the aforementioned Ethers object (customProvider
here), which need no special configuration to work with Particle.
For the first transaction, we’ll be executing a gasless burn of 0.001 BERA, which essentially involves sending BERA to a dead address, often 0x000000000000000000000000000000000000dEaD
. We’ll be doing this through the signer
object retrieved from {your ethers object}.getSigner
, which has a sendTransaction
method. sendTransaction
takes a standard transaction object containing values such as:
to
, which in this case is 0x000000000000000000000000000000000000dEaD
.value
, 0.001 BERA, which needs to be converted to wei through ethers.utils.parseEther("0.001")
.data
.signer
directly, we’ll have to create a contract object for HONEY, on which we can call the transfer method. This can be done by simply initiating ethers.Contract
, passing in 0x7EeCA4205fF31f947EdBd49195a7A88E6A91161B
(the HONEY contract address on Berachain Artio), alongside the ABI. In this case, we’ll simply pass the method signature, function transfer(address to, uint256 amount)
. Finally, you can throw in the same signer
object used within the former transaction (retrieved through {your ethers object}.getSigner
).
🍯 If you don’t have HONEY, but would like some to test this function, Berachain has a native DEX that supports swapping BERA for HONEY.With this contract object constructed, you can call the
transfer
method, passing in (as the method signature suggests), the to
address (0x000000000000000000000000000000000000dEaD
for this example) and value
, which will be ethers.utils.parseEther('1')
here.
A transaction of this nature may look as follows:
visible
to true
within AuthCoreContextProvider
), many ERC-20 and ERC-721 tokens won’t be automatically picked up (including HONEY). If these aren’t automatically reflected within the modal, you’ll need to manually add the token through the plus icon near the list of balances.
So far, you’ve installed and configured Particle Auth Core (@particle-network/auth-core-modal
), constructed a custom Ethers provider object, initiated social login, and sent two burn transactions, one for 0.001 BERA, and another for 1 HONEY. Therefore, the example application built should look something like the following: