DEV Community

Daniel Ioni
Daniel Ioni

Posted on

🤖 How We Built a Robot Payment System with Monero

🤖 How We Built a Robot Payment System with Monero

TL;DR: We built a complete payment system where robots can request payments using the x402 protocol, pay in Monero, and even clone themselves with a referral system. Here's how.


🎯 The Vision

Imagine this:

  • A lawn mower robot finishes its battery → requests payment
  • A farmer pays 0.01 XMR → robot charges
  • The robot's owner earns 90%, MyZubster takes 2%, and 8% goes to a community fund

This is now a reality.


┌─────────────────────────────────────────────────────────────┐
│ Robot API Layer │
http://localhost:10002
├─────────────────────────────────────────────────────────────┤
│ /register │ Register a new robot │
│ /ricarica │ Request payment (x402) │
│ /:robotId │ Get robot info │
│ /location │ Update GPS position │
│ /clone │ Clone robot with referral │
├─────────────────────────────────────────────────────────────┤
│ Monero Integration │
│ Subaddress generation │
│ Fee: 2% (MyZubster) + 8% (Bosco) │
├─────────────────────────────────────────────────────────────┤
│ MongoDB Database │
│ Robots, Users, Bounties │
└─────────────────────────────────────────────────────────────┘
text


💰 The Payment Flow (x402)

The x402 protocol enables robots to request payments with automatic fee calculation.

1️⃣ Register a Robot


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

Response:
json

{
  "success": true,
  "robot": {
    "id": "robot_001",
    "name": "Tagliaerba 3000",
    "type": "lawn_mower",
    "walletAddress": "4A2Btest1234567890"
  }
}

2️⃣ Robot Requests Payment (x402)

The robot requests a recharge with automatic fee calculation:
bash

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

Response (402 Payment Required):
json

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

Breakdown:

    0.01 XMR → Robot recharge amount

    0.0002 XMR → 2% MyZubster fee

    0.0008 XMR → 8% Bosco community fund

    Total: 0.011 XMR

3️⃣ Payment Confirmation

When the farmer sends XMR to the address, the gateway automatically:

    Detects the payment

    Confirms the transaction

    Updates the robot's battery level

    Distributes fees (90% to owner, 2% MyZubster, 8% Bosco)

🔄 Clone System with Referral

Robots can clone themselves, and the original owner earns 5% of the clone's fees for 1 year.
Clone a Robot
bash

curl -X POST http://localhost:10002/api/robot/clone \
  -H "Content-Type: application/json" \
  -d '{
    "originalId": "robot_001",
    "newId": "robot_002",
    "name": "Tagliaerba 2",
    "owner": "45M4DW1...newOwner..."
  }'

Response:
json

{
  "success": true,
  "robot": {
    "id": "robot_002",
    "name": "Tagliaerba 2",
    "type": "lawn_mower",
    "walletAddress": "4A2B5hvkw6wkrobot_",
    "referrer": "45M4DW1..."
  }
}

What happens:

    ✅ New robot created with unique wallet

    ✅ Original owner stored as referrer

    ✅ 5% of fees go to referrer for 1 year

    ✅ Skills copied from original robot

📊 API Endpoints Summary
Endpoint    Method  Description Status
/api/robot/register POST    Register a new robot    ✅ Live
/api/robot/ricarica GET Request payment (x402)  ✅ Live
/api/robot/:robotId GET Get robot details   ✅ Live
/api/robot/:robotId/location    POST    Update GPS position ✅ Live
/api/robot/clone    POST    Clone robot with referral   ✅ Live
🛠️ Tech Stack
Component   Technology
API Gateway Node.js + Express
Database    MongoDB
Payment Protocol    x402
Cryptocurrency  Monero (XMR)
Container   Docker
Process Manager PM2
Reverse Proxy   Nginx
💡 How It Works in Production
Real Scenario

    Robot reaches 10% battery

    Robot sends API request to /api/robot/ricarica

    Gateway returns subaddress + fee breakdown

    Farmer sends XMR to the address

    Gateway detects payment via wallet RPC

    Funds are distributed:

        90% → Robot owner

        2% → MyZubster

        8% → Bosco Community Fund

    Robot charges and continues working

Fee Distribution
javascript

const total = 0.01; // XMR
const ownerShare = total * 0.90; // 0.009 XMR
const myZubsterFee = total * 0.02; // 0.0002 XMR
const boscoFee = total * 0.08; // 0.0008 XMR

🔐 Security

    Subaddress generation for privacy

    Multisig escrow for dispute resolution

    JWT authentication for API endpoints

    Monero wallet RPC with secure connection

    Firewall configured with UFW

🚀 Future Roadmap

    □

    AI arbitration for disputes
    □

    Real-time monitoring with webhooks
    □

    Mobile app for robot owners
    □

    Smart contracts on Base/Polygon
    □

    Telegram bot for notifications
    □

    Analytics dashboard for performance

📦 Quick Start
bash

# Clone the repository
git clone https://github.com/DanielIoni-creator/myzubster.git
cd myzubster

# Start services
docker-compose up -d

# Test the gateway
curl http://localhost:10002/

🔗 Links

    Repository: MyZubster

    Gateway: MyZubsterGateway

    Wiki: MyZubster Wiki

    DEV.to: Follow me

💬 Questions?

Drop a comment below! 👇

Built with ❤️ by Daniel Ioni and the MyZubster Community

#monero #myzubster #robots #web3 #iot #payments #blockchain #opensource

## 🏗️ The Architecture

We extended the MyZubster gateway with a complete robot payment system:
Enter fullscreen mode Exit fullscreen mode

Top comments (0)