
AnyPay
NFC crypto payments: Turn smartphones into banking payment terminals.
About
AnyPay is a React Native mobile app that enables instant cryptocurrency payments via NFC. Users tap phones to exchange payment details and complete transactions. Core Technology: Built with React Native and Expo for iOS and Android NFC communication: uses react-native-nfc-manager for reading and react-native-hce (Android Host Card Emulation) for sharing payment data Dark fintech UI with gradient animations and glassmorphism Blockchain Infrastructure: Cross-chain payments via Layer Zero Omnichain Protocol Automatic asset swapping via Uniswap when sender and recipient prefer different assets Supports Ethereum, Polygon, Arbitrum, and Optimism testnets Supports multiple tokens: USDC, USDT, ETH, wBTC User Experience: Send: choose asset/chain, tap recipient’s device, transaction executes automatically Receive: set amount and preferred asset/chain, wait for NFC tap, receive in preferred format Configuration: customize default send/receive chains, assets, and payment preferences Technical Flow: NFC exchange of payment details (address, amount, desired asset/chain) Source chain: sender’s asset locked in bridge contract Layer Zero: secure cross-chain message delivery Asset conversion: Uniswap swaps if needed Target chain: recipient receives preferred asset on preferred chain Key Features: Instant NFC-based payment initiation Cross-chain compatibility (send on one chain, receive on another) Automatic asset conversion (send ETH, receive USDC) Trustless execution via smart contracts Mobile-first design with smooth animations The project includes smart contracts for bridging, swapping, and cross-chain messaging, deployed on testnets for the EthGlobal Buenos Aires Hackathon. It demonstrates how NFC can simplify crypto payments while maintaining the flexibility of cross-chain and cross-asset transactions.
How it's made
# How It's Made - Technical Description ## Architecture Overview This project implements a cross-chain token bridging system that automatically bridges tokens after swaps, using **LayerZero V2** for omnichain messaging and **Uniswap v4 hooks** for swap integration. ## Core Technologies ### LayerZero V2 OApp Infrastructure - **OApp Contracts**: Built custom `SourceBridge` and `TargetBridge` contracts inheriting from LayerZero's `OApp` and `OAppOptionsType3` - **Cross-Chain Messaging**: Uses LayerZero's messaging protocol to send lock/unlock instructions between Arbitrum Sepolia and Optimism Sepolia - **OptionsBuilder**: Configured executor options with gas limits (200,000) for reliable message execution - **Endpoint IDs**: Arbitrum Sepolia (40231) and Optimism Sepolia (40232) ### Smart Contract Stack - **Solidity 0.8.24**: All contracts written in modern Solidity with safety features - **OpenZeppelin Contracts v5**: Used `SafeERC20` for secure token transfers, `Ownable` for access control - **Hardhat**: Development environment with custom network configurations for testnets ### Uniswap v4 Integration - **BaseHook**: Extended Uniswap's `BaseHook` contract to create `BridgeHook` - **Hook Permissions**: Configured with `afterSwap` permission flag (bit 7) for post-swap execution - **CREATE2 Deployment**: Implemented deterministic deployment using CREATE2 to meet Uniswap v4's hook address requirements - **BridgeHelper**: Helper contract that interfaces between the hook and LayerZero bridge ## Technical Implementation Details ### Bridge Architecture 1. **SourceBridge (Arbitrum Sepolia)**: - Locks tokens when users bridge - Sends cross-chain messages via LayerZero with recipient address and amount - Uses `quoteLockAndBridge` to calculate native fees before execution 2. **TargetBridge (Optimism Sepolia)**: - Receives messages from source chain - Mints bridged tokens to recipients - Handles burn operations when users bridge back ### Swap-to-Bridge Flow 1. User performs a swap on Uniswap v4 pool 2. BridgeHook's `afterSwap` callback is triggered automatically 3. BridgeHelper receives swap output and calls `lockAndBridge` with native ETH for fees 4. SourceBridge locks tokens and sends LayerZero cross-chain message 5. TargetBridge receives message and mints bridged tokens on destination chain ### NFC Crypto Payment Integration - **Contactless Payment Interface**: NFC-enabled devices (smartphones, payment terminals) can trigger the swap and bridge flow with a single tap - **Direct Smart Contract Connection**: NFC tap events connect directly to smart contracts, bypassing traditional payment processors - **Automated Transaction Execution**: Upon NFC tap, the system automatically: - Initiates the swap on Uniswap v4 pool - Triggers the bridge hook to lock tokens - Sends cross-chain message via LayerZero - Completes the entire payment flow in a single transaction - **Seamless User Experience**: Users can make cross-chain crypto payments without manual transaction signing or wallet interactions - **Payment Terminal Integration**: NFC payment terminals can be configured to accept crypto payments that automatically bridge to recipient's preferred chain - **Multi-Chain Payment Support**: Recipients can receive payments on their preferred chain, regardless of which chain the payment was initiated from ### Notable Technical Challenges & Solutions **Challenge 1: Uniswap v4 Hook Deployment** - Uniswap v4 requires hooks to be deployed at specific CREATE2 addresses based on permission bits - **Solution**: Implemented a CREATE2 factory pattern with salt calculation based on hook permissions (AFTER_SWAP_FLAG = 0x40) - Used iterative salt generation to find valid addresses matching permission requirements **Challenge 2: LayerZero Fee Handling** - Bridge operations require native ETH for LayerZero messaging fees - **Solution**: Made `Pool.swap` payable and forwarded `msg.value` through the call chain: `Pool → BridgeHelper → SourceBridge` - Implemented fee quoting before execution to ensure sufficient funds **Challenge 3: Cross-Chain State Synchronization** - Ensuring locked tokens on source chain match minted tokens on destination - **Solution**: Used LayerZero's reliable messaging with enforced options and DVN (Decentralized Verifier Network) configuration - Implemented event emissions for tracking lock/unlock operations ## Partner Technologies ### LayerZero V2 - **Benefit**: Provides secure, reliable cross-chain messaging without requiring custom validators - **Usage**: OApp pattern allows for composable cross-chain applications - **Configuration**: Set up default pathways, send/receive libraries, and DVNs for message verification ### Uniswap v4 SDK - **Benefit**: Enables hook-based customization of swap behavior - **Usage**: Integrated `afterSwap` hook to trigger bridging automatically post-swap - **Implementation**: BridgeHook extends BaseHook and implements afterSwap callback for automatic bridging ### NFC Technology - **Benefit**: Enables contactless crypto payments with the same convenience as traditional NFC payments (Apple Pay, Google Pay) - **Usage**: NFC tap triggers the swap-to-bridge flow automatically, eliminating the need for manual wallet interactions - **Integration**: Connects NFC-enabled devices directly to smart contract execution via Web3 wallet integration - **Payment Flow**: - User taps NFC-enabled device on payment terminal - Terminal reads payment amount and recipient address - Smart contract executes swap (e.g., WETH → USDC) on source chain - Bridge hook automatically bridges tokens to recipient's preferred chain - Payment completes on destination chain without recipient needing to be on source chain - **Use Cases**: - Point-of-sale crypto payments - Cross-chain merchant payments - Contactless donations and tips - Automated payroll and vendor payments ## Development Workflow 1. **Contract Development**: Wrote contracts in Solidity with comprehensive error handling 2. **Testing**: Used Hardhat for local testing and testnet deployments 3. **Deployment**: Automated deployment scripts with address verification and balance checks 4. **Wiring**: Configured LayerZero pathways using custom wiring scripts that set peers, libraries, and DVNs ## Key Features - **NFC Crypto Payments**: Contactless payment system that enables tap-to-pay functionality for cryptocurrency transactions - **Automatic Bridging**: Tokens bridge automatically after swaps without user intervention - **Fixed Swap Flow**: Deterministic swap amounts (0.1 WETH → 280.9 USDC) for predictable behavior - **Cross-Chain Recipient**: Users can specify different recipient addresses on destination chain - **Fee Optimization**: Quotes fees before execution to prevent failed transactions - **One-Tap Payments**: Complete cross-chain payment flow executed with a single NFC tap - **Merchant-Friendly**: Payment terminals can accept crypto payments that automatically bridge to merchant's preferred chain