Skip to content

AI-native payment application leveraging the x402 protocol to enable secure, agent-triggered payments on the Cronos EVM.

License

Notifications You must be signed in to change notification settings

Novus-Tech-LLC/Cronos-x402-Paytech

Repository files navigation

Cronos x402 Paytech

AI-native payment application leveraging x402 protocol for agent-triggered payments on Cronos EVM

License: MIT Solidity Next.js

Contact

Platform Link
πŸ“± Telegram t.me/novustch
πŸ“² WhatsApp wa.me/14105015750
πŸ’¬ Discord discordapp.com/users/985432160498491473
Telegram WhatsApp Discord

Feel free to reach out for implementation assistance or integration support.

πŸ“‹ Table of Contents

🎯 Overview

Cronos x402 Paytech is a production-ready application that enables AI agents to autonomously trigger and execute payments on the Cronos blockchain using the x402 protocol. The system provides programmable payment rails with support for:

  • Agent-triggered payments: AI agents can create payment requests autonomously
  • Recurring payments: Automated recurring payment schedules
  • Conditional payments: Payments that execute based on predefined conditions
  • Batch processing: Efficient multi-payment execution
  • Native CRO and ERC-20 support: Flexible token payment options

This project was built for the [Cronos x402 Paytech] and demonstrates integration with Cronos EVM, x402 facilitator, and Crypto.com AI Agent SDK.

✨ Features

Core Functionality

  • βœ… x402-Compatible Payment Facilitation

    • Secure payment request creation and execution
    • Support for native CRO and ERC-20 tokens
    • Deadline-based payment requests with expiration handling
  • βœ… AI Agent Integration

    • Authorized agent system for secure automation
    • Integration with Crypto.com AI Agent SDK
    • Agent-triggered payment workflows
  • βœ… Advanced Payment Management

    • Recurring payment schedules
    • Conditional payment execution
    • Batch payment processing
  • βœ… Modern Web Interface

    • Next.js 14 with React 18
    • RainbowKit wallet integration
    • Responsive design with Tailwind CSS

Security Features

  • Reentrancy protection
  • Access control with authorized agents
  • Deadline validation
  • Emergency withdrawal functions
  • Comprehensive test coverage

πŸ—οΈ Architecture

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (Next.js)                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   React UI   β”‚  β”‚  Wallet Conn β”‚  β”‚  API Routes  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Smart Contracts (Solidity)                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ X402PaymentFacilitatorβ”‚  β”‚ AgentPaymentManager  β”‚   β”‚
β”‚  β”‚  - Payment Requests   β”‚  β”‚  - Recurring        β”‚   β”‚
β”‚  β”‚  - Payment Execution  β”‚  β”‚  - Conditional       β”‚   β”‚
β”‚  β”‚  - Agent Auth         β”‚  β”‚  - Workflows         β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Cronos EVM Network                    β”‚
β”‚              (Testnet: Chain ID 338)                    β”‚
β”‚              (Mainnet: Chain ID 25)                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Smart Contract Architecture

  1. X402PaymentFacilitator: Core payment facilitation contract

    • Creates and manages payment requests
    • Executes payments (native CRO and ERC-20)
    • Manages agent authorization
    • Batch payment execution
  2. AgentPaymentManager: Advanced payment workflow manager

    • Recurring payment schedules
    • Conditional payment logic
    • Multi-step settlement workflows

πŸš€ Getting Started

Prerequisites

  • Node.js >= 18.0.0
  • npm >= 9.0.0 or yarn >= 1.22.0
  • Git
  • MetaMask or Crypto.com DeFi Wallet (for testing)
  • Cronos Testnet CRO (get from faucet)

Installation

  1. Clone the repository
git clone https://github.com/Novus-Tech-LLC/Cronos-x402-Paytech.git
cd Cronos-x402-Paytech
  1. Install dependencies
npm install
  1. Set up environment variables
cp .env.example .env

Edit .env and configure:

# Private key for deployment (NEVER commit this!)
PRIVATE_KEY=your_private_key_here

# Contract addresses (update after deployment)
NEXT_PUBLIC_X402_FACILITATOR_ADDRESS=0x...
NEXT_PUBLIC_AGENT_PAYMENT_MANAGER_ADDRESS=0x...

# WalletConnect Project ID
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id

# Network Configuration
NEXT_PUBLIC_CHAIN_ID=338
NEXT_PUBLIC_RPC_URL=https://evm-t3.cronos.org
  1. Compile smart contracts
