π 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

Top comments (0)