Requirements
- iOS 13.0+
- Swift 5.7+
- Xcode 14.0+
- WalletKit (ReownWalletKit)
Installation
Swift Package Manager
Add ReownWalletKit to yourPackage.swift:
ReownWalletKit to your target dependencies:
Check the GitHub releases for the latest version.
Configuration
When using WalletKit, Pay is automatically configured using your project’sNetworking.projectId. No separate configuration is needed.
Payment Link Detection
Use the staticisPaymentLink method to detect payment links before processing:
isPaymentLink utility method detects WalletConnect Pay links by checking for:
pay.hosts (e.g., pay.walletconnect.com)pay=parameter in WalletConnect URIspay_prefix in bare payment IDs
Payment Flow
The payment flow consists of five main steps: Detect Payment Link -> Get Options -> Get Actions -> Sign Actions -> Confirm Payment1
Get Payment Options
When a user scans a payment QR code or opens a payment link, fetch available payment options:
2
Get Required Actions
After the user selects a payment option, get the signing actions:
3
Sign Actions
Each action contains a
walletRpc with EIP-712 typed data that needs to be signed:Signing Implementation
4
Collect User Data (If Required)
If
options.collectData is not nil, you must collect user information before confirming:5
Confirm Payment
Submit the signatures and collected data to complete the payment:
Complete Example
Here’s a complete implementation using WalletKit:Deep Link Handling
To handle payment links opened from outside your app:QR Code Scanning
Payment links can be encoded as QR codes. Use theisPaymentLink utility for detection:
API Reference
WalletKit Integration
When using WalletKit, Pay methods are accessed viaWalletKit.instance.Pay.*.
Static Methods
| Method | Description |
|---|---|
WalletKit.isPaymentLink(_:) | Check if a string is a payment link (can call before configure()) |
Instance Methods (WalletKit.instance.Pay)
| Method | Description |
|---|---|
isPaymentLink(_:) | Check if a string is a payment link |
getPaymentOptions(paymentLink:accounts:includePaymentInfo:) | Fetch available payment options |
getRequiredPaymentActions(paymentId:optionId:) | Get signing actions for a payment option |
confirmPayment(paymentId:optionId:signatures:collectedData:maxPollMs:) | Confirm and execute the payment |
Data Types
PaymentOptionsResponse
PaymentInfo
PaymentOption
PayAmount
Action & WalletRpcAction
PaymentStatus
Error Handling
The SDK throws specific error types for different failure scenarios:GetPaymentOptionsError
| Error | Description |
|---|---|
.paymentNotFound | Payment ID doesn’t exist |
.paymentExpired | Payment has expired |
.invalidRequest | Invalid request parameters |
.invalidAccount | Invalid account format |
.complianceFailed | Compliance check failed |
.http | Network error |
.internalError | Server error |
GetPaymentRequestError
| Error | Description |
|---|---|
.optionNotFound | Selected option doesn’t exist |
.paymentNotFound | Payment ID doesn’t exist |
.invalidAccount | Invalid account format |
.http | Network error |
ConfirmPaymentError
| Error | Description |
|---|---|
.paymentNotFound | Payment ID doesn’t exist |
.paymentExpired | Payment has expired |
.invalidOption | Invalid option ID |
.invalidSignature | Signature verification failed |
.routeExpired | Payment route expired |
.http | Network error |
Best Practices
-
Use WalletKit Integration: If your wallet already uses WalletKit, prefer the
WalletKit.instance.Pay.*access pattern for automatic configuration -
Use
isPaymentLink()for Detection: Use the utility method instead of manual URL parsing for reliable payment link detection -
Account Format: Always use CAIP-10 format for accounts:
eip155:{chainId}:{address} - Multiple Chains: Provide accounts for all supported chains to maximize payment options
- Signature Order: Maintain the same order of signatures as the actions array
- Error Handling: Always handle errors gracefully and show appropriate user feedback
- Loading States: Show loading indicators during API calls and signing operations
-
Expiration: Check
paymentInfo.expiresAtand warn users if time is running low -
User Data: Only collect data when
collectDatais present in the response