DEV Community

Daniel Ioni
Daniel Ioni

Posted on

🤖 Build an Autonomous Robot Payment System with Monero & x402

🤖 Build an Autonomous Robot Payment System with Monero & x402

TL;DR: We built an open-source stack where robots autonomously request and pay for energy using the x402 protocol and Monero. ESP32 + Node.js + Monero = robots that pay for themselves.


🎯 The Problem

Your robot runs out of battery. Who pays for the recharge?

  • Farmers don't want to manually pay for every robot
  • Robot owners want automation
  • Charging stations need a way to get paid

Solution: The robot requests a payment when battery is low, and pays automatically using the x402 protocol.


🏗️ The Stack

┌─────────────────────────────────────────────────────────────────┐
│ MyZubster-Robot-Stack │
│ Open-source Repository │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ ESP32/ │ │ MyZubster │ │ Monero Wallet │ │
│ │ Arduino │───▶│ Gateway │───▶│ RPC (Testnet) │ │
│ │ x402 │ │ Node.js │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ GitHub │ │ Docker │ │
│ │ Bounties │ │ Compose │ │
│ └─────────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
text


🔑 Core Features

Feature Description
🤖 x402 Protocol Robot requests payment with 402 Payment Required
₿ Monero Integration Private, secure payments with XMR
🔗 GitHub Bounties Automatic bounty management with webhooks
🧠 AI-Ready MCP (Anthropic) integration for decision-making
📱 ESP32/Arduino Ready-to-use sketches for robots
💰 Fee System 2% MyZubster + 8% Bosco Community Fund
🔄 Robot Cloning Referral system with 5% fees for 1 year

💰 How the Payment Flow Works

1️⃣ Robot Registers


bash
curl -X POST http://localhost:10003/api/robot/register \
  -H "Content-Type: application/json" \
  -d '{
    "id": "robot_001",
    "name": "Tagliaerba 3000",
    "type": "lawn_mower",
    "owner": "45M4DW1...",
    "walletAddress": "4A2Btest..."
  }'

2️⃣ Robot Requests Recharge (x402)

When battery < 15%, the robot sends:
bash

curl -X GET "http://localhost:10003/api/robot/ricarica?robotId=robot_001&amount=0.01"

Gateway responds with 402 Payment Required:
json

{
  "status": "payment_required",
  "amount": 0.011,
  "fee": 0.0002,
  "boscoFee": 0.0008,
  "address": "4A2B...address...",
  "memo": "Ricarica robot robot_001"
}

3️⃣ Payment is Made

    90% → Robot owner

    2% → MyZubster

    8% → Bosco Community Fund

4️⃣ Robot Charges

Gateway confirms the payment and the robot recharges.
📊 The Flow (Visual)
text

┌──────────┐     ┌───────────────┐     ┌──────────────┐
│  Robot   │     │    Gateway    │     │  Monero RPC  │
│  ESP32   │     │   Node.js     │     │   Wallet     │
└──────────┘     └───────────────┘     └──────────────┘
     │                   │                      │
     │ 1. Battery < 15%  │                      │
     │──────────────────▶│                      │
     │                   │                      │
     │ 2. GET /ricarica  │                      │
     │──────────────────▶│                      │
     │                   │                      │
     │ 3. 402 Payment    │                      │
     │◀──────────────────│                      │
     │                   │                      │
     │ 4. Payment to     │                      │
     │    Subaddress     │─────────────────────▶│
     │                   │                      │
     │ 5. Confirm        │◀─────────────────────│
     │◀──────────────────│                      │
     │                   │                      │
     │ 6. Recharge 100%  │                      │
     │──────────────────▶│                      │
     │                   │                      │

🛠️ ESP32 Sketch

Here's the core Arduino/ESP32 code that makes it work:
cpp

// x402_robot.ino - Core robot logic

void loop() {
  // 1. Read battery
  batteryLevel = readBattery();

  // 2. If low battery → request recharge
  if (batteryLevel < BATTERY_LOW) {
    requestRecharge();
  }

  // 3. Check payment status
  checkPaymentStatus();

  delay(5000);
}

