Overview
Sovran supports NFC (Near Field Communication) payments for contactless ecash transfers. Users can tap their device to a point-of-sale terminal or another device to send/receive Cashu tokens instantly.NFC Architecture
The NFC implementation is modular and located inhelper/nfc/:
Payment Hook
TheuseNfcEcashPayment hook provides a declarative interface for NFC payments:
hooks/useNfcEcashPayment.tsx:29-219.
Payment Flow
The NFC payment flow consists of four phases:Phase 1: Read Payment Request
- Acquire IsoDep technology
- Select AID (Application Identifier)
- Select NDEF file
- Read NLEN (NDEF length)
- Read NDEF content (chunked if > 250 bytes)
- Decode payment request
helper/nfc/payment.ts:114-183.
Phase 2: Decode and Validate
- Decode NUT-18 payment request
- Extract amount, unit, allowed mints
- Validate amount against limit
- Wait for mint availability
- Select best mint
helper/nfc/payment.ts:214-247.
Phase 3: Create Token
- Call
createTokencallback - Generate ecash token for amount
- Encode as V4 token
helper/nfc/payment.ts:249-265.
Phase 4: Write Token Back
- Re-select NDEF file
- Write NLEN
- Write NDEF content (chunked if > 250 bytes)
- Release NFC technology
helper/nfc/payment.ts:267-307.
Token Recovery
If the write fails after token creation, the token is automatically recovered:hooks/useNfcEcashPayment.tsx:123-176.
Lightning Invoice Detection
NFC can detect Lightning invoices and redirect to Lightning flow:helper/nfc/payment.ts:198-212.
Mint Selection
TheselectBestMint function chooses the optimal mint:
helper/nfc/mint-selection.ts.
Payment Limit Tiers
Users select a payment limit before tapping:hooks/useNfcEcashPayment.tsx:197-205.
P2P Token Writing
Write tokens to NFC tags for peer-to-peer sharing:helper/nfc/write-token.ts:20-97.
Error Handling
Typed errors with user-friendly messages:NOT_SUPPORTED- NFC not available on deviceNOT_ENABLED- NFC disabled in settingsTAG_LOST- Connection lost during operationAMOUNT_EXCEEDED- Payment exceeds limitNO_AVAILABLE_MINTS- No mints with balanceINVALID_AMOUNT- Invalid payment amountTOKEN_CREATION_FAILED- Failed to create tokenWRITE_CHUNK_FAILED- Failed to write token
Header Integration
NFC payment button in wallet header:app/(drawer)/(tabs)/index/_layout.tsx:70-97.
Key Features
Contactless Payments
Tap-to-pay at NFC-enabled point-of-sale terminals
Automatic Recovery
Token rollback if write fails after creation
Lightning Detection
Automatic detection and routing for Lightning invoices
Smart Mint Selection
Intelligent mint selection based on balance and restrictions
Related Documentation
- Lightning Payments - Lightning Network integration
- Ecash Tokens - Token operations
- QR Scanner - QR code scanning