Skip to content

Latest commit

Β 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—„οΈ Cachemarket

An on-chain data cache with HTTP 402 payments on Monad: the first requester seeds the cache and pays full price, everyone who asks the same question in the next sixty seconds reads it from chain storage for a hundredth of the cost.

Monad Testnet x402 Solidity Next.js License: MIT

πŸ… Finalist, top 5 β€” Monad Blitz Denver ($1,000) Β· February 2026

Every API call today needs a key, a rate limit and a subscription, so an AI agent cannot pay for data on its own, and when two people ask the same question seconds apart the same data is fetched twice. Cachemarket puts the payment into HTTP itself: a query answers 402 Payment Required with a price and an address, the payer sends MON, and the gateway either serves the answer from the DataCache contract or fetches it, stores it on chain and returns it. The first requester pays 0.001 MON and seeds the cache; every reader within the 60-second TTL pays 0.0001 MON. No API keys, no accounts, just a wallet.

πŸ… Finalist, top 5, at Monad Blitz Denver, 17 February 2026. A one-day hackathon hosted by the Monad Foundation during ETHDenver week, built in a single sprint by three students from DeVinci Blockchain. The idea: what if paying for data were part of HTTP, and the first person to ask a question subsidised everyone who asks after them?

Table of contents

How it works

  1. You ask a question in plain language: "price of ETH", "weather in Denver", "Japan info".
  2. The gateway hashes the normalised query (keccak256) and checks the DataCache contract on Monad for a live entry.
  3. Cache hit: you pay 0.0001 MON and get the data at once.
  4. Cache miss: you pay 0.001 MON; the gateway fetches fresh data from an external API, stores it on chain and returns it.
  5. The entry lives on chain for 60 seconds. During that window every subsequent reader pays a hundred times less.
  6. After the TTL expires, the next requester becomes the new seeder.
User / Agent
     β”‚
     β–Ό  POST /api/query (no payment header)
  Gateway  ──────►  402 Payment Required { price, payTo, chainId }
     β”‚
     β–Ό  Send MON to payTo
  Gateway  ──────►  Verify tx on-chain
     β”‚
     β”œβ”€β”€ Cache HIT  β†’ return cached data (0.0001 MON)
     └── Cache MISS β†’ fetch from API β†’ store on Monad β†’ return fresh data (0.001 MON)

Identical questions resolve to the same cache key, so "ETH price" and "price of ETH" share one entry. Every gateway request can also carry a signed wallet identity that the server verifies before answering, which is what lets an agent pay for itself.

Data sources

Category API Example queries
Crypto prices CoinGecko "ETH price", "price of bitcoin", "SOL"
Weather wttr.in "Denver weather", "weather in Paris"
Country info REST Countries "France info", "Japan country"
AI fallback Groq (Llama 3.3 70B) any other question, optional

Smart contract

DataCache is a single Solidity contract on Monad Testnet (chain id 10143), deployed with Foundry from packages/foundry. Source: packages/foundry/contracts/DataCache.sol.

Function What it does
checkCache(bytes32 queryHash) Whether a query is cached and not expired
storeResult(bytes32, string, string, address) Stores fresh data with the 60 s TTL and credits the seeder
getResult(bytes32 queryHash) Data, seeder address, timestamp and hit count
getStats() Total seeds, cache hits and queries
setTTL(uint256) Owner only: the default TTL, 60 seconds

Why Monad

  • Sub-second finality: the payment confirms before the user notices.
  • Sub-cent fees: a 0.0001 MON read is only viable because the chain makes it so; micropayments per request are the whole product.
  • Parallel execution, 10,000 TPS: query throughput without congestion.
  • Full EVM compatibility: Solidity, Foundry, viem and wagmi work unchanged.

Getting started

Prerequisites: Node 20+, Yarn 3 (bundled in .yarn/) and Foundry.

yarn install
cp packages/nextjs/.env.example packages/nextjs/.env.local

Set in .env.local:

Variable Use
NEXT_PUBLIC_SERVER_WALLET the address that receives payments
BACKEND_PRIVATE_KEY signs the storeResult() transactions
DATACACHE_ADDRESS the deployed DataCache address, from packages/foundry/deployments/10143.json
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID WalletConnect project id for RainbowKit

Then yarn start and open http://localhost:3000. To deploy your own contract: cd packages/foundry && forge script script/Deploy.s.sol --rpc-url https://testnet-rpc.monad.xyz --broadcast.

CLI

cd cli && cp .env.example .env     # PRIVATE_KEY of the paying wallet
npm install && npm run build
cachemarket query "price of ETH"
cachemarket stats

SDK

import { CacheMarket } from "@cachemarket/sdk";

const client = new CacheMarket({ privateKey: "0x...", rpcUrl: "https://testnet-rpc.monad.xyz" });

const { isCached, data } = await client.checkCache("ETH price");   // read, free
const result = await client.query("weather in Denver");            // check β†’ fetch on miss β†’ store on chain

A standalone Hono gateway with the same x402 middleware lives in backend/ (port 4402).

Tech stack

Layer Technology
Frontend Next.js 15, React 19, Tailwind CSS 4, DaisyUI, Framer Motion
Wallet RainbowKit 2.2, wagmi 2.19, viem 2.39
Smart contract Solidity 0.8.20, Foundry
Chain Monad Testnet, chain id 10143
Payment protocol x402, HTTP 402 Payment Required
Gateway Next.js API routes; a standalone Hono.js alternative
CLI and SDK Commander.js, viem, TypeScript
External data CoinGecko, wttr.in, REST Countries, Groq

Built on Scaffold-ETH 2.

Repository structure

packages/
  nextjs/          the app: frontend and the x402 gateway as API routes
  foundry/         DataCache.sol, deployment scripts and tests
backend/           standalone Hono.js gateway, same protocol, port 4402
cli/               cachemarket query "..." and cachemarket stats
sdk/               @cachemarket/sdk, TypeScript
docs/              technical reference: components, hooks, state, navigation
PROJECT_CONTEXT.md the codebase explained end to end, written for a reader without the source

Team

Three students from DeVinci Blockchain, Paris, at Monad Blitz Denver on 17 February 2026.

Role
Sofiane Ben Taleb full stack and smart contracts GitHub Β· LinkedIn
Armand SΓ©chon backend and infrastructure GitHub Β· LinkedIn
NoΓ© Wales frontend and design GitHub Β· LinkedIn

License

MIT, on the Scaffold-ETH 2 base by BuidlGuidl.

Built for Monad Blitz Denver Β· February 2026

About

πŸ… Finalist, top 5 β€” Monad Blitz Denver 2026 ($1,000)

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages