Skip to main content
The WalletConnect Pay SDK allows wallet users to pay merchants using their crypto assets. The SDK handles payment option discovery, permit signing coordination, and payment confirmation while leveraging your wallet’s existing signing infrastructure.

Requirements

  • Flutter 3.0+
  • iOS 13.0+
  • Android API 23+

Installation

Add walletconnect_pay package to your pubspec.yaml or simply run:
flutter pub add walletconnect_pay

Configuration

Initialize the WalletConnectPay client with your app ID and client ID or API key:
import 'package:walletconnect_pay/walletconnect_pay.dart';

// Initialize WalletConnect Pay. Either apiKey or appId must be passed
final payClient = WalletConnectPay(
  apiKey: 'YOUR_API_KEY', // Optional
  appId: 'YOUR_APP_ID', // Optional
  clientId: 'OPTIONAL_CLIENT_ID', // Optional
  baseUrl: 'https://api.pay.walletconnect.com', // Optional
);

// Initialize the SDK
try {
  await payClient.init();
} on PayInitializeError catch (e) {
  // Handle initialization error
}

Configuration Parameters

ParameterTypeRequiredDescription
apiKeyString?No*WalletConnect Pay API key
appIdString?No*WalletConnect app ID
clientIdString?NoClient identifier
baseUrlString?NoBase URL for the API (defaults to production)
Either apiKey or appId must be provided for authentication.
Don’t have a project ID? Create one at the WalletConnect Dashboard by signing up and creating a new project.

Supported Networks

WalletConnect Pay currently supports the following networks with USDC:
NetworkChain IDCAIP-10 Format
Ethereum1eip155:1:{address}
Base8453eip155:8453:{address}
Optimism10eip155:10:{address}
Polygon137eip155:137:{address}
Arbitrum42161eip155:42161:{address}
Support for all EVM chains, Solana, and additional native and non-native assets is coming soon. Include accounts for all supported networks to maximize payment options for your users.

Payment Flow

The payment flow consists of four main steps: Get Options -> Get Actions -> Sign Actions -> Confirm Payment
1

Get Payment Options

Retrieve available payment options for a payment link:
final request = GetPaymentOptionsRequest(
  paymentLink: 'https://pay.walletconnect.com/pay_123',
  accounts: ['eip155:1:0x...', 'eip155:137:0x...'], // User's wallet CAIP-10 accounts
  includePaymentInfo: true, // Include payment details in response
);

final response = await payClient.getPaymentOptions(request: request);

// Access payment information
print('Payment ID: ${response.paymentId}');
print('Options available: ${response.options.length}');

if (response.info != null) {
  print('Amount: ${response.info!.amount.formatAmount()}');
  print('Status: ${response.info!.status}');
  print('Merchant: ${response.info!.merchant.name}');
}

// Check if data collection is required
if (response.collectData != null) {
  print('Data collection required: ${response.collectData!.fields.length} fields');
}
2

Get Required Payment Actions

Get the required wallet actions (e.g., transactions to sign) for a selected payment option:
final actionsRequest = GetRequiredPaymentActionsRequest(
  optionId: response.options.first.id, // Or whatever other option chosen by the user
  paymentId: response.paymentId,
);
final actions = await payClient.getRequiredPaymentActions(
  request: actionsRequest,
);

// 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}');
  print('Params: ${walletRpc.params}');
  
  // Sign the transaction using your wallet SDK
  // final signature = await signTransaction(walletRpc);
}
3

Collect User Data (If Required)

Some payments may require additional user data. Check for collectData in the payment options response:
List<CollectDataFieldResult>? collectedData;

if (response.collectData != null) {
  collectedData = response.collectData!.fields.map((field) {
    return CollectDataFieldResult(
      id: field.id,
      value: getUserInput(field.name, field.fieldType),
    );
  }).toList();
}
4

Confirm Payment

Confirm a payment with signatures and optional collected data:
final confirmRequest = ConfirmPaymentRequest(
  paymentId: response.paymentId,
  optionId: response.options.first.id,
  signatures: ['0x...', '0x...'], // Signatures from wallet actions
  collectedData: [
    CollectDataFieldResult(
      id: 'fullName',
      value: 'John Doe',
    ),
    CollectDataFieldResult(
      id: 'dob',
      value: '1990-01-01',
    ),
  ], // Optional: if data collection was required
  maxPollMs: 60000, // Optional: max polling time in milliseconds
);

final confirmResponse = await payClient.confirmPayment(request: confirmRequest);

print('Payment Status: ${confirmResponse.status}');
print('Is Final status: ${confirmResponse.isFinal}');

if (!confirmResponse.isFinal && confirmResponse.pollInMs != null) {
  // Poll again after the specified interval
  await Future.delayed(Duration(milliseconds: confirmResponse.pollInMs!));
  // Re-confirm or check status
}

Complete Example

Here’s a complete implementation example:
import 'package:walletconnect_pay/walletconnect_pay.dart';

class PaymentService {
  late final WalletConnectPay _payClient;

  Future<void> initialize() async {
    _payClient = WalletConnectPay(
      appId: 'YOUR_APP_ID',
    );
    await _payClient.init();
  }

