WalletConnect Pay via WalletKit - Flutter
Integrate WalletConnect Pay through WalletKit for a unified payment experience in your Flutter wallet.
This documentation covers integrating WalletConnect Pay through ReownWalletKit. This approach provides a unified API where Pay is automatically initialized alongside WalletKit, simplifying the integration for wallet developers.
Sample Wallet
For a complete working example, check out our sample wallet implementation:
Sample Wallet - Flutter (WalletKit)
A reference Flutter wallet app demonstrating WalletConnect Pay via WalletKit.
Using AI for Integration? If you're using an AI IDE or assistant to help with integration, you can provide it with our comprehensive AI integration prompt for better context and guidance.
Requirements
- Flutter 3.0+
- iOS 13.0+
- Android API 23+
- ReownWalletKit (
reown_walletkit) 1.5.1 or later (bundleswalletconnect_pay1.1.0)
You also need a WCP ID for your project, obtained from the WalletConnect Dashboard.
How to obtain a WCP ID
- Navigate to the WalletConnect Dashboard.
- Select the project that is associated with your wallet (as in, the projectId that is being used for your wallet's WalletConnect integration).
- Click on the "Get Started" button to get a WCP ID associated with your project.
- The Dashboard will now show the WCP ID associated with your project.
- Click on the three dots on the right of the WCP ID and select "Copy WCP ID". You will be using this for your wallet's WalletConnect Pay integration.
Installation
Add reown_walletkit to your pubspec.yaml:
dependencies:
reown_walletkit: ^1.5.1Then run:
flutter pub getWalletConnectPay is automatically included as a dependency of ReownWalletKit.
Check the pub.dev page for the latest version.
Initialization
The WalletConnectPay client is automatically initialized during ReownWalletKit.init(). No additional setup is required.
import 'package:reown_walletkit/reown_walletkit.dart';
final walletKit = await ReownWalletKit.createInstance(
projectId: 'YOUR_PROJECT_ID',
metadata: PairingMetadata(
name: 'My Wallet',
description: 'My Wallet App',
url: 'https://mywallet.com',
icons: ['https://mywallet.com/icon.png'],
),
);Access the WalletConnectPay client directly via walletKit.pay:
final payClient = walletKit.pay;Payment Link Detection
Detect if a URI is a payment link before processing:
if (walletKit.isPaymentLink(uri)) {
// Handle as payment. See [Get Payment Options] section
} else {
// Handle as regular WalletConnect pairing
await walletKit.pair(uri: Uri.parse(uri));
}Payment Flow
The payment flow consists of six main steps:
Detect Payment Link -> Get Options -> Collect Data (if required) -> Get Actions -> Sign Actions -> Confirm Payment
Get Payment Options
Retrieve available payment options for a payment link:
final response = await walletKit.getPaymentOptions(
request: GetPaymentOptionsRequest(
paymentLink: 'https://pay.walletconnect.com/pay_123',
accounts: ['eip155:1:0x...', 'eip155:137:0x...'], // Wallet's CAIP-10 accounts
includePaymentInfo: true,
),
);
print('Payment ID: ${response.paymentId}');
print('Options available: ${response.options.length}');
if (response.info != null) {
print('Amount: ${response.info!.amount.formatAmount()}');
print('Merchant: ${response.info!.merchant.name}');
}
// Check which options require data collection (per-option)
for (final option in response.options) {
if (option.collectData != null) {
print('Option ${option.id} requires info capture');
}
}Collect User Data (If Required)
After the user selects an option, check for collectData on it. If present, collect the data before fetching the required actions.
Embedded Data Collection Form
When a payment requires user information (e.g., for Travel Rule compliance), the SDK returns a collectData field on individual payment options. Each option may independently require data collection — some options may require it while others don't.
The form is loaded from selectedOption.collectData.url and embedded in your wallet (a WebView on mobile, an iframe on web). It handles field rendering, validation, Terms & Conditions and Privacy Policy acceptance, and submits data directly to the backend.
Collect this data before fetching the required actions. For an option that requires Information Capture, getRequiredPaymentActions fails with 400 IC data required until the data has been submitted.
Recommended Flow
The recommended approach is to display all payment options upfront, then handle data collection only when the user selects an option that requires it:
- Call
getPaymentOptionsand display all available options to the user - Show a visual indicator (e.g., "Info required" badge) on options where
option.collectDatais present - When the user selects an option, check
selectedOption.collectData - If present, load
selectedOption.collectData.urlin the embedded form - Optionally append query parameters to the form URL —
prefill(known user data),theme, andthemeVariables(appearance). See Form URL parameters below. Use proper URL building so existing query parameters are preserved. - Listen for completion messages:
IC_COMPLETE(success) orIC_ERROR(failure) - On
IC_COMPLETE, continue the flow — fetch the required actions, sign, and confirm the payment. Don't passcollectedDatatoconfirmPayment(); the form submits data directly to the backend
Decision Matrix
Response collectData | option.collectData | Behavior |
|---|---|---|
| present | present | Option requires IC — use option.collectData.url |
| present | null | Option does NOT require IC (others might) — skip IC for this option |
null | null | No IC needed for any option |
Form URL parameters
The form URL accepts the following optional query parameters. Append them to selectedOption.collectData.url before loading it, preserving any existing query parameters.
| Parameter | Format | Description |
|---|---|---|
prefill | base64url-encoded JSON | Pre-populates known user fields so the user doesn't re-enter them. Keys must match the required fields from collectData.schema (e.g. fullName, dob, pobAddress). |
theme | light or dark | Sets the form's base color mode. |
themeVariables | base64url-encoded JSON | Overrides design tokens to match your brand — font, font size, select colors, button border radius, and input border radius. Generate and export this value from the WalletConnect Pay Dashboard. |
collectData.schema is a JSON schema string — parse it and read its required array to discover the field keys for prefill. For example, a required array of ["fullName", "dob", "pobAddress"] maps to a prefill object of {"fullName": "...", "dob": "...", "pobAddress": "..."}.
Customizing the form appearance
theme and themeVariables are optional and independent — pass either, both, or neither:
themeswitches the form betweenlightanddarkbase color modes. Match it to your wallet's active mode for a seamless transition.themeVariablesapplies brand-level overrides (font, font size, select colors, button border radius, and input border radius). Generate the theme in the WalletConnect Pay Dashboard, export it as a base64url string, and append it to the form URL verbatim — you don't need to encode it at runtime.
The top-level collectData on the payment options response is still available for backward compatibility. However, the per-option collectData is the recommended approach as it provides more granular control over the flow.
Do not pass collectedData to confirmPayment() when using the embedded form. The form handles data submission directly.
if (selectedOption.collectData?.url != null) {
// Use the "required" list from selectedOption.collectData.schema to determine which fields to prefill
final prefillData = {
'fullName': 'John Doe',
'dob': '1990-01-15',
'pobAddress': '123 Main St, New York, NY 10001',
};
// Encode prefill as base64url (no padding, consistent with the other SDKs)
final prefillBase64 = base64Url.encode(utf8.encode(jsonEncode(prefillData))).replaceAll('=', '');
final uri = Uri.parse(selectedOption.collectData!.url);
final webViewUrl = uri.replace(
queryParameters: {
...uri.queryParameters,
'prefill': prefillBase64,
// Optional appearance params (see "Form URL parameters"):
'theme': 'dark', // "light" | "dark"
// themeVariables is a base64url string exported from the Pay Dashboard:
// 'themeVariables': themeVariables,
},
).toString();
// Show WebView and wait for IC_COMPLETE message
showDataCollectionWebView(webViewUrl);
}WebView Message Types
The WebView communicates with your wallet through JavaScript bridge messages. The message payload is a JSON string with the following structure:
| Message Type | Payload | Description |
|---|---|---|
IC_COMPLETE | { "type": "IC_COMPLETE", "success": true } | User completed the form successfully. Proceed to payment confirmation. |
IC_ERROR | { "type": "IC_ERROR", "error": "..." } | An error occurred. Display the error message and allow the user to retry. |
Platform-Specific Bridge Names
| Platform | Bridge Name | Handler |
|---|---|---|
| Kotlin (Android) | AndroidWallet | @JavascriptInterface onDataCollectionComplete(json: String) |
| Swift (iOS) | payDataCollectionComplete | WKScriptMessageHandler.didReceive(message:) |
| Flutter | ReactNativeWebView (injected via JS bridge) | JavaScriptChannel.onMessageReceived |
| React Native | ReactNativeWebView (native) | WebView.onMessage prop |
Get Required Actions
Get the required wallet actions for a selected payment option:
final actions = await walletKit.getRequiredPaymentActions(
request: GetRequiredPaymentActionsRequest(
optionId: 'option-id',
paymentId: 'payment-id',
),
);
// Process each action (e.g., sign transactions)
for (final action in actions) {
final walletRpc = action.walletRpc;
print('Chain ID: ${walletRpc.chainId}');
print('Method: ${walletRpc.method}');
// Dispatch based on walletRpc.method — see Sign Actions below
}Sign Actions
Sign each action using your wallet's signing implementation, dispatching on the RPC method:
// Sign each action based on its RPC method
final data = <Object>[];
for (final action in actions) {
final rpc = action.walletRpc;
switch (rpc.method) {
case 'eth_signTypedData_v4':
data.add(await signTypedData(rpc.chainId, rpc.params));
break;
case 'eth_sendTransaction':
data.add(await sendTransaction(rpc.chainId, rpc.params));
break;
case 'personal_sign':
data.add(await personalSign(rpc.chainId, rpc.params));
break;
default:
throw UnimplementedError('Unsupported RPC method: ${rpc.method}');
}
}Payment options may include multiple actions with different RPC methods. For example, a Permit2 payment where the user lacks sufficient allowance returns two actions: an eth_sendTransaction to approve the token allowance, followed by an eth_signTypedData_v4 to sign the Permit2 transfer. Your wallet must check action.walletRpc.method and dispatch to the appropriate handler. For full implementation guidance, see USDT support.
Keep data in the same order as the actions array.
Confirm Payment
Confirm the payment with the wallet RPC results (data) collected in the previous step. Each element of data is either a plain String (a signature or transaction hash) or, for chains like Tron, a Map<String, dynamic> JSON object; the SDK forwards each element verbatim. See Tron support for the Tron payload.
final confirmResponse = await walletKit.confirmPayment(
request: ConfirmPaymentRequest(
paymentId: 'payment-id',
optionId: 'option-id',
data: data, // Wallet RPC results from the Sign Actions step
maxPollMs: 60000, // Maximum polling time in milliseconds
),
);
print('Payment Status: ${confirmResponse.status}');
print('Is Final: ${confirmResponse.isFinal}');The signatures parameter is deprecated in favor of data and will be removed in a future major version. Existing integrations that pass signatures keep working; the SDK uses it as a fallback when data is null.
When using the WebView data-collection approach, you do not pass collectedData to confirmPayment. The WebView submits the collected data directly to the backend during the earlier Collect User Data step.
Data Collection Implementation
When selectedOption.collectData.url is present, display the URL in a WebView using webview_flutter (v4.10.0+). Add dependencies:
dependencies:
webview_flutter: ^4.10.0
url_launcher: ^6.1.0Data Collection Best Practices
- Display prominently: Show the form full-screen or as a prominent modal so users can interact with it easily
- Loading indicator: Show a loading indicator while the form loads
- Handle errors: Listen for
IC_ERRORmessages and display a user-facing error message with an option to retry - External links: Open Terms & Conditions and Privacy Policy links in the system browser rather than navigating within the form
- Domain restriction: Only allow navigation to WalletConnect pay domains and HTTPS URLs
- Back navigation: Handle back/dismiss gracefully — confirm cancellation with the user before closing the form mid-flow
- Keyboard behavior: Test that the soft keyboard appears and behaves correctly when users tap on form inputs
- Theme to match your brand: Pass
theme=lightortheme=darkto match your wallet's active color mode, and apply brand tokens withthemeVariablesexported from the WalletConnect Pay Dashboard. See Form URL parameters.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
class PayDataCollectionWebView extends StatefulWidget {
final String url;
final VoidCallback onComplete;
final ValueChanged<String> onError;
const PayDataCollectionWebView({
super.key,
required this.url,
required this.onComplete,
required this.onError,
});
@override
State<PayDataCollectionWebView> createState() =>
_PayDataCollectionWebViewState();
}
class _PayDataCollectionWebViewState extends State<PayDataCollectionWebView> {
late final WebViewController _controller;
bool _isLoading = true;
@override
void initState() {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => setState(() => _isLoading = false),
onNavigationRequest: (request) {
if (!request.url.contains('pay.walletconnect.com')) {
launchUrl(Uri.parse(request.url),
mode: LaunchMode.externalApplication);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
))
..addJavaScriptChannel(
'ReactNativeWebView',
onMessageReceived: (message) {
try {
final data = jsonDecode(message.message) as Map<String, dynamic>;
switch (data['type']) {
case 'IC_COMPLETE':
widget.onComplete();
break;
case 'IC_ERROR':
widget.onError(data['error'] ?? 'Unknown error');
break;
}
} catch (_) {}
},
)
..loadRequest(Uri.parse(widget.url));
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
WebViewWidget(controller: _controller),
if (_isLoading)
const Center(child: CircularProgressIndicator()),
],
);
}
}Complete Example
Here's a complete example of processing a payment:
import 'package:reown_walletkit/reown_walletkit.dart';
class PaymentService {
final ReownWalletKit walletKit;
PaymentService(this.walletKit);
/// Process a payment from a payment link (e.g., after scanning QR code)
Future<void> processPayment(String paymentLink) async {
try {
// Step 1: Get payment options
final accounts = await getWalletAccounts(); // Your wallet accounts
final optionsResponse = await walletKit.getPaymentOptions(
request: GetPaymentOptionsRequest(
paymentLink: paymentLink,
accounts: accounts,
includePaymentInfo: true,
),
);
if (optionsResponse.options.isEmpty) {
throw Exception('No payment options available');
}
// Step 2: Select payment option (or let user choose)
PaymentOption selectedOption = optionsResponse.options.first;
final paymentId = optionsResponse.paymentId;
final optionId = selectedOption.id;
// Step 3: Collect data via WebView if required for selected option.
// This must happen BEFORE fetching the required payment actions —
// the backend rejects the actions request with 400 "IC data required"
// for options needing Information Capture if data wasn't collected first.
// The WebView submits the data directly to the backend, so it is NOT
// passed to confirmPayment later.
if (selectedOption.collectData?.url != null) {
await showDataCollectionWebView(selectedOption.collectData!.url);
}
// Step 4: Get required payment actions (if not already in the option)
List<Action> actions = selectedOption.actions;
if (actions.isEmpty) {
actions = await walletKit.getRequiredPaymentActions(
request: GetRequiredPaymentActionsRequest(
optionId: optionId,
paymentId: paymentId,
),
);
}
// Step 5: Execute wallet actions and collect the results
final data = <Object>[];
for (final action in actions) {
// Dispatch based on action.walletRpc.method:
// 'eth_signTypedData_v4' -> sign EIP-712 typed data
// 'eth_sendTransaction' -> send transaction (e.g., token approval)
// 'personal_sign' -> personal message signing
data.add(await signAction(action.walletRpc));
}
// Step 6: Confirm payment
ConfirmPaymentResponse confirmResponse = await walletKit.confirmPayment(
request: ConfirmPaymentRequest(
paymentId: paymentId,
optionId: optionId,
data: data,
maxPollMs: 60000, // Maximum polling time in milliseconds
),
);
// Step 7: Poll until final status (if needed)
while (!confirmResponse.isFinal && confirmResponse.pollInMs != null) {
await Future.delayed(Duration(milliseconds: confirmResponse.pollInMs!));
confirmResponse = await walletKit.confirmPayment(
request: ConfirmPaymentRequest(
paymentId: paymentId,
optionId: optionId,
data: data,
maxPollMs: 60000,
),
);
}
// Handle final payment status
switch (confirmResponse.status) {
case PaymentStatus.succeeded:
print('Payment succeeded!');
break;
case PaymentStatus.failed:
throw Exception('Payment failed');
case PaymentStatus.expired:
throw Exception('Payment expired');
case PaymentStatus.cancelled:
throw Exception('Payment cancelled');
case PaymentStatus.requires_action:
throw Exception('Payment requires additional action');
case PaymentStatus.processing:
// Should not happen if isFinal is true
break;
}
} catch (e) {
print('Payment error: $e');
rethrow;
}
}
Future<List<String>> getWalletAccounts() async {
// Return your wallet's CAIP-10 formatted accounts
// Example: ['eip155:1:0x1234...', 'eip155:137:0x5678...']
return [];
}
}API Reference
ReownWalletKit Pay Methods
| Method | Description |
|---|---|
isPaymentLink(String uri) | Check if URI is a payment link |
getPaymentOptions({required GetPaymentOptionsRequest request}) | Get available payment options |
getRequiredPaymentActions({required GetRequiredPaymentActionsRequest request}) | Get actions requiring signatures |
confirmPayment({required ConfirmPaymentRequest request}) | Confirm and finalize payment |
pay | Access the underlying WalletConnectPay instance |
Models
GetPaymentOptionsRequest
GetPaymentOptionsRequest({
required String paymentLink,
required List<String> accounts,
@Default(false) bool includePaymentInfo,
})PaymentOptionsResponse
PaymentOptionsResponse({
required String paymentId,
PaymentInfo? info,
required List<PaymentOption> options,
CollectDataAction? collectData,
PaymentResultInfo? resultInfo, // Transaction result details (present when payment already completed)
})PaymentResultInfo
class PaymentResultInfo {
final String txId; // Transaction ID
final PayAmount optionAmount; // Token amount details
}PaymentInfo
PaymentInfo({
required PaymentStatus status,
required PayAmount amount,
required int expiresAt,
required MerchantInfo merchant,
BuyerInfo? buyer,
})PaymentOption
PaymentOption({
required String id,
required String account,
required PayAmount amount,
@JsonKey(name: 'etaS') required int etaSeconds,
required List<Action> actions,
CollectDataAction? collectData, // Per-option data collection (null if not required)
})ConfirmPaymentRequest
ConfirmPaymentRequest({
required String paymentId,
required String optionId,
List<Object>? data, // Wallet RPC results in action order: Strings or Map<String, dynamic> JSON objects
@Default([]) List<String> signatures, // Deprecated alias for `data`, still accepted as fallback when data is null
int? maxPollMs,
})ConfirmPaymentResponse
ConfirmPaymentResponse({
required PaymentStatus status,
required bool isFinal,
int? pollInMs,
PaymentResultInfo? info, // Transaction result details (present on success)
})PaymentStatus
enum PaymentStatus {
requires_action,
processing,
succeeded,
failed,
expired,
cancelled,
}CollectDataAction
class CollectDataAction {
final String url; // WebView URL for data collection
final String? schema; // JSON schema describing required fields
}Error Handling
The SDK throws specific exception types for different error scenarios. All errors extend the abstract PayError class, which itself extends PlatformException:
abstract class PayError extends PlatformException {
PayError({
required super.code,
required super.message,
required super.details,
required super.stacktrace,
});
}| Exception | Description |
|---|---|
PayInitializeError | Initialization failures |
GetPaymentOptionsError | Errors when fetching payment options |
GetRequiredActionsError | Errors when getting required actions |
ConfirmPaymentError | Errors when confirming payment |
All errors include:
code: Error codemessage: Error messagedetails: Additional error detailsstacktrace: Stack trace
Example Error Handling
try {
final response = await walletKit.getPaymentOptions(request: request);
} on GetPaymentOptionsError catch (e) {
print('Error code: ${e.code}');
print('Error message: ${e.message}');
} on PayError catch (e) {
// Catch any Pay-related error
print('Pay error: ${e.message}');
} catch (e) {
print('Unexpected error: $e');
}Best Practices
-
Use WalletKit Integration: If your wallet already uses WalletKit, prefer this approach 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
-
Result Order: Keep
datain the same order 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 and you don't already have the required user data. If you already have the required data, you can submit this without collecting from the user. You must make sure the user accepts WalletConnect Terms and Conditions and Privacy Policy before submitting user information to WalletConnect. -
WebView Data Collection: When
selectedOption.collectData.urlis present, display the URL in a WebView usingwebview_flutterrather than building native forms. The WebView handles form rendering, validation, and T&C acceptance.