MX402 Exchange is a MultiversX-native pay-per-API marketplace. It lets API publishers monetize endpoints with on-chain EGLD settlement, while consumers pay only for what they use.
This repository is the working MVP codebase for the product.
Most APIs are sold through subscriptions, credit cards, and centralized billing. That model creates friction for:
- builders with bursty or low-volume usage
- on-chain applications and agents that need machine-payable access
- global developers who want programmable settlement instead of recurring SaaS plans
MX402 Exchange introduces a different model:
- publishers list APIs with fixed per-call pricing
- buyers fund a MultiversX balance in EGLD
- requests are metered through a gateway
- usage is settled on-chain in batches through a MultiversX smart contract
The result is a practical pay-per-call marketplace with blockchain-native settlement and developer-friendly consumption flows.
MX402 is designed around MultiversX as the value and settlement layer:
- EGLD is used for funding and settlement
- wallet-native login and transaction signing are built into the user flow
- provider earnings are claimable on-chain
- settlement batches are verifiable through the MultiversX Devnet explorer
This makes the product more than a generic API catalog with crypto branding. The payment and settlement mechanics are part of the product core.
Public app:
Live public surfaces:
- marketplace UI
- provider publish flow
- admin moderation flow
- buyer dashboard and wallet screens
- hosted API proxy
- hosted gateway proxy
- hosted worker trigger
Useful live endpoints:
- Products: https://mx402-exchange.vercel.app/__mx402_api/v1/products
- Gateway health: https://mx402-exchange.vercel.app/__mx402_gateway/health
The current MVP includes:
- provider profile creation and product publishing
- admin approval and product activation
- buyer wallet-backed authentication
- deposit preparation and deposit indexing
- project creation, API key issuance, and access grants
- paid API execution through a metering gateway
- usage receipts
- batched on-chain settlement
- provider earnings tracking and claim flow
The current implementation uses:
- on-chain payment and settlement on MultiversX
- off-chain request metering and usage accounting
- batched settlement for practical throughput
MX402 has already been validated on MultiversX Devnet with separate owner, provider, and buyer wallets.
Validated flow:
- Provider created and approved
- Product created, submitted, and activated
- Buyer deposited EGLD
- Buyer executed a paid call
- Usage was settled on-chain
- Provider claimed earnings on-chain
Detailed run report:
Ledger contract used in devnet validation:
erd1qqqqqqqqqqqqqpgqe00lpfaeprevlmj2fj2eezygrp7ljy2dtqsqndmsz6
A full buyer flow was also executed against the public Vercel deployment.
Hosted flow covered:
- public Native Auth login
- public deposit preparation
- real EGLD deposit on Devnet
- hosted deposit tracking
- hosted worker sync
- buyer project creation
- API key creation
- product grant
- paid gateway call
- receipt retrieval
Public hosted buyer flow artifacts:
- Buyer deposit tx: 717638f50809d08db89e0860a37904ce501ac634d7e4210f56bfb26d2ae8f14c
- Receipt id:
rcpt_5f15ac01d9be3089170b - Product used:
xexchange-price-feed - Charged amount:
0.0001 EGLD
That receipt was then settled on Devnet in a confirmed batch:
- Batch id:
mx402-20260322124714-ccca545e - Settlement tx: 2969b162a9c08d70bffe94e724a0c4a7c2496aa50a49eff04c65b1d675141afe
MX402 is organized as a monorepo with a clear separation between user-facing product flows, gateway execution, and on-chain settlement.
-
apps/web
Next.js frontend for marketplace browsing, publish flow, admin flow, wallet, analytics, and dashboards -
apps/api
Core marketplace API for authentication, providers, products, projects, balances, usage, and admin operations -
apps/gateway
Paid-call execution layer that authenticates API keys, meters usage, forwards requests upstream, and issues receipts -
apps/worker
Background settlement runtime for deposit sync, settlement batch submission, and provider claim confirmation
contracts/mx402-ledger
MultiversX smart contract handling deposits, batched settlement accounting, and provider claims
packages/configpackages/dbpackages/domainpackages/multiversxpackages/observability
- Next.js 14
- TypeScript
- Fastify
- Prisma
- PostgreSQL
- MultiversX SDKs
- MultiversX Rust smart contracts
- Vercel for frontend and hosted runtime entry points
- Neon for managed database infrastructure
- Create provider profile
- Create product draft
- Configure endpoint, pricing, and auth
- Submit for review
- Admin approves and activates product
- Product becomes callable through MX402
- Connect wallet and authenticate
- Deposit EGLD
- Create a buyer project
- Generate an API key
- Grant a product to the project
- Make a paid API call
- Receive a usage receipt
- Charged usage events accumulate off-chain
- Worker prepares a settlement batch
- Batch is submitted on-chain
- Batch confirmation updates platform state
- Provider claims earnings from the contract
Core design and implementation references:
Validation reference:
apps/apiapps/gatewayapps/workerapps/webcontracts/mx402-ledgerpackages/*
npm installnpm run buildnpm run dev:api
npm run dev:gateway
npm run dev:worker
npm run dev:webPush the Prisma schema:
npm run db:pushNode services auto-load .env and .env.local by walking upward from the current working directory.
Browser login and wallet flows should use public MultiversX endpoints:
NEXT_PUBLIC_MULTIVERSX_API_URLNEXT_PUBLIC_MULTIVERSX_WALLET_URLNEXT_PUBLIC_MULTIVERSX_EXPLORER_URL
Server-side chain reads can use dedicated endpoints:
MULTIVERSX_CHAIN_API_URLMULTIVERSX_CHAIN_GATEWAY_URLMULTIVERSX_CHAIN_API_KEYMULTIVERSX_CHAIN_EVENTS_URL
Required environment for products using static upstream auth:
MX402_PROVIDER_SECRET_ENCRYPTION_KEY
Deploy the ledger contract:
npm run deploy:devnet:ledgerRun the full devnet scenario:
npm run scenario:devnet:realTypical required variables for a real devnet run:
MX402_OWNER_PRIVATE_KEYMX402_PROVIDER_PRIVATE_KEYMX402_BUYER_PRIVATE_KEYMX402_LEDGER_CONTRACT
The product is already beyond concept stage and into validated MVP territory, but the remaining polish areas are:
- fully browser-only repeatable demo flow without helper scripts
- cleaner provider payout and claim UX
- stronger operational monitoring and settlement visibility
- production-grade infrastructure hardening for all background jobs
- broader set of real third-party provider integrations beyond the demo provider layer
No open-source license has been attached to this repository yet.