FreshMarket

Second-hand marketplace: listings owned on Arkiv, USDT checkout on Whitechain, ENS seller names

FreshMarket

Created At

ETHGlobal Mumbai

Project Description

FreshMarket is a second-hand marketplace where sellers own their listings, buyers pay in stablecoins, and reviews come only from people who actually bought something.

The problem. On today's marketplaces, sellers re-post the same item on every site, sold and abandoned listings stay up for weeks, the platform owns all the data, and anyone can leave a fake review.

How FreshMarket solves it, using three networks:

  1. Listings on Arkiv (Rabdi testnet). Every listing is an Arkiv entity owned by the seller's wallet. Only that wallet can edit it, reserve it, mark it sold, extend it or delete it. The seller chooses how long it lives (15 minutes for demos, up to 30 days), and when it expires it disappears from every app with no cleanup job. Search uses Arkiv's indexed fields (category, brand, model, city, price range, condition, delivery), so buyers can browse without connecting a wallet. To show the data isn't locked into our app, SECOND LOOK, a separate static storefront with its own Arkiv client and none of our code, reads the same listings.

  2. Payments with USDT on Whitechain (Sepolia). Buyers click "Buy now with USDT" and pay through FreshPay, our verified escrow contract. It allows one paid order per listing, so two buyers can't pay for the same item, and it holds the payment until the buyer confirms the item arrived, or a hold period passes. The seller can refund all or part of it, and the refund goes straight back to the buyer's wallet. Payments are verified from the chain, never from what the browser reports. Sellers get a payments dashboard and buyers get a receipt page. The checkout is a reusable React widget and SDK that another app can embed in about 20 lines (live at /checkout-demo).

  3. Seller identity with ENSv2 (Ethereum Sepolia). We own freshmarket.eth, run our own subname registry, and give each seller a name like alice.freshmarket.eth with its own Permissioned Resolver, so sellers fully control their profile records. Using Enhanced Access Control, a seller can let a shop manager edit one specific text record and revoke that right later. A listing shows a seller's name only if it resolves back to the wallet that owns the listing.

Reviews tied to real purchases. After a FreshPay order is released or refunded, the buyer can write a review. It's stored on Arkiv as a record the buyer owns, and it cites the FreshPay order number. A review counts toward a seller's rating only if that order on Whitechain names the same buyer and seller, so fake reviews are filtered out automatically.

Live on testnets now. Realistic listings from several sellers across Mumbai, Pune and Bengaluru; real USDT orders including a partial refund; verified buyer reviews; and ENS registration, delegation and revocation transactions. Every transaction is linked in the README.

Tech. Next.js, TypeScript, wagmi/viem, the Arkiv SDK, Solidity with Foundry (FreshPay contract, tests and a fork test against the real USDT), and ENSv2 contracts on Sepolia. The code is open source under the MIT license.

How it's Made

Stack. Next.js 16 (App Router), React 19 and TypeScript, Tailwind, wagmi + RainbowKit + viem for wallets, TanStack Query for caching, Vitest and Testing Library for app tests, and Foundry for the Solidity contract. The second storefront, SECOND LOOK, is a separate static Vite build. Deployed on Vercel.

Three chains, each doing one job. Arkiv Rabdi stores listings and reviews, Ethereum Sepolia (ENSv2) stores seller identity, and Whitechain Sepolia settles USDT payments. Each chain gets its own read client and transport, and none of them reads the wallet's active network. So an ENS or Whitechain outage, or a user switching networks, never breaks Arkiv browsing. Each page declares the chain it needs, and the navbar badge switches the wallet only when the user clicks it.

Arkiv. We defined a freshmarket.listings.v2 schema with the Arkiv SDK, using 10 indexed attributes so every search is a single indexed query instead of a client-side scan:

  • Price is a u64 in USDT minor units (6 decimals), so price ranges are range queries on the chain.
  • Categories are paths like pets/dogs/toys, so startsWith selects a whole branch. A small resolver maps free text, spacing and typos ("dogtoy", "dgo toy") to category paths.

The repository validates every row it reads (seller must equal $owner, enums must be known values), because anyone can write the same schema tag. Expiry is a block height, and extending reads the current deadline and sets a new one. The UI never retries a wallet write, and it waits out indexing lag before refreshing. The wallet's Rabdi connection deliberately carries no access key, so the key never reaches the wallet; public reads use an origin-restricted key. Arkiv's ownership model is what makes the marketplace portable: SECOND LOOK reads the same entities with its own client and zero FreshMarket code.

ENSv2. We own freshmarket.eth and deployed our own UserRegistry proxy through ENS's VerifiableFactory, then attached it as the subregistry. Each seller gets a dedicated PermissionedResolver proxy. Because Enhanced Access Control resources are scoped by record key, not by name, a resolver per seller is what stops a delegate from touching other storefronts. Sellers grant ROLE_SET_TEXT on the resource keccak256("freshmarket.description") to a shop manager and can revoke it. A name is shown only after reverse lookup, then forward resolution back to the same wallet, matched against the listing's Arkiv $owner. We pinned the ENSv2 Sepolia deployment and tested delegation against the real resolver bytecode with eth_simulateV1.

Whitechain: the FreshPay contract. Solidity 0.8.28 with OpenZeppelin SafeERC20 and ReentrancyGuard, and no admin keys:

  • Order IDs are sequential u64 values so they fit the orderId field of our Arkiv review schema; that's the cross-chain proof of purchase.
  • activeOrder[merchant][ref] uses the Arkiv entity key as the reference, which gives every listing an atomic "stock of one" across all storefronts. Arkiv data alone can't enforce that.
  • A quote deadline stops a stale checkout page from paying an old price.
  • A balance-delta check rejects fee-on-transfer tokens.
  • Escrow holds funds until the buyer confirms or a hold period passes. Partial refunds come from escrow, or from the seller after release.

It has 21 unit and fuzz tests, plus fork tests against the official USDT on an Anvil fork of Whitechain. It's deployed and verified through Foundry's Blockscout verifier.

Reusable checkout. src/freshpay/ is self-contained (it imports only react, viem and wagmi): a hook and widget that switch network, approve the exact amount, simulate before asking for a signature, pay, and then verify the order from the receipt and contract state, never from what the browser reports. There are also signed webhooks (HMAC-SHA256, idempotency keys, an outbox with a cursor and exponential backoff), tested for crash recovery.

Notable hacks:

  • Getting official test USDT. There's no faucet, and the docs list a different token. We traced the official USDT's owner to a USDTBridge contract, found a Uniswap V3 WWBT/USDT pool on Whitechain Sepolia, and swapped our own WBT through SwapRouter02 to get the USDT for real payments.
  • Log history. Whitechain's RPC caps eth_getLogs at 10,000 blocks (under 3 hours), so order history comes from the Blockscout logs API, with a chunked RPC fallback.
  • Live demo data. Seeded through opt-in Vitest scripts that reuse the app's own repositories. They're resumable from an evidence file and detect writes whose receipts were lost to rate limits, so nothing is posted twice.
  • Proving a failed edit. Wallets won't broadcast a transaction that will revert, so we prove "a revoked delegate can't edit" with a read-only eth_call against the live resolver (npm run verify:ens-delegation).
  • Reviews checked across chains. Each Arkiv review is checked against its Whitechain order, so ratings count only real, settled purchases.
background image mobile

Join the mailing list

Get the latest news and updates