This guide will help you get started with Particle Connect iOS SDK by setting up your environment, creating a wallet with social account, and sending a EVM transaction. 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 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 'ConnectCommon','0.2.16' pod 'ParticleConnect','0.2.16' pod 'ParticleAuthAdapter','0.2.16'# The following SDKs are optional.# ConnectWalletConnectAdapter is WalletConnect SDK, support EVM. pod 'ConnectWalletConnectAdapter','0.2.16'# ConnectEVMAdapter is EVM private SDK. pod 'ConnectEVMAdapter','0.2.16'# ConnectSolanaAdapter is Solana Private SDK. pod 'ConnectSolanaAdapter','0.2.16'# ConnectPhantomAdapter is Phantom Wallet SDK, support Solana. pod 'ConnectPhantomAdapter','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.
importConnectCommonimportConnectEVMAdapterimportConnectSolanaAdapterimportConnectPhantomAdapterimportConnectWalletConnectAdapterimportParticleConnectimportParticleAuthAdapterimportUIKit// if you want to use auth core service// import AuthCoreAdapter@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] = [ParticleAuthAdapter(),MetaMaskConnectAdapter(),PhantomConnectAdapter(),WalletConnectAdapter(),RainbowConnectAdapter(),BitkeepConnectAdapter(),ImtokenConnectAdapter(),TrustConnectAdapter(),ZerionConnectAdapter(),MathConnectAdapter(),OmniConnectAdapter(),Inch1ConnectAdapter(),ZengoConnectAdapter(),AlphaConnectAdapter(),OKXConnectAdapter(), SolanaConnectAdapter(),EVMConnectAdapter()// if you want to use auth core service// add AuthCoreAdapter() ] ParticleConnect.initialize(env: .debug, chainInfo: .polygon(.mumbai)) { adapters } ParticleConnect.setWalletConnectV2ProjectId("75ac08814504606fc06126541ace9df6")// 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) }}
If you don't want to support private key connect and wallet connect, you can remove their pods in Podfile, then remove their adapters when initializing, keep ParticleAuthAdapter or AuthCoreAdapter
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.
// 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)case .failure(let error):print(error) } }.disposed(by: self.bag)}
Triggering the sign
After connect, if you want to authenticate by signature call signMessage.
In this guide, we learned how to use the Particle Connect iOS SDK for social login, sending transactions, and signing message. If you want to learn more about different use cases, check out the Particle Connect page.