Modular Swift wallet adapters and components for EVM & Solana chains. Manage wallet and custom RPC request.
It is strongly discouraged to use private key or mnemonic import/generate function, if you use it, you need to secure the data yourself, Particle's SDK has no relationship with the imported/generated mnemonic or private key.
Quick Start
Add Connect Service to Your iOS Project
Prerequisites
Install the following:
Xcode 14.1 or later
CocoaPods 1.12.1 or higher
Make sure that your project meets the following requirements:
Your project must target these platform versions or later:
iOS 14
Create a Particle Project and App
Before you can add our Connect Service to your iOS app, you need to create a Particle project to connect to your iOS app. Visit Particle Dashboard to learn more about Particle projects and apps.
Connect Service supports installation with CocoaPods.
Here's how to install the Auth Service using CocoaPods:
Create a Podfile if you don't already have one. From the root of your project directory, run the following command:
pod init
2. To your Podfile, add the Auth Service pods that you want to use in your app:
pod 'ConnectCommon'pod 'ParticleConnect'pod 'ConnectWalletConnectAdapter'pod 'ConnectEVMAdapter'pod 'ConnectSolanaAdapter'pod 'ConnectPhantomAdapter'pod 'ParticleAuthAdapter'# if you are using Auth Core Service, don't forget to add AuthCoreAdapter
3. Install the pods, then open your .xcworkspace file to see the project in Xcode:
pod install --repo-update
open your-project.xcworkspace
If you would like to receive release updates, subscribe to our GitHub repository.
Edit Podfile
It is required for every iOS project that integrates the Auth Service SDK.
// paste there code into pod filepost_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
Initialize Connect Service in your app
The final step is to add an initialization code to your application. You may have already done this as part of adding the Connect Service to your app. If you are using a quickstart sample project, this has been done for you.
Create a ParticleNetwork-Info.plist into the root of your Xcode project
3. Replace YOUR_PROJECT_UUID, YOUR_PROJECT_CLIENT_KEY, and YOUR_PROJECT_APP_UUID with the new values created in your Dashboard
4. Import the ParticleNetwork module in your UIApplicationDelegate
importConnectCommonimportConnectEVMAdapterimportConnectPhantomAdapterimportConnectSolanaAdapterimportConnectWalletConnectAdapterimportParticleNetworkBaseimportParticleConnectimportParticleAuthAdapter// if you are using ParticleAuthCore// import AuthCoreAdapter
5. Initialize the ParticleNetwork service, which is typically in your app's application:didFinishLaunchingWithOptions: method:
// initialize method// you can modify the adapters, remove the one you dont need.var adapters: [ ParticleAuthAdapter(), WalletConnectAdapter(), MetaMaskConnectAdapter(), PhantomConnectAdapter(), EVMConnectAdapter(), SolanaConnectAdapter(), ImtokenConnectAdapter(), BitkeepConnectAdapter(), RainbowConnectAdapter(), TrustConnectAdapter()// if you are using ParticleAuthCore// AuthCoreAdaper() ]let moreAdapterClasses: [WalletConnectAdapter.Type] = [ZerionConnectAdapter.self, MathConnectAdapter.self, OmniConnectAdapter.self, Inch1ConnectAdapter.self, ZengoConnectAdapter.self, AlphaConnectAdapter.self, OKXConnectAdapter.self]adapters.append(contentsOf: moreAdapterClasses.map { $0.init()})ParticleConnect.initialize(env: .debug, chainInfo: .ethereum, dAppData: DAppMetaData(name:"Particle Connect", icon: URL(string:"https://connect.particle.network/icons/512.png")!, url: URL(string:"https://connect.particle.network")!)) { adapters}
Migrating to WalletConnect v2
Starting from version 0.2.0, WalletConnectV2 is supported.
// WalletConnect 2.0 required, set wallet connect v2 project idParticleConnect.setWalletConnectV2ProjectId("your wallet connect v2.0 project id")// Set the required chains for WalletConnect v2. If not set, the current chain will be used.ParticleConnect.setWalletConnectV2SupportChainInfos([.ethereum, .ethereumGoerli])
6. Add the scheme URL handle in your app's application(_:open:options:) method
return ParticleConnect.handleUrl(url)
7. Configure your app scheme URL, select your app target in the info section, click to add the URL type, and pass your scheme in URL Schemes
Your scheme URL should be "pn" + your project app uuid.
For example, if your project app id is "63bfa427-cf5f-4742-9ff1-e8f5a1b9828f", your scheme URL is "pn63bfa427-cf5f-4742-9ff1-e8f5a1b9828f".
8. Add LSApplicationQueriesSchemes to info.plist.
each of them is optional, you can add which you want.
Account Abstraction could use together with Connect Service, explore Account Abstraction for more detail, learn how to get a smart account address, how to send transaction under AA mode.
Wallet Service could use together with Connect Service, explore Wallet Service for more detail, learn how to open wallet page, how to open send page, how to open swap page etc.
call this method to check if the public address is connected.
After user connects with a third party wallet, user can remove the wallet connect's session in the third party wallet, when receive disconnect request, local session cache should be removed.
It is better to call reconnectIfNeeded when start app.
before sign or open GUI page, check the method isConnected, if result is disconnected, you need to connect again.
let publicAddress =getSender()let result = adapter.isConnected(publicAddress: publicAddress)if result {print("publicAddress \(publicAddress) is connected")} else {print("publicAddress \(publicAddress) is disconnected")}
Reconnect if needed
// Wallet Connect Adapter need reconnect after app launch// other sub adapter as MetaMaskConnectAdapter, RainConnectAdaper ... also need reconnect after app launch // call reconnectIfNeeded after app launch, or before call other sign methods.(adapter as? WalletConnectAdapter)?.reconnectIfNeeded(publicAddress: getSender())
Check whether the account is connected.
let result = connectAdapter.isConnected(address)
Import wallet.
Only EVMConnectAdapter and SolanaConnectAdapter support this method.
// import wallet with private keyconnectAdapter.importWalletFromPrivateKey(privateKey).subscribe { [weak self] result inguardlet self = self else { return }switch result {case .failure(let error):print(error)case .success(let account):print(account) }}.disposed(by: bag)// import wallet with mnemonic (Split with space).connectAdapter.importWalletFromMnemonic(mnemonic).subscribe { [weak self] result inguardlet self = self else { return }switch result {case .failure(let error):print(error)case .success(let account):print(account) }}.disposed(by: bag)
Export wallet.
Only EVMConnectAdapter and SolanaConnectAdapter support this method.
/// How to define a custom wallet connect adapter/// for examle coin98 wallet/// 1. subclass from WalletConnectAdapter/// 2. override walletType, provide a AdapterInfo object/// don't use teh same redirectUrlHost with other connect adapters/// if the app has a universal link, like metamask's is "https://metamask.app.link/"/// set it to deeplink/// if the app doesn't have a universal link, set scheme as the deeplink/// if the app has neither universal link nor scheme,/// it is not ready for wallet connect.publicclassCoin98WalletConnectAdapter:WalletConnectAdapter {publicoverridevar walletType: WalletType {return WalletType.custom(info: AdapterInfo.init(name:"Coin98", url:"https://coin98.com/", icon:"https://registry.walletconnect.com/v2/logo/md/dee547be-936a-4c92-9e3f-7a2350a62e00", redirectUrlHost:"coin98", supportChains: [.evm], deepLink:"coin98://", scheme:"coin98://")) }}