iOS (Swift) - AA
Leveraging Particle’s AA SDK within iOS applications.
Account Abstraction for iOS
Particle Network’s AA SDK, existing at the center of its Smart Wallet-as-a-Service, facilitates flexible end-to-end utilization of ERC-4337 account abstraction, natively supporting modular smart account implementations, Paymasters, and natural Bundler usage. Within iOS applications, the Particle Network AA SDK can be used (in tandem with Particle Auth or Particle Connect) to refine user experience through account abstraction.
Details on configuration, initialization, and utilization are listed below.
Getting Started
To get started, you’ll need to have already integrated either Particle Connect or Particle Auth within your iOS application. If you haven’t, head over to those pages, follow the configuration process, and return here. Otherwise, you can begin by including ParticleAA
within your Podfile, as shown below:
This new addition to your Podfile can then be settled and installed by running the command below:
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
To begin, before using the SDK, you’ll need to initialize it; without this, the setAAService
within ParticleNetwork
will fail or raise issues down the line.
You can initialize the SDK through AAService.initialize
, which requires the following parameters:
name
, the name of the smart account implementation to be used, the choices here are:.biconomyV1
, a Biconomy smart account..biconomyV2
, a Biconomy smart account..cyberConnect
, a CyberConnect smart account..simpleV1
, a SimpleAccount implementation..simpleV2
, a SimpleAccount implementation..light
, a Light Account.
Once AAService.initialize
has been called, you’ll need to use ParticleNetwork.setAAService
, passing in an instance of AAService
. This will tell Particle Auth to use your smart account rather than your EOA. Either before or after doing this, you’ll also need to call aaService.enableAAMode
.
Examples of Utilization
Disable AA Mode
If you’d like to disable AA mode (stop using account abstraction) after enabling it during the initialization process (through enableAAMode
), then you’ll need to call aaService.disableAAMode
, with aaService
being an instance of AAService
.
However, if you aren’t sure whether AA mode is enabled or not, you can call aaService.isAAModeEnable
, which returns a Boolean representing this status.
E.g.:
Get Smart Account
You can also retrieve the address of the smart account, among other details, by calling the getSmartAccount
method on aaService
(which can be defined by ParticleNetwork.getAAService
if needed), in which you can pass by
(your Signer/owner address, which should be an EOA), and chainInfo
, which should be a ChainInfo
object representing the chain on which you’re querying account information. E.g.:
Field | Type | Description |
---|---|---|
publicAddress | String | EOA address. |
chainInfo | ChainInfo? | (Optional) default is current chainInfo. |
Send Transaction
Sending a transaction (UserOperation) is also quite simple, primarily just deviating in the fee mechanism being used for it. There are three ways to send transactions with the AA SDK:
The auth.evm.sendTransaction
method, defined in ParticleAuthCore
, is used to send a single transaction to the network.
The adapter.signAndSendTransaction
method, defined in ConnectAdapter
, is used to send a single transaction to the network.
The aaService.quickSendTransactions
method, defined in ParticleAA
, is used to send batched transactions within a single UserOperation.
auth.evm.sendTransaction
takes the following parameters:
transaction
, a stringified standard transaction object.feeMode
, the mechanism to be used for paying gas fees, can be:.gasless
, for sponsored transactions; this will happen automatically for Testnets, and will pull from your previously defined (or configured) Paymaster for Mainnets..native
, paying for gas fees in a native token (such as ETH)..token
, paying for gas fees in an ERC-20 token (such as USDC), and thus takes one parameter:feeQuote
, to be used when leveraging a Token Paymaster.
- Optionally,
chainInfo
: aChainInfo
object representing the chain on which this transaction will be executed.
adapter.signAndSendTransaction
takes the following parameters:
publicAddress
, the connected public address, ifadapter.WalletType
is.authCore
, you can pass an empty string, for other walletTypes, you need pass a connected public address.transaction
, a stringified standard transaction object.feeMode
, the mechanism to be used for paying gas fees, can be:.gasless
, for sponsored transactions; this will happen automatically for Testnets, and will pull from your previously defined (or configured) Paymaster for Mainnets..native
, paying for gas fees in a native token (such as ETH)..token
, paying for gas fees in an ERC-20 token (such as USDC), and thus takes one parameter:feeQuote
, to be used when leveraging a Token Paymaster.
- Optionally,
chainInfo
: aChainInfo
object representing the chain on which this transaction will be executed.
Alternatively, for aaService.quickSendTransactions
, the parameters will be the same with the following exceptions:
transactions
being an array of transactions.feeMode
is same with upon.messageSigner
, which is the Signer/owner authenticating the transaction.wholeFeeQuote
, which for eachfeeMode
should be passed with a complete fee quote object.- Optionally,
chainInfo
is same with upon.
E.g.:
Implement MessageSigner protocol
Check if you can send gasless/native/token.
Manually Deploy Smart Account
An undeployed smart account will automatically be deployed upon the first transaction (UserOperation) it sends through the SDK (the deployment transaction is bundled/batched with the other). If you’d like to initiate deployment manually, bypassing automatic deployment, then you can use aaService.deployWalletContract
, which will create, request signature for, and send a deployment transaction. This method requires messageSigner
(the Signer of the transaction), and the feeMode
of the deployment transaction.
The status of deployment can be retrieved with smartAccount.isDeploy
, which takes an owner/Signer eoaAddress
.
E.g.:
Was this page helpful?