  Future<ConfirmPaymentResponse> processPayment(
    String paymentLink,
    List<String> accounts,
  ) async {
    // Step 1: Get payment options
    final optionsResponse = await _payClient.getPaymentOptions(
      request: GetPaymentOptionsRequest(
        paymentLink: paymentLink,
        accounts: accounts,
        includePaymentInfo: true,
      ),
    );

    if (optionsResponse.options.isEmpty) {
      throw Exception('No payment options available');
    }

    // Step 2: Select payment option (simplified - use first option)
    final selectedOption = optionsResponse.options.first;

    // Step 3: Get required payment actions
    final actions = await _payClient.getRequiredPaymentActions(
      request: GetRequiredPaymentActionsRequest(
        optionId: selectedOption.id,
        paymentId: optionsResponse.paymentId,
      ),
    );

    // Step 4: Sign all actions
    final signatures = <String>[];
    for (final action in actions) {
      final signature = await signTransaction(action.walletRpc);
      signatures.add(signature);
    }

    // Step 5: Collect user data if required
    List<CollectDataFieldResult>? collectedData;
    if (optionsResponse.collectData != null) {
      collectedData = await collectUserData(optionsResponse.collectData!.fields);
    }

    // Step 6: Confirm payment
    final confirmResponse = await _payClient.confirmPayment(
      request: ConfirmPaymentRequest(
        paymentId: optionsResponse.paymentId,
        optionId: selectedOption.id,
        signatures: signatures,
        collectedData: collectedData,
        maxPollMs: 60000,
      ),
    );

    // Step 7: Poll until final status (if needed)
    var response = confirmResponse;
    while (!response.isFinal && response.pollInMs != null) {
      await Future.delayed(Duration(milliseconds: response.pollInMs!));
      response = await _payClient.confirmPayment(
        request: ConfirmPaymentRequest(
          paymentId: optionsResponse.paymentId,
          optionId: selectedOption.id,
          signatures: signatures,
          collectedData: collectedData,
          maxPollMs: 60000,
        ),
      );
    }

    return response;
  }

  Future<String> signTransaction(WalletRpcAction walletRpc) async {
    // Implement your wallet's signing logic
    // Use walletRpc.chainId, walletRpc.method, walletRpc.params
    throw UnimplementedError('Implement signing logic');
  }

  Future<List<CollectDataFieldResult>> collectUserData(
    List<CollectDataField> fields,
  ) async {
    // Implement your UI to collect user data
    return fields.map((field) {
      return CollectDataFieldResult(
        id: field.id,
        value: getUserInput(field),
      );
    }).toList();
  }
}

API Reference

WalletConnectPay

The main class for interacting with the WalletConnect Pay SDK.

Constructor

WalletConnectPay({
  String? apiKey,
  String? appId,
  String? clientId,
  String? baseUrl,
})

Methods

MethodDescription
Future<bool> init()Initializes the SDK. Returns true on success or throw PayInitializeError on error
Future<PaymentOptionsResponse> getPaymentOptions({required GetPaymentOptionsRequest request})Retrieves available payment options
Future<List<Action>> getRequiredPaymentActions({required GetRequiredPaymentActionsRequest request})Gets the required wallet actions for a selected option (to be called if the selected option does not have actions included)
Future<ConfirmPaymentResponse> confirmPayment({required ConfirmPaymentRequest request})Confirms a payment

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,
})

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,
})

ConfirmPaymentRequest

ConfirmPaymentRequest({
  required String paymentId,
  required String optionId,
  required List<String> signatures,
  List<CollectDataFieldResult>? collectedData,
  int? maxPollMs,
})

ConfirmPaymentResponse

ConfirmPaymentResponse({
  required PaymentStatus status,
  required bool isFinal,
  int? pollInMs,
})

PaymentStatus

enum PaymentStatus {
  requires_action,
  processing,
  succeeded,
  failed,
  expired,
}

Action & WalletRpcAction

class Action {
  final WalletRpcAction walletRpc;
}

class WalletRpcAction {
  final String chainId;   // CAIP-2 chain ID (e.g., "eip155:8453")
  final String method;    // RPC method (e.g., "eth_signTypedData_v4")
  final String params;    // JSON-encoded parameters
}

CollectDataField & CollectDataFieldResult

class CollectDataField {
  final String id;
  final String name;
  final bool required;
  final CollectDataFieldType fieldType;
}

class CollectDataFieldResult {
  final String id;
  final String value;
}

enum CollectDataFieldType {
  text,
  date,
}

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,
  });
}
ExceptionDescription
PayInitializeErrorInitialization failures
GetPaymentOptionsErrorErrors when fetching payment options
GetRequiredActionsErrorErrors when getting required actions
ConfirmPaymentErrorErrors when confirming payment
All errors include:
  • code: Error code
  • message: Error message
  • details: Additional error details
  • stacktrace: Stack trace

Example Error Handling

try {
  await payClient.init();
} on PayInitializeError catch (e) {
  print('Initialization failed: ${e.code} - ${e.message}');
}

try {
  final response = await payClient.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

  1. Initialize once: Call init() only once, typically during app startup
  2. Account Format: Always use CAIP-10 format for accounts: eip155:{chainId}:{address}
  3. Multiple Chains: Provide accounts for all supported chains to maximize payment options
  4. Signature Order: Maintain the same order of signatures as the actions array
  5. Error Handling: Always handle errors gracefully and show appropriate user feedback
  6. Loading States: Show loading indicators during API calls and signing operations
  7. Expiration: Check paymentInfo.expiresAt and warn users if time is running low
  8. User Data: Only collect data when collectData is present in the response

Examples

For a complete example implementation, see the reown_walletkit example.