Flutter (Dart) - AA
Leveraging Particle’s AA SDK within applications built using Flutter.
Account Abstraction for Flutter
Particle Network’s AA SDK offers a mechanism for facilitating full-stack ERC-4337 account abstraction, leveraging built-in infrastructure modularity without compromising simplicity. Paired with Particle Auth or Particle Connect for seamless onboarding, the Particle Network AA SDK presents itself as a key method for building high-quality UX within applications built using Flutter.
Repository
All Particle Network Flutter SDKs, including the AA SDK for Flutter, are open-source in the particle-flutter
repository on GitHub, with each including demos/examples. It may be worthwhile taking a look at the AA Flutter SDK’s architecture and implementation flow before continuing to build some context.
Getting Started
Before jumping in, you’ll need to already have setup either Particle Auth or Particle Connect within your Flutter project (the AA SDK doesn’t work on its own, requiring one of the two to function). If you don’t have either of these already implemented, read through those pages and follow the outlined steps, then return to continue.
With either of these SDKs set up, you can move on to adding particle_aa
to your Flutter project through the following command:
Important details before initialization
Before initializing the SDK, there are a few points to keep in mind, specifically regarding the utilization of Paymasters (to sponsor gas fees, pay for gas in ERC-20 tokens, etc.)
- All Testnets automatically have the Verifying Particle Network Omnichain Verifying Paymaster enabled. Transactions requesting it will automatically be sponsored and thus gasless.
- On the occasion that you’d like to use the Particle Network Omnichain Verifying Paymaster for Mainnets, you’ll need to deposit USDT on either Ethereum or BNB Chain within the Particle dashboard. This USDT will then automatically be converted as needed into the native token of the network you’re requesting (and qualifying for) sponsorship on.
- The Particle Network AA SDK automatically uses Biconomy’s Token Paymaster; transactions that request it will be able to leverage it without additional configuration.
Initialization
The Particle Network AA SDK will fail to function correctly until it has been initialized. Initialization allows you to specify a smart account implementation and version, alongside the Paymaster you’d like to use. This can be initiated through ParticleAA.init
, which takes the following parameters:
name
, the smart account implementation to be used (any of these choices):AccountName.BICONOMY_V1
, a Biconomy smart account.AccountName.BICONOMY_V2
, a Biconomy smart account.AccountName.CYBERCONNECT
, a CyberConnect smart account.AccountName.SIMPLE_V1
, a SimpleAccount implementation.AccountName.SIMPLE_V2
, a SimpleAccount implementation.AccountName.LIGHT
, a Light Account implementation.
Once init
has been called, you can close off initialization by enabling AA mode with ParticleAA.enableAAMode
.
Examples of Utilization
Is Deployed
Now that you’ve initialized the AA SDK, you can move onto several methods to utilize it. First, it’s important to note that the smart account implementation you chose will be automatically deployed with the first transaction it initiates. The deployment transaction will be bundled (batched) in with the first transaction.
However, if you’d like to check the deployment status of a given smart account manually, you can first retrieve the host address with Evm.getAddress
, then pass that into ParticleAA.isDeploy
, which returns a Boolean indicating deployment status.
E.g.:
Disable AA Mode
If you’d like to exit AA mode and thus disable account abstraction functionality within your application, you’ll need to call ParticleAA.disableAAMode
. This will immediately render the usage of AA incompatible. Additionally, if you’re unsure whether or not AA mode is enabled, you can call ParticleAA.isAAModeEnable
, which will return a Boolean representing this status. E.g.:
Send Transaction
Sending a transaction (UserOperation) is as simple as calling pre-existing methods within ParticleConnect
or Evm
in particle_auth_core
and just passing in an additional parameter, feeMode
. There are two ways to send transactions with the AA SDK: The first is with signAndSendTransaction
of sendTransaction
, which will send a singular transaction to the network. Alternatively, you can use batchSendTransactions
to send batched transactions within a single UserOperation.
ParticleConnect.signAndSendTransaction
or Evm.sendTransaction
in particle_auth_core
takes the following parameters:
- For Particle Connect,
walletType
, dictates the specific adapter being used/targeted. account
, the public address of the smart account sending the transaction, which can be retrieved throughEvmService.getSmartAccount
.transaction
, a stringified standard transaction object.feeMode
, the mechanism to be used for paying gas fees, can be:AAFeeMode.gasless
, for sponsored transactions. This will happen automatically for Testnets and will pull from your previously defined (or configured) Paymaster for Mainnets. Takes one parameter:wholeFeeQuote
, which can be retrieved throughParticleAA.rpcGetFeeQuotes
.
AAFeeMode.native
, paying for gas fees in a native token (such as ETH). Takes one parameter:wholeFeeQuote
, which can be retrieved throughParticleAA.rpcGetFeeQuotes
.
AAFeeMode.token
, paying for gas fees in an ERC-20 token (such as USDC). Takes one parameter:feeQuote
, to be used when leveraging a Token Paymaster. It can be retrieved throughParticleAA.rpcGetFeeQuotes
.tokenPaymasterAddress
, which can be retrieved throughParticleAA.rpcGetFeeQuotes
.
Alternatively, for ParticleConnect.batchSendTransactions
or ParticleAuthCore Evm.batchSendTransactions
, the parameters will be the same, with the exception of transaction
being an array of transactions.
Check if you can send with AAFeeMode.gasless/native/token.
See the Particle Auth and Particle Connect pages for insights into additional compatible methods (such as signAndSendTransaction
), as shown here.
Was this page helpful?