void requestRecharge() {
  HTTPClient http;
  String url = GATEWAY_URL + "/api/robot/ricarica?robotId=" + robotId + "&amount=0.01";
  http.begin(url);

  int code = http.GET();

  if (code == 402) {
    // Payment Required!
    String response = http.getString();
    // Parse JSON, get address and amount
    // Simulate payment (or use wallet SDK)
    simulatePayment(address, amount);
  }

  http.end();
}

🚀 Quick Start
Prerequisites

    Docker & Docker Compose

    ESP32 (or any WiFi-enabled Arduino)

    Monero testnet wallet (optional)

1. Clone the Repository
bash

git clone https://github.com/MyZubster-Ecosystem/MyZubster-Robot-Stack.git
cd MyZubster-Robot-Stack

2. Start the Gateway
bash

docker-compose up -d

3. Test the API
bash

curl http://localhost:10003/

Expected Response:
json

{
  "name": "MyZubster Gateway",
  "version": "1.0.0",
  "status": "running",
  "endpoints": {
    "monero": "/api/monero",
    "payments": "/api/payments",
    "robot": "/api/robot",
    "bounties": "/api/bounties"
  }
}

4. Upload to ESP32

    Open arduino/x402_robot.ino in Arduino IDE

    Set your WiFi credentials

    Upload to ESP32

    Open Serial Monitor (115200 baud)

📡 API Endpoints
Method  Endpoint    Description
POST    /api/robot/register Register a new robot
GET /api/robot/ricarica Request payment (x402)
GET /api/robot/:robotId Get robot info
POST    /api/robot/:robotId/location    Update GPS position
POST    /api/robot/clone    Clone robot with referral
POST    /api/payments/create-order  Create payment order
GET /api/payments/status/:orderId   Check payment status
POST    /api/bounties/webhook   GitHub webhook for bounties
🔗 GitHub Webhook Setup

    Go to your repository → Settings → Webhooks

    Add webhook:

        Payload URL: http://YOUR_SERVER:10003/api/bounties/webhook

        Content type: application/json

        Events: Issues, Issue comment

Now when you add a bounty label to an issue, the gateway automatically:

    Creates a payment order

    Adds a comment with the Monero address

    Waits for payment

    Updates the issue status

📊 Fee Distribution
text

┌─────────────────────────────────────────────────────────────┐
│                     Payment: 0.01 XMR                       │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
│  │  90% Owner  │  │   2% Fee    │  │    8% Bosco        │ │
│  │  0.009 XMR  │  │ 0.0002 XMR │  │   0.0008 XMR       │ │
│  └─────────────┘  └─────────────┘  └─────────────────────┘ │
│                    │                    │                    │
│                    ▼                    ▼                    │
│              MyZubster           Community Fund             │
│              Maintenance         Bosco Comune               │
└─────────────────────────────────────────────────────────────┘

🔬 Technical Stack
Component   Technology  Version
Gateway Node.js + Express   20.x
Database    MongoDB 6.x
Payment Protocol    x402    Standard
Cryptocurrency  Monero  0.18.x
Robot   ESP32 / Arduino -
Container   Docker  Latest
Process Manager PM2 Latest
Reverse Proxy   Nginx   Latest
📚 Full Documentation

    GitHub Repository

    API Reference

    Setup Guide

    Robot Guide

🤝 Contributing

We welcome contributions from the community!

    Fork the repository

    Create a feature branch

    Commit your changes

    Open a Pull Request

Check our Good First Issues
📄 License

GPL-3.0 License – see LICENSE file.
🌐 Links

    Repository: MyZubster-Robot-Stack

    Ecosystem: MyZubster

    DEV.to: @danielioni

    Twitter/X: @MyZubster

💬 Questions?

Drop a comment below or open an issue on GitHub! 👇

Built with ❤️ by Daniel Ioni & the MyZubster Community

#monero #robotics #iot #opensource #web3 #myzubster #arduino #esp32 #blockchain
Enter fullscreen mode Exit fullscreen mode

Top comments (0)