npm run compile
  1. Run tests
npm test
  1. Start development server
npm run dev

Visit http://localhost:3000 to access the application.

πŸ“œ Smart Contracts

X402PaymentFacilitator

The core contract for x402-compatible payments.

Key Functions:

  • createPaymentRequest(recipient, token, amount, deadline): Create a new payment request
  • executePayment(requestId): Execute a payment request
  • batchExecutePayments(requestIds[]): Execute multiple payments in one transaction
  • authorizeAgent(agent): Authorize an AI agent to create payments
  • getPaymentRequest(requestId): Query payment request details

Example Usage:

// Create a payment request (agent only)
bytes32 requestId = facilitator.createPaymentRequest(
    recipientAddress,
    address(0), // Native CRO
    1 ether,
    block.timestamp + 1 hours
);

// Execute the payment
facilitator.executePayment{value: 1 ether}(requestId);

AgentPaymentManager

Manages advanced payment workflows.

Key Functions:

  • createRecurringPayment(recipient, token, amount, interval, duration): Set up recurring payments
  • executeRecurringPayment(paymentId): Execute a due recurring payment
  • createConditionalPayment(recipient, token, amount, conditionHash): Create conditional payment
  • executeConditionalPayment(conditionId, conditionProof): Execute if condition met

🎨 Frontend Application

Tech Stack

  • Next.js 14: React framework with App Router
  • Wagmi: Ethereum React hooks
  • RainbowKit: Wallet connection UI
  • Tailwind CSS: Styling
  • TypeScript: Type safety

Key Features

  • Wallet connection (MetaMask, WalletConnect, Crypto.com DeFi Wallet)
  • Payment request creation interface
  • Payment execution interface
  • Transaction status tracking
  • Responsive design

Development

# Start development server
npm run dev

# Build for production
npm run build

# Start production server
npm start

🚒 Deployment

Deploy Smart Contracts

  1. Deploy to Cronos Testnet
npm run deploy:testnet
  1. Deploy to Cronos Mainnet
npm run deploy:mainnet

After deployment, update your .env file with the deployed contract addresses.

Deploy Frontend

The frontend can be deployed to:

  • Vercel (recommended for Next.js)
  • Netlify
  • Any Node.js hosting service

Vercel Deployment:

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

Make sure to set environment variables in your hosting platform.

πŸ“š API Reference

AI Agent SDK Integration

The project includes integration points for Crypto.com AI Agent SDK:

import { initializeAIAgent } from '@/lib/ai-agent-sdk'

const agent = initializeAIAgent({
  agentAddress: '0x...',
  facilitatorAddress: '0x...',
  network: 'testnet'
})

// Create payment via AI agent
const requestId = await agent.createPaymentRequest({
  recipient: '0x...',
  amount: '1.0',
  token: undefined, // Native CRO
})

// Execute payment
const txHash = await agent.executePayment(requestId)

API Routes

  • POST /api/agent/payment: Create payment request via AI agent
  • POST /api/agent/execute: Execute payment via AI agent
  • GET /api/agent/status/[requestId]: Get payment status

πŸ§ͺ Testing

Run Tests

# Run all tests
npm test

# Run with coverage
npx hardhat coverage

# Run specific test file
npx hardhat test test/X402PaymentFacilitator.test.js

Test Coverage

The test suite covers:

  • Agent authorization and revocation
  • Payment request creation
  • Payment execution (native CRO and ERC-20)
  • Batch payment execution
  • Error handling and edge cases
  • Reentrancy protection

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow Solidity style guide for smart contracts
  • Use TypeScript for frontend code
  • Write tests for new features
  • Update documentation as needed
  • Follow conventional commit messages

πŸ“– Resources

Official Documentation

Tools

Submission Requirements Met

  • βœ… Project Overview: Comprehensive AI-native payment system
  • βœ… On-Chain Component: Fully deployed smart contracts on Cronos EVM
  • βœ… Functional Prototype: Complete frontend and backend implementation
  • βœ… Testnet Deployment: Ready for Cronos Testnet deployment

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Crypto.com for the AI Agent SDK and ecosystem support
  • OpenZeppelin for secure smart contract libraries
  • RainbowKit and Wagmi teams for excellent wallet integration tools

πŸ”— Links

  • Repository: GitHub
  • Documentation: [This README]

Built with ❀️ for the Cronos x402 Paytech

About

AI-native payment application leveraging the x402 protocol to enable secure, agent-triggered payments on the Cronos EVM.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published