scaffold-hbar-metered-mcp
Meters MCP tool calls with HBAR payments on Hedera testnet, verifies transfers against the Hedera mirror node, and writes tamper-evident usage receipts to Hedera Consensus Service (HCS) topics.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@scaffold-hbar-metered-mcpcheck the HBAR balance of testnet account 0.0.123"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
scaffold-hbar-metered-mcp
A metered MCP server on Hedera. Every MCP tool call settles in HBAR on Hedera testnet, and every paid call writes a tamper-evident usage receipt to an HCS topic.
This template meters MCP tool calls directly. It is intentionally different from per-request HTTP payment schemes: the client sends a small HBAR transfer to the configured treasury account, calls the tool with the payment transaction id, the server verifies the transfer against the Hedera testnet mirror node, executes the tool, and logs an HCS receipt.
What is inside
packages/nextjs: Next.js app with an MCP route atapp/api/mcp/route.ts(built on@modelcontextprotocol/sdk), a receipt feed atapp/api/receipts/route.ts, and a setup-flow home page.packages/hardhat: kept from the scaffold-hbar baseline (HTS demo contracts, compile and tests pass). No new contract was added: metering settles in native HBAR and receipts live on HCS, so an on chain registry would add deploy cost without changing trust. The server still verifies every payment against the mirror node.template.json: manifest forcreate-scaffold-hbar0.4.1..env.example: all configuration. No.envis committed, ever.
Tools exposed by the MCP route:
Tool | Cost | What it does |
| free | Liveness check, no payment needed |
| paid | HBAR balance of a testnet account via the mirror node |
| paid | Recent messages of a testnet HCS topic via the mirror node |
| paid | Returns your message with its length |
Related MCP server: x402-gateway-mcp
Prerequisites
Node.js 20.18.3 or later
Yarn (this repo uses Yarn workspaces) or npm if you scaffolded with the CLI
A Hedera testnet account with a little testnet HBAR (see setup)
Quickstart
yarn install
cp .env.example .env
# edit .env: set METER_TREASURY_ACCOUNT to your testnet account
yarn next:startOpen http://localhost:3000 and follow the setup flow: configure, try the free ping, pay for a metered call, view recent receipts.
How metering works
GET /api/mcpadvertises the treasury account, the price per call in tinybar, and the tool list.The client sends
priceTinybar(default 10000) in HBAR to the treasury on Hedera testnet, from any wallet. No facilitator, no API keys.The client calls
POST /api/mcpwith{ tool, params, paymentTxId }.The server fetches the transaction from the testnet mirror node (
https://testnet.mirrornode.hedera.com), checks the result isSUCCESS, the timestamp is under 30 minutes old, and the treasury was credited at least the price. Mirror node reads need no operator key.Unpaid, unknown, insufficient, stale, or already spent transaction ids are rejected (
402 PAYMENT_REQUIRED,409 PAYMENT_ALREADY_SPENT, and friends). Each payment works exactly once; the spent registry is in memory, which is fine for the template.On success the server runs the tool and records a receipt
{ tool, payer, amount, paymentTxId, timestamp }.
Testnet setup
Create a testnet account at portal.hedera.com and fund it from the faucet.
Put that account id in
METER_TREASURY_ACCOUNT. This is the account your users pay.Optional but recommended: create an HCS topic for receipts and set
HCS_RECEIPT_TOPIC_ID. WithHEDERA_OPERATOR_IDandHEDERA_OPERATOR_KEYset, each paid call submits its receipt to that topic. Without them, receipts are logged and kept in memory and everything else still works. Never commit keys.
How to verify receipts on Hashscan
Payments:
https://hashscan.io/testnet/transaction/<paymentTxId>Receipt topic:
https://hashscan.io/testnet/topic/<topicId>Payer accounts:
https://hashscan.io/testnet/account/<accountId>
The home page links every receipt to HashScan. A real testnet payment plus HCS receipt is the bounty proof item; it needs a funded testnet account from the faucet, which is a human step.
API shape
# Manifest and pricing
curl http://localhost:3000/api/mcp
# Free tool
curl -X POST http://localhost:3000/api/mcp \
-H 'content-type: application/json' \
-d '{"tool":"ping","params":{}}'
# Paid tool (after sending HBAR to the treasury)
curl -X POST http://localhost:3000/api/mcp \
-H 'content-type: application/json' \
-d '{"tool":"account_balance","params":{"accountId":"0.0.123"},"paymentTxId":"0.0.123@1727712000.123456789"}'
# Receipt feed
curl http://localhost:3000/api/receiptsScripts
yarn install # install all workspaces
yarn lint # lint nextjs and hardhat
yarn next:build # production build of the frontend
yarn next:start # dev server at http://localhost:3000
yarn hardhat:compile
yarn hardhat:testLinks
This server cannot be deployed
Maintenance
Related MCP Connectors
Metered MCP tools: free discovery over MCP; per-call execution settled in USDC via x402 v2.
Paid MCP tools behind one endpoint. Agents pay per call in USDC on Base via x402.
Pay-per-action access to APIs and MCP tools over Lightning L402 and Base USDC x402.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Related MCP Servers
- AlicenseAqualityBmaintenanceProduction MCP server giving AI agents metered access to live Hedera blockchain data. Query token prices, screen identities, monitor governance, write tamper-evident HCS compliance records, and analyze smart contracts — all paid in HBAR micropayments per call.2050 npmAcademic Free v1.1
- AlicenseAqualityFmaintenanceEnables MCP clients to access all endpoints of an x402 gateway by paying real-time microtransactions (USDC on Base) per API call, with automatic tool discovery and spend guardrails.2340 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP tools to be gated behind per-call USDC micropayments with direct on-chain verification and settlement, removing the need for third-party payment facilitators.MIT
- AlicenseNot gradedqualityBmaintenanceAn MCP server that charges real testnet USDC per tool call using x402 pay-per-request protocol, transparently handled by a paying proxy for any standard MCP client.2MIT