Skip to content

rtree/crypify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Crypify - Decentralized Crypto Rewards Platform

Seamless crypto payments with automatic wallet creation and gasless rewards

Crypify is a production-ready e-commerce platform that demonstrates the power of Coinbase Developer Platform (CDP) by combining Embedded Wallets for user payments with Server Wallets for gasless reward distribution.

🌟 Project Significance

The Problem

Traditional e-commerce platforms struggle with crypto adoption because:

  • Users need to manage complex wallets and private keys
  • High gas fees discourage small transactions
  • Reward distribution requires manual processes
  • No seamless integration between fiat and crypto ecosystems

Our Solution

Crypify eliminates these barriers by:

  • Zero-friction onboarding: Email OTP authentication creates wallets automatically (CDP Embedded Wallets)
  • Gasless rewards: Server-side distribution eliminates gas costs for users (CDP Server Wallets)
  • Instant liquidity: Users can spend rewards immediately without additional setup
  • Email-based recovery: No seed phrases to remember - wallet access tied to email

πŸ—οΈ Architecture

Monorepo structure with microservices deployment on Google Cloud Run:

crypify/
  web/        # Next.js 14 frontend with CDP Embedded Wallets
  api/        # Express backend with CDP Server Wallets
  specs/      # Technical documentation

System Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User      β”‚
β”‚  (Browser)  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”‚ 1. Browse products
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web Service       β”‚
β”‚  (Next.js + CDP)    β”‚
β”‚                     β”‚
β”‚ β€’ Product catalog   β”‚
β”‚ β€’ Email OTP auth    β”‚
β”‚ β€’ USDC payment UI   β”‚
β”‚ β€’ Embedded Wallets  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”‚ 2. Payment notification
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   API Service       β”‚
β”‚ (Express + CDP)     β”‚
β”‚                     β”‚
β”‚ β€’ Payment tracking  β”‚
β”‚ β€’ Reward calculationβ”‚
β”‚ β€’ Email with claim  β”‚
β”‚ β€’ Server Wallets    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”‚ 3. Gasless reward transfer
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Coinbase CDP       β”‚
β”‚                     β”‚
β”‚ β€’ Wallet management β”‚
β”‚ β€’ USDC transfers    β”‚
β”‚ β€’ Base Sepolia      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’‘ Unique Implementation Details

Hybrid CDP Architecture

We leverage two distinct CDP wallet systems working in harmony:

1. Embedded Wallets (User-Controlled)

// Frontend: Email OTP authentication
const { signInWithEmail } = useSignInWithEmail();
await signInWithEmail(email);

// CDP automatically manages wallet lifecycle
// userId = email β†’ persistent wallet address

Why?

  • Users own their private keys (non-custodial)
  • Zero setup friction (no MetaMask required)
  • Email-based recovery (familiar UX)
  • Perfect for payment flows

2. Server Wallets (Developer-Controlled)

// Backend: Merchant wallet management
const merchant = await Wallet.fetch(process.env.MERCHANT_WALLET_ID);

// Gasless reward distribution
await merchant.createTransfer({
  amount: rewardAmount,
  assetId: USDC_CONTRACT,
  destination: userAddress,
  gasless: true  // 🎯 User pays zero gas
});

Why?

  • Automated backend operations
  • Gasless transfers (better UX)
  • Centralized fund management
  • Perfect for reward distribution

HMAC-Signed Claim Links

No database required for claim validation:

// Generate tamper-proof claim token
const token = makeClaimToken({
  email,
  userAddress,
  rewardUsd,
  expiresAt: Date.now() + 24 * 3600 * 1000
});

// Email: https://crypify.app/claim?token=eyJ...

Security features:

  • HMAC-SHA256 signature prevents tampering
  • Time-based expiration (24 hours)
  • Stateless validation (no DB lookup)
  • Replay-resistant (one-time use tracked via frontend)

Build-Time Environment Variable Injection

Next.js NEXT_PUBLIC_* variables require special handling in Docker:

# Build stage - Accept build arguments
ARG NEXT_PUBLIC_CDP_PROJECT_ID
ARG NEXT_PUBLIC_API_BASE_URL

# Inject into build environment
ENV NEXT_PUBLIC_CDP_PROJECT_ID=$NEXT_PUBLIC_CDP_PROJECT_ID
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL

