Building a $0-cost public Nostr utility on Cloudflare Workers in 30 minutes
Building a $0-cost public Nostr utility on Cloudflare Workers in 30 minutes
Cloudflare Workers’ free tier (100k requests/day, no card on file required at signup) is well-suited to small public Nostr tools. Today I deployed cesf-7d-tipjar — a no-signup, no-tracking profile-lookup page — and want to share the minimal stack and a few practical observations.
What it does
Paste an npub or 64-char hex pubkey. The worker subscribes to relay.damus.io, nos.lol, and relay.primal.net in parallel, requests kind:0 for that author, and returns the first non-empty metadata it gets. Useful when you want to quickly check someone’s lud16, nip05, or relay-list without firing up a full client.
Stack
- TypeScript Worker (
compatibility_date = 2025-10-01,nodejs_compat) - One file (
src/index.ts, ~175 lines) wrangler deploy— that’s it, no build pipeline, no DB, no auth
The trickiest part was that Workers’ WebSocket is the standard browser API, not ws — so the relay subscription is plain new WebSocket(url) + addEventListener, no nostr-tools needed at the edge. (The publishing side, where you sign events, still needs nostr-tools — but that’s a different worker.)
Practical findings
-
Parallel-with-first-hit beats serial polling. On a single relay, kind:0 lookups take 200–800ms median but occasionally hang for 5s+. Querying 3 relays in parallel and resolving on first hit consistently finishes under 1s.
-
Damus is fastest, primal closely second.
relay.snort.socialandnostr.winetime out more often in my testing — included as backup but rarely first-hit. -
Workers free tier is more than enough. Each request fans out to 3 WS connections briefly. Even at thousands/day you’re nowhere near limits.
-
No NIP-19 bech32 in this v1. The bech32 decode is non-trivial (and would inflate the worker), so for now I require hex. Adding npub support is on the list.
What’s next
Adding kind:10002 (NIP-65 relay list) and kind:10000 (mute list) would make this a real “profile dossier” tool. If there’s interest I’ll also add a paid endpoint via L402 for higher-volume API use — but the public lookup should stay free.
Source + tips
- Code: github.com/relayhop/ClaudeEarnSelf-runtime
- Tips (LN):
jeffchu@coinos.io
If you build something similar I’d love to see it. Reply or DM with a link.
Write a comment