CoinPay is a non-custodial cryptocurrency payment gateway that enables e-commerce merchants to accept crypto payments with automatic fee handling and real-time transaction monitoring.
graph TB
Customer[Customer/Buyer]
Merchant[Merchant]
Landing[Landing Page]
Dashboard[Merchant Dashboard]
API[Next.js API Routes]
Supabase[(Supabase Database)]
WalletGen[Wallet Generation Service]
Monitor[Blockchain Monitor Service]
Forward[Payment Forwarding Service]
Webhook[Webhook Service]
Customer -->|Makes Payment| QR[QR Code Payment]
Merchant -->|Manages| Dashboard
Merchant -->|Views Demo| Landing
Dashboard -->|API Calls| API
Landing -->|API Calls| API
QR -->|Monitors| Monitor
API -->|CRUD Operations| Supabase
API -->|Generate Address| WalletGen
Monitor -->|Detects Payment| Forward
Forward -->|Deduct 2% Fee| MerchantWallet[Merchant Wallet]
Forward -->|Triggers| Webhook
Webhook -->|Notifies| MerchantSystem[Merchant System]
subgraph Blockchains
BTC[Bitcoin]
BCH[Bitcoin Cash]
ETH[Ethereum]
POL[Polygon]
SOL[Solana]
USDC[USDC Multi-chain]
end
Monitor -.->|RPC Calls| Blockchains
Forward -.->|Transactions| Blockchains
- Demo payment integration
- Feature showcase
- Quick start guide
- Live payment example
- Business management
- Payment history
- Wallet connection (MetaMask, WalletConnect, Phantom)
- Webhook configuration
- Analytics and reporting
All Supabase interactions go through server-side API routes for security.
/api/auth/register- Merchant registration/api/auth/login- Merchant login/api/auth/logout- Session termination
/api/businesses- List merchant businesses/api/businesses/create- Create new business/api/businesses/[id]- Get/Update/Delete business
/api/payments/create- Generate payment request/api/payments/[id]- Get payment status/api/payments/[id]/qr- Generate QR code/api/payments/webhook- Receive blockchain events
/api/webhooks- Manage webhook endpoints/api/webhooks/test- Test webhook delivery
- HD wallet derivation for each payment
- Support for multiple blockchain standards:
- BIP44 for Bitcoin/Bitcoin Cash
- BIP44 for Ethereum/Polygon
- Ed25519 for Solana
- Encrypted key storage in Supabase
- Real-time transaction monitoring via RPC providers:
- Bitcoin/BCH: Public RPC nodes or BlockCypher
- Ethereum/Polygon: Alchemy or Infura
- Solana: Public RPC or QuickNode
- Webhook-based event system
- Confirmation tracking (3+ confirmations)
- Automatic forwarding after confirmations
- 2% fee calculation and deduction
- Gas fee optimization
- Transaction retry logic
- Multi-signature support for security
merchants
- id (uuid, primary key)
- email (text, unique)
- created_at (timestamp)
- updated_at (timestamp)
businesses
- id (uuid, primary key)
- merchant_id (uuid, foreign key)
- name (text)
- description (text)
- webhook_url (text, nullable)
- webhook_secret (text, nullable)
- created_at (timestamp)
- updated_at (timestamp)
payment_addresses
- id (uuid, primary key)
- business_id (uuid, foreign key)
- blockchain (text) - btc, bch, eth, pol, sol, usdc_eth, usdc_pol, usdc_sol
- address (text, unique)
- private_key_encrypted (text)
- derivation_path (text)
- created_at (timestamp)
- used (boolean)
payments
- id (uuid, primary key)
- business_id (uuid, foreign key)
- payment_address_id (uuid, foreign key)
- amount (numeric)
- currency (text)
- blockchain (text)
- status (text) - pending, confirmed, forwarded, failed
- customer_paid_amount (numeric, nullable)
- merchant_received_amount (numeric, nullable)
- fee_amount (numeric, nullable)
- tx_hash (text, nullable)
- forward_tx_hash (text, nullable)
- confirmations (integer)
- merchant_wallet_address (text)
- metadata (jsonb)
- created_at (timestamp)
- updated_at (timestamp)
webhook_logs
- id (uuid, primary key)
- business_id (uuid, foreign key)
- payment_id (uuid, foreign key)
- url (text)
- payload (jsonb)
- response_status (integer, nullable)
- response_body (text, nullable)
- attempt (integer)
- created_at (timestamp)
sequenceDiagram
participant Customer
participant MerchantSite
participant CoinPay
participant Blockchain
participant MerchantWallet
participant WebhookEndpoint
MerchantSite->>CoinPay: Create Payment Request
CoinPay->>CoinPay: Generate Forwarding Address
CoinPay->>MerchantSite: Return Payment Details + QR
MerchantSite->>Customer: Display QR Code
Customer->>Blockchain: Send Payment to Forwarding Address
Blockchain->>CoinPay: Transaction Detected
CoinPay->>CoinPay: Wait for Confirmations
CoinPay->>CoinPay: Calculate 2% Fee
CoinPay->>MerchantWallet: Forward Payment minus Fee
CoinPay->>WebhookEndpoint: Send Payment Notification
WebhookEndpoint->>MerchantSite: Update Order Status
- Private keys encrypted at rest using AES-256
- Encryption keys stored in environment variables
- Never expose private keys in API responses
- Consider HSM or KMS for production
- JWT-based authentication
- Rate limiting on all endpoints
- CORS configuration
- Input validation and sanitization
- SQL injection prevention via Supabase RLS
- Multi-confirmation requirements
- Transaction replay protection
- Gas price limits
- Nonce management
- Next.js 14+ (App Router)
- TypeScript
- TailwindCSS
- Wagmi (Ethereum wallet connection)
- WalletConnect
- Phantom Wallet SDK
- Next.js API Routes
- Supabase (PostgreSQL)
- Node.js crypto libraries
- bitcoinjs-lib (Bitcoin/BCH)
- ethers.js (Ethereum/Polygon)
- @solana/web3.js (Solana)
- Vitest
- Testing Library
- Playwright (E2E)
- Commander.js (CLI)
- ESM exports for programmatic use
Required environment variables:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEYENCRYPTION_KEYBITCOIN_RPC_URLETHEREUM_RPC_URLPOLYGON_RPC_URLSOLANA_RPC_URLPLATFORM_FEE_WALLET_BTCPLATFORM_FEE_WALLET_ETHPLATFORM_FEE_WALLET_POLPLATFORM_FEE_WALLET_SOLWEBHOOK_SIGNING_SECRET
graph LR
Users[Users] -->|HTTPS| Vercel[Vercel Next.js]
Vercel -->|API Calls| Supabase[Supabase Cloud]
Vercel -->|RPC Calls| RPC[RPC Providers]
Vercel -->|Webhooks| Merchants[Merchant Systems]
subgraph Monitoring
Cron[Vercel Cron Jobs]
Monitor[Payment Monitor]
end
Cron -->|Trigger| Monitor
Monitor -->|Check| RPC
Monitor -->|Update| Supabase
- Database: Supabase auto-scaling with connection pooling
- API Routes: Serverless functions scale automatically
- Blockchain Monitoring: Queue-based processing for high volume
- Caching: Redis for frequently accessed data
- CDN: Static assets via Vercel Edge Network
- Support for additional blockchains (Avalanche, BSC, etc.)
- Fiat off-ramp integration
- Recurring payment subscriptions
- Multi-currency invoicing
- Advanced analytics dashboard
- Mobile SDK
- Plugin marketplace (WooCommerce, Shopify, etc.)