On this page
How it works
Architecture
The Worker, one Durable Object for each collection's book, the registry, settings, R2 for pictures, the sync loop, the pool refresh, and a request's path from browser to book.
The parts#
A marketplace is one Cloudflare Worker in your account, with these parts. The books, sync loop and registry described here are Ethereum's; on Ink, listings made on your site are kept in R2 and checked when a page of them is read (see the Ink API).
| Part | What it is | What it holds |
|---|---|---|
| The Worker | The code that answers every request | Your secrets, and what it may keep between requests, such as the placement record it read |
| A book for each collection | A SQLite Durable Object (BOOK) |
That collection's listings, offers, pool quotes, traits, floor history and the orders made on your site |
| The registry | A SQLite Durable Object (REGISTRY) |
The list of collections, with each one's floor and best offer, for the home page |
| Settings | SQLite Durable Objects (SETTINGS) |
The chosen settings object holds your stored settings record and where each object was placed; separately named objects hold each visitor's admin token tries |
| Pictures | An R2 bucket (MEDIA) |
NFT pictures and metadata, and the small placement record |
| Images | Cloudflare Images (IMAGES) |
Nothing: it resizes large pictures |
The server builds transactions; it never signs or sends one, and it holds no wallet key that could.
The sync loop#
Each book runs its own sync inside its Durable Object, on its own alarm:
- It reads the market: OpenSea listings and collection offers (with your key), and the orders made on your site.
- It applies what changed and tells open pages over a WebSocket.
- It commits the pool quotes it holds, so a pool that has gone thin is left out of the floor and the sweep.
- It reports its floor and best offer to the registry.
- It checks the health of the orders made on your site.
- It starts the pool refresh in the background, and reads traits.
A listing read never waits on NFTX. The pool refresh runs on its own, with a 50 second deadline, and reads each NFTX V2 and V4 pool's inventory and the cost of buying one, two, three or more NFTs from it. Each pool quote is valid for a few minutes. The refresh can time out or fail: an expired quote cannot supply a current floor or sweep price, and a replacement may not be there yet.
There is no scheduled trigger. A page view starts or restarts a book's alarm, and the first read of a collection starts in the background when settings are stored.
A request's path#
A visitor opens a collection page:
browser ──GET /c/<collection>──▶ Worker
│ reads the placement record (it may keep it) and the chosen settings object
├─▶ the collection's book (Durable Object): the items, prices, offers
├─▶ R2: picture addresses
▼
HTML, with no inline script
browser ──GET /v1/collections/1/<address>/items──▶ Worker ──▶ book
browser ◀──WebSocket──────────────────────────────── book (changes as they happen)A shopper buys:
browser ──POST …/purchases/quote──▶ Worker ──▶ OpenSea (fulfilment details, your key)
──▶ RPC: simulate the purchase from the buyer's account
browser ◀── the transaction to sign
wallet ──signs and sends──▶ the chain
browser ──▶ wallet provider: the transaction, its block and its receipt
browser: checks the call and counts the NFT transfers to the buyerOn Ethereum the receipt is checked in the browser, through the shopper's wallet provider. On Ink, OpenSea checkout uses your site's receipt route.
The live updates are the book stream.
The API reference lists every route.
Where each object lives#
A Durable Object stays where it is first created. At the claim, the template measures candidates and keeps the first that answers within 40 ms, or else the fastest measured in time; it measures time to answer, not distance. See Where storage lives.
The data it reads#
| Source | Read with | For |
|---|---|---|
| OpenSea's API | Your OPENSEA_API_KEY |
Listings, collection offers, offers on one NFT, purchase details |
| NFTX's API and the chain | No key | Pool inventory and quotes |
| The chain | Your RPC_URL, or the shared public RPC |
Ownership, royalties, simulations, receipts, activity |
| Token metadata hosts and IPFS gateways | No key | Pictures and traits |
Activity (sales, mints, transfers) is read from the chain, never from OpenSea's API.