Skip to content

ashutoshpw/x402-vechain

Repository files navigation

x402 VeChain Facilitator

A TypeScript monorepo implementing the x402 payment protocol for VeChain blockchain. This project enables seamless cryptocurrency payment facilitation using VeChain's native tokens (VET, VTHO, VEUSD, B3TR) with support for testnet and mainnet environments.

🏗️ Project Structure

This monorepo consists of:

Applications

  • apps/api - Hono-based REST API implementing the x402 protocol facilitator endpoints
  • apps/dashboard - React Router admin dashboard for managing payments
  • apps/web - Astro marketing website

Examples

🚀 Quick Start

Prerequisites

  • Node.js 20 or higher
  • pnpm 10.12.4 (install with npm install -g [email protected])
  • PostgreSQL database (for API)
  • VeChain RPC access (testnet/mainnet)

Installation

  1. Clone the repository:
git clone https://github.com/ashutoshpw/x402-vechain.git
cd x402-vechain
  1. Install dependencies:
pnpm install
  1. Configure environment variables:
cp .env.example .env
# Edit .env with your configuration
  1. Start development servers:
pnpm dev

This will start all applications concurrently:

📦 Available Scripts

Development

pnpm dev              # Run all apps in development mode
pnpm build            # Build all apps for production

Individual App Commands

# API
pnpm --filter api dev              # Start API dev server
pnpm --filter api build            # Build API for production
pnpm --filter api db:generate      # Generate database migrations
pnpm --filter api db:migrate       # Run database migrations
pnpm --filter api db:push          # Push schema changes to database
pnpm --filter api db:studio        # Open Drizzle Studio

# Dashboard
pnpm --filter dashboard dev        # Start dashboard dev server
pnpm --filter dashboard build      # Build dashboard for production

# Web
pnpm --filter web dev              # Start web dev server
pnpm --filter web build            # Build web for production

🔧 Technology Stack

Build & Package Management

  • Turbo - Monorepo build orchestration with intelligent caching
  • pnpm - Fast, disk space efficient package manager

Backend (API)

  • Hono - Lightweight, fast web framework
  • Drizzle ORM - TypeScript-first ORM for PostgreSQL
  • Zod - TypeScript-first schema validation
  • @vechain/sdk - VeChain blockchain integration

Frontend

  • React Router 7 (Dashboard) - Full-stack React framework
  • Astro 5 (Web) - Modern static site generator
  • Tailwind CSS - Utility-first CSS framework

Database & Blockchain

  • PostgreSQL - Relational database
  • VeChain - Layer-1 blockchain platform

🌐 x402 Protocol Implementation

The API implements the x402 facilitator specification with the following endpoints:

GET /supported

Returns supported VeChain networks and assets.

Response:

{
  "networks": [{
    "network": "eip155:100009",
    "assets": ["VET", "VTHO", "VEUSD", "B3TR"]
  }],
  "schemes": ["x402"]
}

POST /verify

Validates payment payloads without settling on-chain.

POST /settle

Submits payment to VeChain and waits for confirmation.

For detailed API documentation, see apps/api/README.md.

⚙️ Environment Configuration

Key environment variables (see .env.example for complete list):

# VeChain Network
VECHAIN_NETWORK=testnet              # or 'mainnet'
VECHAIN_TESTNET_RPC=https://testnet.vechain.org
VECHAIN_MAINNET_RPC=https://mainnet.vechain.org

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/x402_testnet

# Fee Delegation (optional)
FEE_DELEGATION_ENABLED=false
FEE_DELEGATION_PRIVATE_KEY=          # Required if enabled

# Security
JWT_SECRET=                          # Generate: openssl rand -base64 32

# Rate Limiting
RATE_LIMIT_REQUESTS_PER_MINUTE=100

# Application
NODE_ENV=development
PORT=3000

⚠️ Security Note: Never commit .env files containing secrets to version control.

🗄️ Database Setup

The API uses PostgreSQL with Drizzle ORM. Database operations:

# Generate migration files from schema changes
pnpm --filter api db:generate

# Apply migrations to database
pnpm --filter api db:migrate

# Push schema changes directly (dev only)
pnpm --filter api db:push

# Open Drizzle Studio (database GUI)
pnpm --filter api db:studio

Database schema is defined in apps/api/src/db/schema.ts.

📚 Documentation

Each application has its own detailed README:

💡 Examples

Learn by example! Check out our practical integration examples:

View all examples →

🏗️ Architecture

┌─────────────────┐
│   Marketing     │
│   Website       │  Astro 5
│   (apps/web)    │
└─────────────────┘

┌─────────────────┐
│   Dashboard     │
│   Admin Panel   │  React Router 7
│ (apps/dashboard)│
└────────┬────────┘
         │
         │ API Calls
         │
         ▼
┌─────────────────┐
│   x402 API      │
│   Facilitator   │  Hono + PostgreSQL
│   (apps/api)    │
└────────┬────────┘
         │
         │ VeChain SDK
         │
         ▼
┌─────────────────┐
│   VeChain       │
│   Blockchain    │  Testnet / Mainnet
└─────────────────┘

🔐 Security Features

  • Request Validation - Zod schema validation on all API inputs
  • Rate Limiting - IP-based rate limiting (configurable)
  • CORS - Configurable cross-origin resource sharing
  • Environment Validation - Startup validation of all required environment variables
  • Fee Delegation - Optional gas fee sponsorship for users
  • JWT Authentication - Token-based authentication support

🚢 Deployment

API Deployment (Vercel)

# Install Vercel CLI
npm install -g vercel

# Deploy
pnpm --filter api install
vc deploy

Configure environment variables in the Vercel dashboard.

📖 References

📄 License

ISC

🤝 Contributing

This is a monorepo managed with pnpm and Turbo. When contributing:

  1. Use pnpm install to install dependencies
  2. Run pnpm dev to start all apps in development mode
  3. Ensure TypeScript types are correct
  4. Build successfully with pnpm build
  5. Follow existing code style and conventions
  6. See .github/copilot-instructions.md for detailed development guidelines

🌟 Supported Networks & Assets

VeChain Testnet (eip155:100009)

  • VET (VeChain Token)
  • VTHO (VeThor Token)
  • VEUSD (VeChain USD Stablecoin)
  • B3TR (Better Token)

VeChain Mainnet (eip155:100010)

  • VET (VeChain Token)
  • VTHO (VeThor Token)
  • VEUSD (VeChain USD Stablecoin)
  • B3TR (Better Token)

About

VeChain facilitator for the x402 payment protocol — API, dashboard, and example integrations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors