Skip to main content

Wallet Integration

The WalletDelegate interface is the bridge between the Privacy Boost SDK and your wallet. This guide covers implementing it for various wallet types, expanding on the brief examples in Authentication.

Interface Definition

Implementation Requirements

Return Values

  • Addresses: Checksummed hex strings with 0x prefix (42 characters)
  • Signatures: Hex strings with 0x prefix (132 characters for 65 bytes)
  • Transaction hashes: Hex strings with 0x prefix (66 characters)
  • Transaction receipts: Mined receipt status and logs from eth_getTransactionReceipt
  • Chain ID: ULong matching expected network

Suspend Behavior

All WalletDelegate methods are suspend functions. The SDK calls them within a coroutine context, so your implementation can use Kotlin coroutines natively. The SDK calls waitForTransactionReceipt after sendTransaction to confirm on-chain inclusion and read emitted events.

WalletConnect Integration

Example using WalletConnect Kotlin SDK:

Web3j Integration

Example using Web3j with a local keystore:

Testing with Mock Wallet

For testing, create a mock delegate:

Error Handling

Throw appropriate exceptions from delegate methods:

Best Practices

  1. Validate inputs - Check addresses and data formats before processing
  2. Handle timeouts - Set reasonable timeouts for wallet operations
  3. User feedback - Show loading indicators during signing/transactions
  4. Error messages - Provide clear error messages for user-facing errors
  5. Thread safety - Delegate methods are called from background threads

Next Steps