# Build with embedded variables
RUN pnpm build

Why this matters:

  • Next.js bundles NEXT_PUBLIC_* at build time, not runtime
  • Runtime env vars don't work for client-side code
  • Our solution: GitHub Actions β†’ Secret Manager β†’ Docker build args

πŸš€ Features

  • πŸ›οΈ E-commerce shop with crypto payments (USDC on Base Sepolia)
  • πŸ’Ό Automatic wallet creation via Email OTP (no MetaMask needed)
  • πŸ’° 10% cashback rewards distributed gaslessly
  • πŸ“§ Email notifications with tamper-proof claim links
  • πŸ” Zero-knowledge architecture - no user data stored
  • ⚑ Instant settlement - blockchain-native transactions

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 14 (App Router)
  • Wallet SDK: @coinbase/cdp-hooks (Embedded Wallets)
  • Blockchain: viem + wagmi (Base Sepolia)
  • Deployment: Google Cloud Run (containerized)

Backend

  • Runtime: Node.js 20 + Express
  • Wallet SDK: @coinbase/coinbase-sdk (Server Wallets)
  • Email: SendGrid (transactional emails)
  • Deployment: Google Cloud Run + Secret Manager

DevOps

  • CI/CD: GitHub Actions (automated deployment)
  • Container Registry: Google Artifact Registry
  • Secrets: Google Secret Manager
  • Monitoring: Cloud Run metrics

πŸ“¦ Local Development

Prerequisites

  • Node.js 20+
  • pnpm 9.0.0+
  • Coinbase Developer Platform account
  • SendGrid API key
  • Google Cloud account (for deployment)

Setup

  1. Clone repository
git clone https://github.com/rtree/crypify.git
cd crypify
  1. Install dependencies
pnpm install
  1. Configure API
cd api
cp .env.example .env
# Edit .env with your credentials:
# - CDP_API_KEY, CDP_API_SECRET
# - SENDGRID_API_KEY, FROM_EMAIL
# - MERCHANT_WALLET_ADDRESS, CLAIM_SECRET
pnpm dev  # Runs on http://localhost:8080
  1. Configure Web
cd web
cp .env.local.example .env.local
# Edit .env.local:
# - NEXT_PUBLIC_CDP_PROJECT_ID (from CDP Portal)
# - NEXT_PUBLIC_API_BASE_URL=http://localhost:8080
pnpm dev  # Runs on http://localhost:3000
  1. Visit http://localhost:3000

🌐 Production Deployment

Deployment is fully automated via GitHub Actions when pushing to main branch.

Setup Steps

  1. Create Google Cloud Project

    • Enable Cloud Run, Artifact Registry, Secret Manager APIs
    • Create service account with required permissions
  2. Configure GitHub Secrets

    • GCP_PROJECT_ID: Your GCP project ID
    • GCP_SA_KEY: Service account JSON key
  3. Populate Secret Manager

# CDP credentials
echo -n "YOUR_API_KEY" | gcloud secrets create CDP_API_KEY --data-file=-
echo -n "YOUR_API_SECRET" | gcloud secrets create CDP_API_SECRET --data-file=-
echo -n "YOUR_PROJECT_ID" | gcloud secrets create CDP_PROJECT_ID --data-file=-

# Email
echo -n "YOUR_SENDGRID_KEY" | gcloud secrets create SENDGRID_API_KEY --data-file=-
echo -n "noreply@crypify.app" | gcloud secrets create FROM_EMAIL --data-file=-

# Application
echo -n "YOUR_MERCHANT_ADDRESS" | gcloud secrets create MERCHANT_WALLET_ADDRESS --data-file=-
echo -n "$(openssl rand -hex 32)" | gcloud secrets create CLAIM_SECRET --data-file=-
  1. Deploy
git push origin main

GitHub Actions will:

  • Build Docker images with embedded environment variables
  • Push to Artifact Registry
  • Deploy to Cloud Run (asia-northeast1)
  • Configure secrets and environment variables

Production URLs

