DEV Community

Daniel Ioni
Daniel Ioni

Posted on

πŸš€ Building a Gateway for $MYZ Payments with Tari Ootle and x402

πŸš€ Building a Gateway for $MYZ Payments with Tari Ootle and x402

I recently built a payment gateway for my project MyZubster, a decentralized marketplace where robots perform tasks and get paid in a custom token ($MYZ).

The goal was simple: users pay in XMR, get $MYZ, and robots are paid via escrow.

In this guide, I’ll walk through the architecture, the key components, and how you can build something similar.


🧱 The Stack

Layer Technology
Token Tari Ootle (Confidential Assets, Rust)
Escrow Custom Rust template on Tari
Gateway Node.js + Express
Simulation In‑memory token and escrow for testing

⚠️ This guide uses simulation for the Tari and Monero layers. You can replace them with real RPC calls when ready.


πŸͺ™ The Token: $MYZ

The token is a Confidential Asset on Tari Ootle. It’s minted via a Rust template with only three methods:

  • mint(to, amount)
  • transfer(from, to, amount)
  • balance(address)

The smart contract is minimal, no dependencies, and compiles to WASM.


rust
#[template]
pub struct MyzToken {
    balances: HashMap<ComponentAddress, Amount>,
    total_supply: Amount,
}

impl MyzToken {
    pub fn mint(...) { ... }
    pub fn transfer(...) -> Result<(), String> { ... }
    pub fn balance(...) -> Amount { ... }
}
πŸ” The Escrow: 2‑of‑3 with Proof

The escrow contract allows:

    lock_funds – buyer locks $MYZ

    submit_proof – seller sends a proof hash

    release – buyer approves and funds are transferred

    dispute – if proof is invalid

This is implemented as a Tari template in Rust. For testing, it’s simulated in Node.js.
βš™οΈ The Gateway API

The Node.js Express gateway exposes:
Endpoint    Description
POST /buy-myz   User sends XMR (simulated), gets $MYZ
POST /escrow/create Create a new escrow
POST /escrow/lock   Lock buyer's funds
POST /escrow/proof  Seller submits proof hash
POST /escrow/release    Buyer releases funds
POST /escrow/dispute    Raise a dispute
GET /balance/:address   Check wallet balance

The simulation uses in‑memory maps, so you can test the entire flow without a real Tari node.
πŸ§ͺ Testing the Flow

Here’s a full test using curl:
bash

# 1. Buy 50 MYZ
curl -X POST http://localhost:3002/buy-myz \
  -H "Content-Type: application/json" \
  -d '{"userTariWallet":"wallet_user1","amountMYZ":50}'

# 2. Create escrow
curl -X POST http://localhost:3002/escrow/create \
  -H "Content-Type: application/json" \
  -d '{"escrowId":"escrow_001","buyer":"wallet_user1","seller":"wallet_robot1","amount":30}'

# 3. Lock funds
curl -X POST http://localhost:3002/escrow/lock \
  -H "Content-Type: application/json" \
  -d '{"escrowId":"escrow_001","payer":"wallet_user1","amount":30}'

# 4. Submit proof
curl -X POST http://localhost:3002/escrow/proof \
  -H "Content-Type: application/json" \
  -d '{"escrowId":"escrow_001","proofHash":"hash_della_foto"}'

# 5. Release
curl -X POST http://localhost:3002/escrow/release \
  -H "Content-Type: application/json" \
  -d '{"escrowId":"escrow_001","caller":"wallet_user1"}'

# 6. Check robot balance
curl http://localhost:3002/balance/wallet_robot1

The robot receives the funds automatically after release.
πŸ“ Project Structure
text

myzubster-gateway/
β”œβ”€β”€ server.js              # Express API
β”œβ”€β”€ buy_myz.js             # XMR β†’ $MYZ simulation
β”œβ”€β”€ escrow_simulator.js    # Escrow logic
β”œβ”€β”€ token_simulator.js     # In‑memory token balances
β”œβ”€β”€ test_simulator.js      # Unit test
└── package.json           # Dependencies

πŸš€ Next Steps

    Replace simulations with real Tari RPC – use grpcurl or tari-cli.

    Add a Monero webhook – listen for real XMR payments.

    Connect the Marketplace – point the frontend to this gateway.

    Deploy on a public server – for production use.

πŸ“¦ Resources

    Tari Ootle Documentation

    Tari Template Library on crates.io

    MyZubster Gateway Repo

πŸ’¬ Final Thought

Building a payment system with Tari Ootle and a custom token is surprisingly straightforward. The separation of the Rust contract from the Node.js gateway makes the system clean and maintainable.

If you're building a decentralized marketplace or robot‑based economy, this stack is worth exploring.

#Tari #Rust #NodeJS #Escrow #Blockchain #MyZubster
Enter fullscreen mode Exit fullscreen mode

Top comments (0)