This guide will help you get started with Particle Connect and Particle AA iOS SDK by setting up your environment, creating a wallet with social account, and sending a User Operation from it. By the end of this guide, you'll have a basic understanding of how to use the SDK and where to look for more advanced user cases.
If you face any problem anytime, you can always refer to the ParticleCommunity for us to help you out as soon as possible!
Install ParticleConnectService and ParticleAA SDK using Cocoapods.
platform :ios,'14.0'source 'https://github.com/CocoaPods/Specs.git'target 'ParticleExample'do# Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'ParticleNetworkBase','1.3.10' pod 'ParticleAuthService','1.3.10' pod 'ParticleWalletAPI','1.3.10' pod 'ParticleAA','1.3.10' pod 'ConnectCommon','0.2.16' pod 'ConnectEVMAdapter','0.2.16' pod 'ConnectSolanaAdapter','0.2.16' pod 'ConnectWalletConnectAdapter','0.2.16' pod 'ConnectPhantomAdapter','0.2.16' pod 'ParticleConnect','0.2.16' pod 'ParticleAuthAdapter','0.2.16'endpost_install do|installer| installer.pods_project.targets.each do|target| target.build_configurations.each do|config| config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] ='YES'endendend
Register your application
In order to use ParticleConnectService, you'll need to create a project in the Particle Dashboard and get your project id, client key and project app id.
Create a ParticleNetwork-Info.plist into the root of your Xcode project, Copy the following text into this file, then replace YOUR_PROJECT_UUID, YOUR_PROJECT_CLIENT_KEY, and YOUR_PROJECT_APP_UUID with the new values created in your Dashboard.
Next step is set your scheme, select your app from TARGETS in Xcode, go to the "Info" section and click on the '+' button to add a new entry to the "URL types" field, under "URL Schemes", paste your specific scheme information.
Your scheme URL should be "pn" followed by your project app id.
For instance, if your project app id is "63bfa427-cf5f-4742-9ff1-e8f5a1b9828f", your scheme URL should be "pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f".
Now, let's initialize ParticleConnectService in your project, chainInfo signifies the chain (ethereum, polygon ...) you want to initialize ParticleConnectService with.
importConnectCommonimportConnectPhantomAdapterimportConnectWalletConnectAdapterimportParticleAAimportParticleAuthAdapterimportParticleConnectimportParticleNetworkBaseimportUIKit@mainclassAppDelegate:UIResponder, UIApplicationDelegate {var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.particleInit()returntrue }funcparticleInit() {let adapters: [ConnectAdapter] = [MetaMaskConnectAdapter(),ParticleAuthAdapter(),PhantomConnectAdapter(),WalletConnectAdapter(),RainbowConnectAdapter(),BitkeepConnectAdapter(),ImtokenConnectAdapter(),TrustConnectAdapter(),ZerionConnectAdapter(),MathConnectAdapter(),OmniConnectAdapter(),Inch1ConnectAdapter(),ZengoConnectAdapter(),AlphaConnectAdapter(),OKXConnectAdapter(), ] ParticleConnect.initialize(env: .debug, chainInfo: .polygon(.mumbai)) { adapters } ParticleConnect.setWalletConnectV2ProjectId("your wallet connect project id")// set your biconomy api keyslet biconomyApiKeys = [80001:"your biconomy api key"]// We support biconomy v1 | biconomy v2 | cyberConnect | simple AAService.initialize(name: AA.AccountName.biconomyV1, biconomyApiKeys: biconomyApiKeys)let aaService =AAService() ParticleNetwork.setAAService(aaService) aaService.enableAAMode()// Set wallet connect chains,// Note metamask only support one chain for each connection.// ParticleConnect.setWalletConnectV2SupportChainInfos([.ethereum, .ethereumGoerli, .polygon, .polygonMumbai]) } func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return ParticleConnect.handleUrl(url) }}
All here, initialization is complete.
Triggering the login
Trigger login flow with email, phone number, google, facebook, twitter, JWT, etc.
Retrieve the adapter with the type 'particle' from all the adapters you have registered so far, call connect with a parameter ParticleAuthConfig.
You need to save the returned Account object for convenient use next time.
Due to initialize AA service before, you can get a smart account address from account object.
// After connect a particle accountParticleAuthService.getUserInfo()?.signature// also you can get token from userInfo.
Particle Connect iOS SDK also support connect with other wallets, here is an example show how to connect with MetaMask wallet, other wallets are in the same way.
@IBActionfuncconnectMetaMask() {let adapter = ParticleConnect.getAllAdapters().filter {// specify the wallet that you want. $0.walletType == .metaMask }.first! adapter.connect(ConnectConfig.none).subscribe { [weak self] result inguardlet self = self else { return }switch result {case .success(let account): self.account = accountprint(account)print(account?.smartAccount?.smartAccountAddress)case .failure(let error):print(error) } }.disposed(by: self.bag)}
Triggering the sign
After connect, if you want to send a EVM transaction, call signAndSendTransaction.
You can create a transaction by ParticleWalletAPI.getEvmService().createTransaction method.
@IBActionfuncsendTransaciton() {guardlet account = self.account else {print("you didn't connect any account")return }guardlet smartAccountAddress = account.smartAccount?.smartAccountAddress else {print("you didn't get a smart account address")return }let adapter = ParticleConnect.getAllAdapters().filter { $0.walletType == account.walletType }.first!let publicAddress = account.publicAddresslet receiverAddress ="0x0000000000000000000000000000000000000000"// the smallest unitlet amount =BInt(10000000000000).toHexString() ParticleWalletAPI.getEvmService().createTransaction(from: smartAccountAddress, to: receiverAddress, value: amount, data: "0x", gasFeeLevel: .high).flatMap { transaction in
adapter.signAndSendTransaction(publicAddress: publicAddress, transaction: transaction, feeMode: .native, chainInfo: ParticleNetwork.getChainInfo())
}.subscribe { result inswitch result {case .success(let signature):print(signature)case .failure(let error):print(error) } }.disposed(by: self.bag)}
Note the parameter feeMode in signAndSendTransaction method, it has three options, native, gasless and token, just as its name implies, it means how to pay gas fee.
Now I will show you how to pay token as gas fee.
Use aaService.rpcGetFeeQuotes get the wholeFeeQuote for your transactions, then find a available token to pay.
In this guide, we learned how to use the Particle Connect iOS SDK for social login, sending User Operation. If you want to learn more about different use cases, check out the Account Abstraction page.