πŸ“– User Flow

  1. Browse Products β†’ User visits /shop and selects a product
  2. Email OTP Login β†’ CDP Embedded Wallet created automatically
  3. Pay with USDC β†’ User approves transaction (Embedded Wallet signature)
  4. Backend Processing β†’ API calculates 10% reward and sends email
  5. Claim Reward β†’ User clicks email link β†’ Gasless USDC transfer from Server Wallet
  6. View Wallet β†’ User can check balance and transaction history

πŸ”’ Security Considerations

HMAC Claim Tokens

  • SHA-256 signature with 256-bit secret
  • Payload includes: {email, userAddress, rewardUsd, expiresAt}
  • 24-hour expiration window
  • Stateless validation (no database required)

Gasless Transfer Limits

  • Source: Merchant Server Wallet (CDP-managed)
  • Network: Base Sepolia (testnet)
  • Asset: USDC only
  • Maximum: Wallet balance limit

Cloud Run Security

  • Secrets stored in Secret Manager (not environment variables)
  • Stateless containers (auto-scaling, no session persistence)
  • HTTPS-only (automatic TLS certificates)
  • IAM-based access control

πŸ“Š Project Structure

crypify/
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ deploy-web.yml           # Web deployment pipeline
β”‚   └── deploy-api.yml           # API deployment pipeline
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ claim.ts         # Reward claim endpoint
β”‚   β”‚   β”‚   β”œβ”€β”€ fundWallet.ts    # Gas funding endpoint
β”‚   β”‚   β”‚   β”œβ”€β”€ merchant.ts      # Merchant address endpoint
β”‚   β”‚   β”‚   β”œβ”€β”€ pay.ts           # Payment notification
β”‚   β”‚   β”‚   └── purchase.ts      # Purchase creation
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── email.ts         # SendGrid integration
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ cdp.ts           # CDP SDK initialization
β”‚   β”‚   β”‚   └── claimToken.ts    # HMAC token utilities
β”‚   β”‚   β”œβ”€β”€ types.ts             # TypeScript definitions
β”‚   β”‚   └── index.ts             # Express app
β”‚   β”œβ”€β”€ Dockerfile               # Multi-stage production build
β”‚   └── package.json
β”œβ”€β”€ web/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ shop/                # Product catalog
β”‚   β”‚   β”‚   └── page.tsx
β”‚   β”‚   β”œβ”€β”€ thanks/              # Payment page
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   β”‚   └── PayWithCrypto.tsx  # Embedded Wallet UI
β”‚   β”‚   β”œβ”€β”€ claim/               # Reward claim page
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   β”‚   └── ClaimWithAuth.tsx
β”‚   β”‚   β”œβ”€β”€ wallet/              # Wallet dashboard
β”‚   β”‚   β”‚   └── page.tsx
β”‚   β”‚   β”œβ”€β”€ CDPProvider.tsx      # CDP hooks provider
β”‚   β”‚   β”œβ”€β”€ layout.tsx
β”‚   β”‚   └── globals.css
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   └── api.ts               # API client utilities
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── shop/                # Static shop assets
β”‚   β”œβ”€β”€ Dockerfile               # Next.js production build
β”‚   β”œβ”€β”€ next.config.js
β”‚   └── package.json
β”œβ”€β”€ specs/
β”‚   β”œβ”€β”€ MVP_FINALDESIGN.md       # Architecture documentation
β”‚   β”œβ”€β”€ DEPLOYMENT.md            # Deployment guide
β”‚   └── PROCEDURE.md             # Development procedures
β”œβ”€β”€ pnpm-workspace.yaml          # Monorepo configuration
└── README.md

🎯 Roadmap

Current (MVP)

  • βœ… Embedded Wallets with Email OTP
  • βœ… Server Wallets for gasless transfers
  • βœ… HMAC-signed claim links
  • βœ… Production deployment on Cloud Run
  • βœ… Automated CI/CD with GitHub Actions

Future Enhancements

  • CDP OnRamp integration (fiat β†’ crypto)
  • Multi-chain support (Ethereum, Polygon, Arbitrum)
  • Firestore for claim deduplication
  • Advanced analytics dashboard
  • Mobile app (React Native)
  • NFT rewards for loyal customers

πŸ“„ License

MIT License - see LICENSE file for details

🀝 Contributing

Contributions welcome! Please read our contributing guidelines and submit pull requests.

πŸ“ž Support


Built with ❀️ using Coinbase Developer Platform

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •