Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

refactor: remove deprecated ERC-8004 backfill script and update crawling logic to use RPC

nirholas247a7f0bb0d0
diff --git a/agent-home.html b/agent-home.html
index 22911982e..e2a7434fd 100644
--- a/agent-home.html
+++ b/agent-home.html
@@ -116,24 +116,35 @@
overflow: auto;
display: flex;
flex-direction: column;
+ background: #000;
+ color: #fff;
}
.agent-page-header {
display: flex;
align-items: center;
gap: 1rem;
- padding: 1rem 1.618rem;
- border-bottom: 1px solid rgba(255, 255, 255, 0.06);
+ padding: 0.75rem 1.618rem;
+ border-bottom: 1px solid rgba(255, 255, 255, 0.08);
+ background: #000;
}
.agent-page-header a {
- color: rgba(255, 255, 255, 0.4);
+ color: rgba(255, 255, 255, 0.5);
text-decoration: none;
font-size: 0.764rem;
+ display: inline-flex;
+ align-items: center;
}
.agent-page-header a:hover {
- color: rgba(255, 255, 255, 0.8);
+ color: #fff;
+ }
+
+ .agent-header-logo {
+ height: 28px;
+ width: auto;
+ display: block;
}
.agent-stage {
@@ -229,14 +240,14 @@
.agent-page-title {
font-size: 1.618rem;
font-weight: 300;
- color: #e5e5e5;
+ color: #fff;
letter-spacing: -0.02em;
margin: 0 0 0.618rem;
}
.agent-page-subtitle {
font-size: 0.764rem;
- color: rgba(255, 255, 255, 0.35);
+ color: rgba(255, 255, 255, 0.55);
line-height: 1.618;
}
@@ -419,7 +430,9 @@
<body>
<a href="#main" class="skip-link">Skip to main content</a>
<header class="agent-page-header" style="justify-content: space-between">
- <a href="/" aria-label="Back to three.ws home">← three.ws</a>
+ <a href="/" aria-label="Back to three.ws home">
+ <img src="/three.svg" alt="three.ws" class="agent-header-logo" />
+ </a>
<!-- BEGIN:AGENT_HOME_ORPHANS_DOM -->
<div id="agent-share-btn-mount"></div>
<!-- END:AGENT_HOME_ORPHANS_DOM -->
@@ -610,10 +623,10 @@
<span class="h-footer-status-dot" aria-hidden="true"></span>
<span>All systems normal</span>
</span>
- <a class="h-footer-badge" href="https://github.com/nirholas/3D/blob/main/LICENSE" target="_blank" rel="noopener" aria-label="MIT license">
+ <span class="h-footer-badge">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm0 14.5A6.5 6.5 0 1 1 8 1.5a6.5 6.5 0 0 1 0 13zm-1-9.25a1 1 0 1 1 2 0v3.5a1 1 0 1 1-2 0v-3.5zm1 6.5a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2z"/></svg>
- <span>MIT Licensed</span>
- </a>
+ <span>Transparent by default</span>
+ </span>
<a class="h-footer-badge" href="https://github.com/nirholas/3D" target="_blank" rel="noopener" aria-label="View source on GitHub">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>Open source</span>
diff --git a/api/cron/erc8004-backfill.js b/api/cron/erc8004-backfill.js
deleted file mode 100644
index e5d1eb1eb..000000000
--- a/api/cron/erc8004-backfill.js
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * One-shot historical backfill for the ERC-8004 agent index.
- *
- * Scans every Registered event from block 0 to latest on every configured
- * chain using Etherscan V2 getLogs, paging through all results.
- *
- * Usage:
- * POST /api/cron/erc8004-backfill
- * Authorization: Bearer $CRON_SECRET
- *
- * Optional body: { chainIds: [8453, 84532] } — limit to specific chains.
- * Optional query: ?reset=1 — clear cursors first so the regular cron also
- * re-scans from block 0 (use with care on prod).
- */
-
-import { id as keccakId, AbiCoder, getAddress } from 'ethers';
-import { sql } from '../_lib/db.js';
-import { cors, error, json, wrap } from '../_lib/http.js';
-import { env } from '../_lib/env.js';
-import { CHAINS } from '../_lib/erc8004-chains.js';
-
-const REGISTERED_TOPIC = keccakId('Registered(uint256,string,address)');
-const ETHERSCAN_BASE = 'https://api.etherscan.io/v2/api';
-const ABI_CODER = AbiCoder.defaultAbiCoder();
-
-const PAGE_SIZE = 1000; // Etherscan V2 max offset
-const FETCH_TIMEOUT_MS = 12_000;
-
-export default wrap(async (req, res) => {
- if (cors(req, res, { methods: 'POST,OPTIONS' })) return;
-
- const auth = req.headers['authorization'] || '';
- const expected = env.CRON_SECRET ? `Bearer ${env.CRON_SECRET}` : null;
- if (expected && auth !== expected) {
- return error(res, 401, 'unauthorized', 'cron secret required');
- }
- if (!env.ETHERSCAN_API_KEY) {
- return error(res, 500, 'missing_env', 'ETHERSCAN_API_KEY not configured');
- }
-
- let body = {};
- try {
- if (req.headers['content-type']?.includes('application/json')) {
- const chunks = [];
- for await (const chunk of req) chunks.push(chunk);
- body = JSON.parse(Buffer.concat(chunks).toString());
- }
- } catch {
- /* no body — fine */
- }
-
- const resetCursors = req.query?.reset === '1' || body.reset === true;
- const onlyChains = Array.isArray(body.chainIds) ? new Set(body.chainIds.map(Number)) : null;
- const chains = onlyChains ? CHAINS.filter((c) => onlyChains.has(c.id)) : CHAINS;
-
- if (chains.length === 0) {
- return error(res, 400, 'bad_request', 'no matching chains');
- }
-
- if (resetCursors) {
- const ids = chains.map((c) => c.id);
- await sql`DELETE FROM erc8004_crawl_cursor WHERE chain_id = ANY(${ids})`;
- }
-
- const report = { chains: [], errors: [] };
-
- for (const chain of chains) {
- try {
- const r = await backfillChain(chain);
- report.chains.push({ chainId: chain.id, name: chain.name, ...r });
- } catch (err) {
- report.errors.push({ chainId: chain.id, name: chain.name, error: err.message || String(err) });
- }
- }
-
- return json(res, 200, report);
-});
-
-async function backfillChain(chain) {
- let page = 1;
- let inserted = 0;
- let lastBlock = 0;
- let hasMore = true;
-
- while (hasMore) {
- const url = new URL(ETHERSCAN_BASE);
- url.searchParams.set('chainid', String(chain.id));
- url.searchParams.set('module', 'logs');
- url.searchParams.set('action', 'getLogs');
- url.searchParams.set('address', chain.registry);
- url.searchParams.set('topic0', REGISTERED_TOPIC);
- url.searchParams.set('fromBlock', '0');
- url.searchParams.set('toBlock', 'latest');
- url.searchParams.set('page', String(page));
- url.searchParams.set('offset', String(PAGE_SIZE));
- url.searchParams.set('apikey', env.ETHERSCAN_API_KEY);
-
- const body = await fetchJson(url.toString());
-
- if (body.status === '0' && /no records/i.test(body.message || '')) {
- break;
- }
- if (body.status !== '1' || !Array.isArray(body.result)) {
- throw new Error(`etherscan ${chain.id} page ${page}: ${body.message || 'unknown'}`);
- }
-
- for (const log of body.result) {
- try {
- const agentId = BigInt(log.topics[1]).toString();
- const ownerHex = '0x' + log.topics[2].slice(-40);
- const owner = getAddress(ownerHex).toLowerCase();
- const [agentURI] = ABI_CODER.decode(['string'], log.data);
- const blockNumber = Number.parseInt(log.blockNumber, 16);
- const timestamp = Number.parseInt(log.timeStamp, 16);
- const registeredAt = new Date(timestamp * 1000).toISOString();
-
- await sql`
- INSERT INTO erc8004_agents_index
- (chain_id, agent_id, owner, registry, agent_uri,
- registered_block, registered_tx, registered_at, last_seen_at)
- VALUES
- (${chain.id}, ${agentId}, ${owner}, ${chain.registry.toLowerCase()},
- ${agentURI || null}, ${blockNumber}, ${log.transactionHash},
- ${registeredAt}, now())
- ON CONFLICT (chain_id, agent_id) DO UPDATE SET
- owner = excluded.owner,
- agent_uri = COALESCE(excluded.agent_uri, erc8004_agents_index.agent_uri),
- last_seen_at = now()
- `;
- inserted += 1;
- if (blockNumber > lastBlock) lastBlock = blockNumber;
- } catch (decodeErr) {
- console.warn('[backfill] decode failed', chain.id, log.transactionHash, decodeErr.message);
- }
- }
-
- // Fewer results than page size means we've reached the end.
- hasMore = body.result.length === PAGE_SIZE;
- page += 1;
- }
-
- // Advance the cron cursor so the regular crawler resumes from here.
- if (lastBlock > 0) {
- await sql`
- INSERT INTO erc8004_crawl_cursor (chain_id, last_block, updated_at)
- VALUES (${chain.id}, ${lastBlock}, now())
- ON CONFLICT (chain_id) DO UPDATE SET
- last_block = GREATEST(erc8004_crawl_cursor.last_block, excluded.last_block),
- updated_at = now()
- `;
- }
-
- return { inserted, pages: page - 1, lastBlock };
-}
-
-async function fetchJson(url) {
- const ac = new AbortController();
- const t = setTimeout(() => ac.abort(), FETCH_TIMEOUT_MS);
- try {
- const res = await fetch(url, { signal: ac.signal });
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
- return await res.json();
- } finally {
- clearTimeout(t);
- }
-}
diff --git a/api/cron/erc8004-crawl.js b/api/cron/erc8004-crawl.js
index 994dbe4de..1023a151b 100644
--- a/api/cron/erc8004-crawl.js
+++ b/api/cron/erc8004-crawl.js
@@ -9,7 +9,7 @@
*
* Flow per chain:
* 1. Read last scanned block from erc8004_crawl_cursor.
- * 2. Etherscan V2 getLogs → Registered events since that block.
+ * 2. eth_getLogs via the chain's public RPC — Registered events since that block.
* 3. Decode agentId (topic1), owner (topic2), agentURI (data) and upsert.
* 4. Advance cursor.
*
@@ -22,15 +22,12 @@ import { sql } from '../_lib/db.js';
import { cors, error, json, wrap } from '../_lib/http.js';
import { env } from '../_lib/env.js';
import { CHAINS } from '../_lib/erc8004-chains.js';
+import { SERVER_CHAIN_META } from '../_lib/onchain.js';
const REGISTERED_TOPIC = keccakId('Registered(uint256,string,address)');
-const ETHERSCAN_BASE = 'https://api.etherscan.io/v2/api';
const ABI_CODER = AbiCoder.defaultAbiCoder();
-// Per-chain log page size. Etherscan V2 caps `offset` at 1000.
-const LOG_PAGE_SIZE = 1000;
-
-// Metadata enrichment per invocation. Keep modest — each fetch hits IPFS/R2.
+// Metadata enrichment per invocation.
const METADATA_BATCH = 25;
// Per-request timeout so one stuck chain can't eat the whole cron budget.
@@ -39,17 +36,12 @@ const FETCH_TIMEOUT_MS = 8_000;
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,POST,OPTIONS' })) return;
- // Vercel Cron sends `Authorization: Bearer $CRON_SECRET`. Allow GET/POST
- // from the Vercel cron runner and from a manually-authorized caller.
const auth = req.headers['authorization'] || '';
const expected = env.CRON_SECRET ? `Bearer ${env.CRON_SECRET}` : null;
const fromCron = req.headers['x-vercel-cron'] === '1';
if (!fromCron && expected && auth !== expected) {
return error(res, 401, 'unauthorized', 'cron secret required');
}
- if (!env.ETHERSCAN_API_KEY) {
- return error(res, 500, 'missing_env', 'ETHERSCAN_API_KEY not configured');
- }
const report = { chains: [], enriched: 0, errors: [] };
@@ -76,46 +68,36 @@ export default wrap(async (req, res) => {
// ─── Log crawl ───────────────────────────────────────────────────────────
async function crawlChain(chain) {
+ const meta = SERVER_CHAIN_META[chain.id];
+ if (!meta?.rpc) return { inserted: 0, skipped: true, reason: 'no_rpc' };
+
const [cursor] = await sql`
SELECT last_block FROM erc8004_crawl_cursor WHERE chain_id = ${chain.id}
`;
const fromBlock = cursor ? Number(cursor.last_block) + 1 : 0;
- const url = new URL(ETHERSCAN_BASE);
- url.searchParams.set('chainid', String(chain.id));
- url.searchParams.set('module', 'logs');
- url.searchParams.set('action', 'getLogs');
- url.searchParams.set('address', chain.registry);
- url.searchParams.set('topic0', REGISTERED_TOPIC);
- url.searchParams.set('fromBlock', String(fromBlock));
- url.searchParams.set('toBlock', 'latest');
- url.searchParams.set('page', '1');
- url.searchParams.set('offset', String(LOG_PAGE_SIZE));
- url.searchParams.set('apikey', env.ETHERSCAN_API_KEY);
+ const latestHex = await rpc(meta.rpc, 'eth_blockNumber', []);
+ const latest = Number(latestHex);
+ if (fromBlock > latest) return { inserted: 0, lastBlock: latest, fromBlock };
- const body = await fetchJson(url.toString());
- // Etherscan returns `status:"1"` with `result:[...]` OR `status:"0"` with
- // `message:"No records found"` when empty. Anything else is an error.
- if (body.status === '0' && /no records/i.test(body.message || '')) {
- return { inserted: 0, lastBlock: fromBlock - 1, fromBlock };
- }
- if (body.status !== '1' || !Array.isArray(body.result)) {
- throw new Error(
- `etherscan ${chain.id}: ${body.message || 'unknown'} — ${String(body.result).slice(0, 120)}`,
- );
- }
+ const logs = await rpc(meta.rpc, 'eth_getLogs', [{
+ address: chain.registry,
+ topics: [REGISTERED_TOPIC],
+ fromBlock: '0x' + fromBlock.toString(16),
+ toBlock: '0x' + latest.toString(16),
+ }]);
let lastBlock = fromBlock - 1;
let inserted = 0;
- for (const log of body.result) {
+ for (const log of logs) {
try {
const agentId = BigInt(log.topics[1]).toString();
const ownerHex = '0x' + log.topics[2].slice(-40);
const owner = getAddress(ownerHex).toLowerCase();
const [agentURI] = ABI_CODER.decode(['string'], log.data);
- const blockNumber = Number.parseInt(log.blockNumber, 16);
- const timestamp = Number.parseInt(log.timeStamp, 16);
+ const blockNumber = Number(log.blockNumber);
+ const timestamp = Number(log.timeStamp);
const registeredAt = new Date(timestamp * 1000).toISOString();
await sql`
@@ -127,20 +109,18 @@ async function crawlChain(chain) {
${agentURI || null}, ${blockNumber}, ${log.transactionHash},
${registeredAt}, now())
ON CONFLICT (chain_id, agent_id) DO UPDATE SET
- owner = excluded.owner,
+ owner = excluded.owner,
agent_uri = COALESCE(excluded.agent_uri, erc8004_agents_index.agent_uri),
last_seen_at = now()
`;
inserted += 1;
if (blockNumber > lastBlock) lastBlock = blockNumber;
} catch (decodeErr) {
- // Skip malformed log; continue.
console.warn('[crawl] decode failed', chain.id, log.transactionHash, decodeErr.message);
}
}
- // Update cursor (even on zero inserts — keeps fromBlock monotonic).
- const newCursor = Math.max(lastBlock, fromBlock - 1);
+ const newCursor = Math.max(lastBlock, fromBlock - 1, latest);
await sql`
INSERT INTO erc8004_crawl_cursor (chain_id, last_block, updated_at)
VALUES (${chain.id}, ${newCursor}, now())
@@ -155,7 +135,6 @@ async function crawlChain(chain) {
// ─── Metadata enrichment ─────────────────────────────────────────────────
async function enrichMetadata(limit) {
- // Rows with no metadata yet, or metadata older than 7d.
const rows = await sql`
SELECT chain_id, agent_id, agent_uri
FROM erc8004_agents_index
@@ -172,8 +151,7 @@ async function enrichMetadata(limit) {
if (!meta) {
await sql`
UPDATE erc8004_agents_index
- SET metadata_error = 'fetch failed',
- last_metadata_at = now()
+ SET metadata_error = 'fetch failed', last_metadata_at = now()
WHERE chain_id = ${row.chain_id} AND agent_id = ${row.agent_id}
`;
continue;
@@ -219,16 +197,17 @@ async function enrichMetadata(limit) {
// ─── Helpers ─────────────────────────────────────────────────────────────
-async function fetchJson(url) {
- const ac = new AbortController();
- const t = setTimeout(() => ac.abort(), FETCH_TIMEOUT_MS);
- try {
- const res = await fetch(url, { signal: ac.signal });
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
- return await res.json();
- } finally {
- clearTimeout(t);
- }
+async function rpc(url, method, params) {
+ const res = await fetch(url, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
+ });
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const body = await res.json();
+ if (body.error) throw new Error(`RPC ${body.error.code}: ${body.error.message}`);
+ return body.result;
}
async function fetchAgentMetadata(uri) {
diff --git a/create.html b/create.html
index fd9cd628b..9a59224b5 100644
--- a/create.html
+++ b/create.html
@@ -665,10 +665,10 @@
<span class="h-footer-status-dot" aria-hidden="true"></span>
<span>All systems normal</span>
</span>
- <a class="h-footer-badge" href="https://github.com/nirholas/3D/blob/main/LICENSE" target="_blank" rel="noopener" aria-label="MIT license">
+ <span class="h-footer-badge">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm0 14.5A6.5 6.5 0 1 1 8 1.5a6.5 6.5 0 0 1 0 13zm-1-9.25a1 1 0 1 1 2 0v3.5a1 1 0 1 1-2 0v-3.5zm1 6.5a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2z"/></svg>
- <span>MIT Licensed</span>
- </a>
+ <span>Transparent by default</span>
+ </span>
<a class="h-footer-badge" href="https://github.com/nirholas/3D" target="_blank" rel="noopener" aria-label="View source on GitHub">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>Open source</span>
diff --git a/home.html b/home.html
index 9b26b9707..d458ca1c7 100644
--- a/home.html
+++ b/home.html
@@ -523,10 +523,10 @@
<span class="h-footer-status-dot" aria-hidden="true"></span>
<span>All systems normal</span>
</span>
- <a class="h-footer-badge" href="https://github.com/nirholas/3D/blob/main/LICENSE" target="_blank" rel="noopener" aria-label="MIT license">
+ <span class="h-footer-badge">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm0 14.5A6.5 6.5 0 1 1 8 1.5a6.5 6.5 0 0 1 0 13zm-1-9.25a1 1 0 1 1 2 0v3.5a1 1 0 1 1-2 0v-3.5zm1 6.5a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2z"/></svg>
- <span>MIT Licensed</span>
- </a>
+ <span>Transparent by default</span>
+ </span>
<a class="h-footer-badge" href="https://github.com/nirholas/3D" target="_blank" rel="noopener" aria-label="View source on GitHub">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>Open source</span>
diff --git a/index.html b/index.html
index 7a57a05cc..c57b012bc 100644
--- a/index.html
+++ b/index.html
@@ -1227,10 +1227,10 @@
<span class="h-footer-status-dot" aria-hidden="true"></span>
<span>All systems normal</span>
</span>
- <a class="h-footer-badge" href="https://github.com/nirholas/3D/blob/main/LICENSE" target="_blank" rel="noopener" aria-label="MIT license">
+ <span class="h-footer-badge">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm0 14.5A6.5 6.5 0 1 1 8 1.5a6.5 6.5 0 0 1 0 13zm-1-9.25a1 1 0 1 1 2 0v3.5a1 1 0 1 1-2 0v-3.5zm1 6.5a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2z"/></svg>
- <span>MIT Licensed</span>
- </a>
+ <span>Transparent by default</span>
+ </span>
<a class="h-footer-badge" href="https://github.com/nirholas/3D" target="_blank" rel="noopener" aria-label="View source on GitHub">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>Open source</span>
diff --git a/profile.html b/profile.html
index 847015d6c..08f07becb 100644
--- a/profile.html
+++ b/profile.html
@@ -381,10 +381,10 @@
<span class="h-footer-status-dot" aria-hidden="true"></span>
<span>All systems normal</span>
</span>
- <a class="h-footer-badge" href="https://github.com/nirholas/3D/blob/main/LICENSE" target="_blank" rel="noopener" aria-label="MIT license">
+ <span class="h-footer-badge">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0zm0 14.5A6.5 6.5 0 1 1 8 1.5a6.5 6.5 0 0 1 0 13zm-1-9.25a1 1 0 1 1 2 0v3.5a1 1 0 1 1-2 0v-3.5zm1 6.5a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2z"/></svg>
- <span>MIT Licensed</span>
- </a>
+ <span>Transparent by default</span>
+ </span>
<a class="h-footer-badge" href="https://github.com/nirholas/3D" target="_blank" rel="noopener" aria-label="View source on GitHub">
<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>Open source</span>
diff --git a/public/my-agents/my-agents.js b/public/my-agents/my-agents.js
index a4fe1e6c5..37175adcc 100644
--- a/public/my-agents/my-agents.js
+++ b/public/my-agents/my-agents.js
@@ -4,6 +4,31 @@
* as importable cards.
*/
+async function fetchDiscoveredAgents() {
+ const res = await fetch('/api/erc8004/hydrate', { method: 'GET', credentials: 'include' });
+ if (!res.ok) {
+ const error = await res.json().catch(() => ({}));
+ throw new Error(error.error_description || `HTTP ${res.status}`);
+ }
+ const data = await res.json();
+ return data.agents || [];
+}
+
+async function importAgent({ chainId, agentId }) {
+ const res = await fetch('/api/erc8004/import', {
+ method: 'POST',
+ credentials: 'include',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ chainId, agentId }),
+ });
+ if (!res.ok) {
+ const error = await res.json().catch(() => ({}));
+ throw new Error(error.error_description || `HTTP ${res.status}`);
+ }
+ const data = await res.json();
+ return data.agent;
+}
+
/** @type {Record<number, string>} Minimal chain name map to avoid importing chain-meta.js deps. */
const CHAIN_NAMES = {
1: 'Ethereum',
diff --git a/scripts/backfill-erc8004.mjs b/scripts/backfill-erc8004.mjs
index 0e04a5fe0..c12756d71 100644
--- a/scripts/backfill-erc8004.mjs
+++ b/scripts/backfill-erc8004.mjs
@@ -1,15 +1,12 @@
/**
- * One-shot ERC-8004 historical backfill script.
+ * One-shot ERC-8004 historical backfill.
*
- * Reads DATABASE_URL and ETHERSCAN_API_KEY from .env.local (or process.env).
- * Scans every Registered event from block 0 on every chain and upserts into
- * erc8004_agents_index, then advances the crawl cursor.
+ * Fetches all Registered events from the Identity Registry contract address
+ * on each chain via eth_getLogs, then upserts into erc8004_agents_index.
*
* Usage:
* node scripts/backfill-erc8004.mjs
* node scripts/backfill-erc8004.mjs 8453 84532 # specific chain IDs only
- *
- * Set ETHERSCAN_API_KEY in .env.local or export it before running.
*/
import { readFileSync } from 'fs';
@@ -20,121 +17,96 @@ import { neon } from '@neondatabase/serverless';
const __dir = dirname(fileURLToPath(import.meta.url));
-// Load .env.local
try {
const raw = readFileSync(resolve(__dir, '../.env.local'), 'utf8');
for (const line of raw.split('\n')) {
const m = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
if (m && !process.env[m[1]]) process.env[m[1]] = m[2].trim();
}
-} catch {
- /* no .env.local — rely on process.env */
-}
-
-const DATABASE_URL = process.env.DATABASE_URL;
-const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
+} catch { /* no .env.local */ }
-if (!DATABASE_URL) { console.error('Missing DATABASE_URL'); process.exit(1); }
-if (!ETHERSCAN_API_KEY) { console.error('Missing ETHERSCAN_API_KEY'); process.exit(1); }
-
-const sql = neon(DATABASE_URL);
+if (!process.env.DATABASE_URL) { console.error('Missing DATABASE_URL'); process.exit(1); }
+const sql = neon(process.env.DATABASE_URL);
const REGISTERED_TOPIC = keccakId('Registered(uint256,string,address)');
const ABI_CODER = AbiCoder.defaultAbiCoder();
-const ETHERSCAN_BASE = 'https://api.etherscan.io/v2/api';
-const PAGE_SIZE = 1000;
const CHAINS = [
- { id: 8453, name: 'Base', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 42161, name: 'Arbitrum One', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 56, name: 'BNB Chain', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 1, name: 'Ethereum', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 10, name: 'Optimism', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 137, name: 'Polygon', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 43114, name: 'Avalanche', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 100, name: 'Gnosis', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 250, name: 'Fantom', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 42220, name: 'Celo', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 59144, name: 'Linea', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 534352, name: 'Scroll', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 5000, name: 'Mantle', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 324, name: 'zkSync Era', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 1284, name: 'Moonbeam', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
- { id: 97, name: 'BSC Testnet', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
- { id: 84532, name: 'Base Sepolia', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
- { id: 421614, name: 'Arbitrum Sepolia', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
- { id: 11155111, name: 'Ethereum Sepolia', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
- { id: 11155420, name: 'Optimism Sepolia', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
- { id: 80002, name: 'Polygon Amoy', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
- { id: 43113, name: 'Avalanche Fuji', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 8453, name: 'Base', rpc: 'https://mainnet.base.org', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 42161, name: 'Arbitrum One', rpc: 'https://arb1.arbitrum.io/rpc', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 56, name: 'BNB Chain', rpc: 'https://bsc-dataseed.bnbchain.org', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 1, name: 'Ethereum', rpc: 'https://eth.llamarpc.com', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 10, name: 'Optimism', rpc: 'https://mainnet.optimism.io', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 137, name: 'Polygon', rpc: 'https://polygon-rpc.com', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 43114, name: 'Avalanche', rpc: 'https://api.avax.network/ext/bc/C/rpc', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 100, name: 'Gnosis', rpc: 'https://rpc.gnosischain.com', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 250, name: 'Fantom', rpc: 'https://rpc.ftm.tools', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 42220, name: 'Celo', rpc: 'https://forno.celo.org', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 59144, name: 'Linea', rpc: 'https://rpc.linea.build', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 534352, name: 'Scroll', rpc: 'https://rpc.scroll.io', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 5000, name: 'Mantle', rpc: 'https://rpc.mantle.xyz', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 324, name: 'zkSync Era', rpc: 'https://mainnet.era.zksync.io', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 1284, name: 'Moonbeam', rpc: 'https://rpc.api.moonbeam.network', registry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432' },
+ { id: 97, name: 'BSC Testnet', rpc: 'https://data-seed-prebsc-1-s1.bnbchain.org:8545', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 84532, name: 'Base Sepolia', rpc: 'https://sepolia.base.org', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 421614, name: 'Arbitrum Sepolia', rpc: 'https://sepolia-rollup.arbitrum.io/rpc', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 11155111, name: 'Ethereum Sepolia', rpc: 'https://rpc.sepolia.org', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 11155420, name: 'Optimism Sepolia', rpc: 'https://sepolia.optimism.io', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 80002, name: 'Polygon Amoy', rpc: 'https://rpc-amoy.polygon.technology', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
+ { id: 43113, name: 'Avalanche Fuji', rpc: 'https://api.avax-test.network/ext/bc/C/rpc', registry: '0x8004A818BFB912233c491871b3d84c89A494BD9e' },
];
const onlyIds = process.argv.slice(2).map(Number).filter(Boolean);
const chains = onlyIds.length ? CHAINS.filter((c) => onlyIds.includes(c.id)) : CHAINS;
-async function fetchJson(url) {
- const res = await fetch(url, { signal: AbortSignal.timeout(15_000) });
+async function getLogs(chain) {
+ const res = await fetch(chain.rpc, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({
+ jsonrpc: '2.0', id: 1,
+ method: 'eth_getLogs',
+ params: [{ address: chain.registry, topics: [REGISTERED_TOPIC], fromBlock: '0x0', toBlock: 'latest' }],
+ }),
+ signal: AbortSignal.timeout(30_000),
+ });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
- return res.json();
+ const body = await res.json();
+ if (body.error) throw new Error(`RPC ${body.error.code}: ${body.error.message}`);
+ return body.result;
}
async function backfillChain(chain) {
- let page = 1;
+ const logs = await getLogs(chain);
let inserted = 0;
let lastBlock = 0;
- while (true) {
- const url = new URL(ETHERSCAN_BASE);
- url.searchParams.set('chainid', String(chain.id));
- url.searchParams.set('module', 'logs');
- url.searchParams.set('action', 'getLogs');
- url.searchParams.set('address', chain.registry);
- url.searchParams.set('topic0', REGISTERED_TOPIC);
- url.searchParams.set('fromBlock', '0');
- url.searchParams.set('toBlock', 'latest');
- url.searchParams.set('page', String(page));
- url.searchParams.set('offset', String(PAGE_SIZE));
- url.searchParams.set('apikey', ETHERSCAN_API_KEY);
-
- const body = await fetchJson(url.toString());
-
- if (body.status === '0' && /no records/i.test(body.message || '')) break;
- if (body.status !== '1' || !Array.isArray(body.result)) {
- throw new Error(`etherscan ${chain.id} p${page}: ${body.message} — ${String(body.result).slice(0, 80)}`);
+ for (const log of logs) {
+ try {
+ const agentId = BigInt(log.topics[1]).toString();
+ const owner = getAddress('0x' + log.topics[2].slice(-40)).toLowerCase();
+ const [agentURI] = ABI_CODER.decode(['string'], log.data);
+ const blockNumber = Number(log.blockNumber);
+ const registeredAt = new Date(Number(log.timeStamp) * 1000).toISOString();
+
+ await sql`
+ INSERT INTO erc8004_agents_index
+ (chain_id, agent_id, owner, registry, agent_uri,
+ registered_block, registered_tx, registered_at, last_seen_at)
+ VALUES
+ (${chain.id}, ${agentId}, ${owner}, ${chain.registry.toLowerCase()},
+ ${agentURI || null}, ${blockNumber}, ${log.transactionHash},
+ ${registeredAt}, now())
+ ON CONFLICT (chain_id, agent_id) DO UPDATE SET
+ owner = excluded.owner,
+ agent_uri = COALESCE(excluded.agent_uri, erc8004_agents_index.agent_uri),
+ last_seen_at = now()
+ `;
+ inserted++;
+ if (blockNumber > lastBlock) lastBlock = blockNumber;
+ } catch (e) {
+ console.warn(` skip ${log.transactionHash}: ${e.message}`);
}
-
- for (const log of body.result) {
- try {
- const agentId = BigInt(log.topics[1]).toString();
- const owner = getAddress('0x' + log.topics[2].slice(-40)).toLowerCase();
- const [agentURI] = ABI_CODER.decode(['string'], log.data);
- const blockNumber = Number.parseInt(log.blockNumber, 16);
- const registeredAt = new Date(Number.parseInt(log.timeStamp, 16) * 1000).toISOString();
-
- await sql`
- INSERT INTO erc8004_agents_index
- (chain_id, agent_id, owner, registry, agent_uri,
- registered_block, registered_tx, registered_at, last_seen_at)
- VALUES
- (${chain.id}, ${agentId}, ${owner}, ${chain.registry.toLowerCase()},
- ${agentURI || null}, ${blockNumber}, ${log.transactionHash},
- ${registeredAt}, now())
- ON CONFLICT (chain_id, agent_id) DO UPDATE SET
- owner = excluded.owner,
- agent_uri = COALESCE(excluded.agent_uri, erc8004_agents_index.agent_uri),
- last_seen_at = now()
- `;
- inserted++;
- if (blockNumber > lastBlock) lastBlock = blockNumber;
- } catch (e) {
- console.warn(` skip ${log.transactionHash}: ${e.message}`);
- }
- }
-
- process.stdout.write(`\r page ${page} — ${inserted} upserted`);
-
- if (body.result.length < PAGE_SIZE) break;
- page++;
}
if (lastBlock > 0) {
@@ -147,15 +119,15 @@ async function backfillChain(chain) {
`;
}
- return { inserted, pages: page, lastBlock };
+ return { found: logs.length, inserted, lastBlock };
}
console.log(`Backfilling ${chains.length} chain(s)…\n`);
for (const chain of chains) {
- process.stdout.write(`[${chain.name} (${chain.id})] scanning…`);
+ process.stdout.write(`[${chain.name}] fetching logs…`);
try {
- const { inserted, pages, lastBlock } = await backfillChain(chain);
- console.log(`\r[${chain.name}] done — ${inserted} rows, ${pages} page(s), last block ${lastBlock}`);
+ const { found, inserted, lastBlock } = await backfillChain(chain);
+ console.log(`\r[${chain.name}] ${inserted} upserted (${found} events, last block ${lastBlock})`);
} catch (e) {
console.error(`\r[${chain.name}] ERROR: ${e.message}`);
}
diff --git a/style.css b/style.css
index 30a584093..627488d8f 100644
--- a/style.css
+++ b/style.css
@@ -1218,13 +1218,17 @@ footer .separator {
}
/* Page mode — /deploy renders inside app.html shell, not as a modal overlay. */
+body[data-viewer-mode='deploy'],
+body[data-viewer-mode='explore'] {
+ overflow-y: auto;
+}
+
.deploy-page,
.explore-page {
display: block;
width: 100%;
min-height: calc(100vh - var(--header-h));
padding: var(--space-xl) var(--space-lg) var(--space-2xl);
- overflow-y: auto;
}
/* /a/<chainId>/<agentId> — overlay card that tells the viewer whose agent they're looking at. */