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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(erc8004): fail over across keyless EVM nodes so one rate-limited RPC stops blanking agent pages, reputation and registration
nirholas4a3043a62e73
diff --git a/src/erc8004/chain-edit.js b/src/erc8004/chain-edit.jsindex 0ab8f2351..3041f7bd1 100644--- a/src/erc8004/chain-edit.js+++ b/src/erc8004/chain-edit.js@@ -8,7 +8,7 @@import { BrowserProvider, Contract } from 'ethers';import { IDENTITY_REGISTRY_ABI, REGISTRY_DEPLOYMENTS } from './abi.js';-import { CHAIN_META } from './chain-meta.js';+import { CHAIN_META, readProvider } from './chain-meta.js';import { fetchAgentMetadata, findAvatar3D } from './queries.js';import { buildRegistrationJSON, pinFile } from './agent-registry.js';import { resolveURI } from '../ipfs.js';@@ -54,7 +54,7 @@ export async function mountChainEdit(rootEl, chainId, agentId) {let currentGlbUrl = null;try {- const provider = new JsonRpcProvider(chainMeta.rpcUrl, chainId);+ const provider = readProvider(chainId);const registry = new Contract(deployment.identityRegistry, IDENTITY_REGISTRY_ABI, provider);currentTokenURI = await registry.tokenURI(agentId).catch(() => null);diff --git a/src/erc8004/chain-meta.js b/src/erc8004/chain-meta.jsindex 750008e2a..537febeeb 100644--- a/src/erc8004/chain-meta.js+++ b/src/erc8004/chain-meta.js@@ -11,9 +11,15 @@* wallet provider for production reads.*/+import { FallbackProvider, JsonRpcProvider, Network } from 'ethers';+import { REGISTRY_DEPLOYMENTS } from './abi.js';-/** @type {Record<number, { name: string, shortName: string, currency: { name: string, symbol: string, decimals: number }, rpcUrl: string, explorer: string, testnet: boolean }>} */+// `rpcUrl` is the primary public node (also what wallet_addEthereumChain is+// handed); `rpcUrls` lists keyless alternates that readProvider() below fails+// over to. One node rate-limiting a visitor's IP used to blank the agent page,+// the reputation panel and registration with no way to recover.+/** @type {Record<number, { name: string, shortName: string, currency: { name: string, symbol: string, decimals: number }, rpcUrl: string, rpcUrls?: string[], explorer: string, testnet: boolean }>} */export const CHAIN_META = {// ── Mainnets ──────────────────────────────────────────────────────────1: {@@ -21,6 +27,7 @@ export const CHAIN_META = {shortName: 'ETH',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://ethereum-rpc.publicnode.com',+ rpcUrls: ['https://eth.drpc.org', 'https://1rpc.io/eth', 'https://rpc.ankr.com/eth'],explorer: 'https://etherscan.io',testnet: false,},@@ -29,6 +36,7 @@ export const CHAIN_META = {shortName: 'OP',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://mainnet.optimism.io',+ rpcUrls: ['https://optimism.drpc.org', 'https://1rpc.io/op'],explorer: 'https://optimistic.etherscan.io',testnet: false,},@@ -37,6 +45,7 @@ export const CHAIN_META = {shortName: 'BSC',currency: { name: 'BNB', symbol: 'BNB', decimals: 18 },rpcUrl: 'https://bsc-dataseed.bnbchain.org',+ rpcUrls: ['https://bsc.drpc.org', 'https://1rpc.io/bnb', 'https://bsc-rpc.publicnode.com'],explorer: 'https://bscscan.com',testnet: false,},@@ -45,6 +54,7 @@ export const CHAIN_META = {shortName: 'GNO',currency: { name: 'xDAI', symbol: 'xDAI', decimals: 18 },rpcUrl: 'https://rpc.gnosischain.com',+ rpcUrls: ['https://gnosis.drpc.org'],explorer: 'https://gnosisscan.io',testnet: false,},@@ -53,6 +63,7 @@ export const CHAIN_META = {shortName: 'POL',currency: { name: 'POL', symbol: 'POL', decimals: 18 },rpcUrl: 'https://polygon-rpc.com',+ rpcUrls: ['https://polygon.drpc.org', 'https://1rpc.io/matic', 'https://polygon-bor-rpc.publicnode.com'],explorer: 'https://polygonscan.com',testnet: false,},@@ -61,6 +72,7 @@ export const CHAIN_META = {shortName: 'FTM',currency: { name: 'Fantom', symbol: 'FTM', decimals: 18 },rpcUrl: 'https://rpc.ftm.tools',+ rpcUrls: ['https://fantom.drpc.org'],explorer: 'https://ftmscan.com',testnet: false,},@@ -69,6 +81,7 @@ export const CHAIN_META = {shortName: 'zkSync',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://mainnet.era.zksync.io',+ rpcUrls: ['https://zksync.drpc.org'],explorer: 'https://explorer.zksync.io',testnet: false,},@@ -77,6 +90,7 @@ export const CHAIN_META = {shortName: 'GLMR',currency: { name: 'Glimmer', symbol: 'GLMR', decimals: 18 },rpcUrl: 'https://rpc.api.moonbeam.network',+ rpcUrls: ['https://moonbeam.drpc.org'],explorer: 'https://moonbeam.moonscan.io',testnet: false,},@@ -85,6 +99,7 @@ export const CHAIN_META = {shortName: 'MNT',currency: { name: 'Mantle', symbol: 'MNT', decimals: 18 },rpcUrl: 'https://rpc.mantle.xyz',+ rpcUrls: ['https://mantle.drpc.org'],explorer: 'https://explorer.mantle.xyz',testnet: false,},@@ -93,6 +108,7 @@ export const CHAIN_META = {shortName: 'Base',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://mainnet.base.org',+ rpcUrls: ['https://base.drpc.org', 'https://1rpc.io/base', 'https://base-rpc.publicnode.com'],explorer: 'https://basescan.org',testnet: false,},@@ -101,6 +117,7 @@ export const CHAIN_META = {shortName: 'ARB',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://arb1.arbitrum.io/rpc',+ rpcUrls: ['https://arbitrum.drpc.org', 'https://1rpc.io/arb', 'https://arbitrum-one-rpc.publicnode.com'],explorer: 'https://arbiscan.io',testnet: false,},@@ -109,6 +126,7 @@ export const CHAIN_META = {shortName: 'CELO',currency: { name: 'Celo', symbol: 'CELO', decimals: 18 },rpcUrl: 'https://forno.celo.org',+ rpcUrls: ['https://celo.drpc.org'],explorer: 'https://celoscan.io',testnet: false,},@@ -117,6 +135,7 @@ export const CHAIN_META = {shortName: 'AVAX',currency: { name: 'Avax', symbol: 'AVAX', decimals: 18 },rpcUrl: 'https://api.avax.network/ext/bc/C/rpc',+ rpcUrls: ['https://avalanche.drpc.org', 'https://1rpc.io/avax/c', 'https://avalanche-c-chain-rpc.publicnode.com'],explorer: 'https://snowtrace.io',testnet: false,},@@ -125,6 +144,7 @@ export const CHAIN_META = {shortName: 'Linea',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://rpc.linea.build',+ rpcUrls: ['https://linea.drpc.org'],explorer: 'https://lineascan.build',testnet: false,},@@ -133,6 +153,7 @@ export const CHAIN_META = {shortName: 'Scroll',currency: { name: 'Ether', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://rpc.scroll.io',+ rpcUrls: ['https://scroll.drpc.org'],explorer: 'https://scrollscan.com',testnet: false,},@@ -143,6 +164,7 @@ export const CHAIN_META = {shortName: 'BSCt',currency: { name: 'tBNB', symbol: 'tBNB', decimals: 18 },rpcUrl: 'https://bsc-testnet-rpc.publicnode.com',+ rpcUrls: ['https://bsc-testnet.drpc.org'],explorer: 'https://testnet.bscscan.com',testnet: true,},@@ -151,6 +173,7 @@ export const CHAIN_META = {shortName: 'Sep',currency: { name: 'SepETH', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',+ rpcUrls: ['https://sepolia.drpc.org', 'https://1rpc.io/sepolia'],explorer: 'https://sepolia.etherscan.io',testnet: true,},@@ -159,6 +182,7 @@ export const CHAIN_META = {shortName: 'BaseSep',currency: { name: 'SepETH', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://sepolia.base.org',+ rpcUrls: ['https://base-sepolia.drpc.org', 'https://base-sepolia-rpc.publicnode.com'],explorer: 'https://sepolia.basescan.org',testnet: true,},@@ -167,6 +191,7 @@ export const CHAIN_META = {shortName: 'ArbSep',currency: { name: 'SepETH', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://sepolia-rollup.arbitrum.io/rpc',+ rpcUrls: ['https://arbitrum-sepolia.drpc.org', 'https://arbitrum-sepolia-rpc.publicnode.com'],explorer: 'https://sepolia.arbiscan.io',testnet: true,},@@ -175,6 +200,7 @@ export const CHAIN_META = {shortName: 'OpSep',currency: { name: 'SepETH', symbol: 'ETH', decimals: 18 },rpcUrl: 'https://sepolia.optimism.io',+ rpcUrls: ['https://optimism-sepolia.drpc.org', 'https://optimism-sepolia-rpc.publicnode.com'],explorer: 'https://sepolia-optimism.etherscan.io',testnet: true,},@@ -183,6 +209,7 @@ export const CHAIN_META = {shortName: 'Amoy',currency: { name: 'POL', symbol: 'POL', decimals: 18 },rpcUrl: 'https://rpc-amoy.polygon.technology',+ rpcUrls: ['https://polygon-amoy.drpc.org', 'https://polygon-amoy-bor-rpc.publicnode.com'],explorer: 'https://amoy.polygonscan.com',testnet: true,},@@ -191,6 +218,7 @@ export const CHAIN_META = {shortName: 'Fuji',currency: { name: 'Avax', symbol: 'AVAX', decimals: 18 },rpcUrl: 'https://api.avax-test.network/ext/bc/C/rpc',+ rpcUrls: ['https://avalanche-fuji.drpc.org', 'https://avalanche-fuji-c-chain-rpc.publicnode.com'],explorer: 'https://testnet.snowtrace.io',testnet: true,},@@ -283,3 +311,29 @@ export function tokenExplorerUrl(chainId, contract, tokenId) {const m = CHAIN_META[chainId];return m ? `${m.explorer}/token/${contract}?a=${tokenId}` : '';}++/**+ * Read-only provider for a chain that survives one public node being down,+ * rate-limiting the visitor's IP, or stalling. Every node in `rpcUrl` ++ * `rpcUrls` becomes a JsonRpcProvider pinned to the chain (`staticNetwork`, so+ * no eth_chainId probe per call) and they are combined in a FallbackProvider+ * with quorum 1: the first healthy node answers and a stalled one is passed+ * over after `stallTimeout`.+ *+ * @param {number} chainId+ * @returns {import('ethers').AbstractProvider}+ */+export function readProvider(chainId) {+ const meta = CHAIN_META[chainId];+ if (!meta?.rpcUrl) throw new Error(`No RPC configured for chainId ${chainId}`);+ const urls = [...new Set([meta.rpcUrl, ...(meta.rpcUrls || [])])];+ const network = Network.from(chainId);+ const providers = urls.map((url, i) => ({+ provider: new JsonRpcProvider(url, network, { staticNetwork: network, batchMaxCount: 1 }),+ priority: i + 1,+ stallTimeout: 4_000,+ weight: 1,+ }));+ if (providers.length === 1) return providers[0].provider;+ return new FallbackProvider(providers, network, { quorum: 1 });+}diff --git a/src/erc8004/enumeration.js b/src/erc8004/enumeration.jsindex baab83717..4ef2ffb18 100644--- a/src/erc8004/enumeration.js+++ b/src/erc8004/enumeration.js@@ -162,17 +162,21 @@ export async function getRegistrationHistory(registry, ownerAddress, opts = {})* Used by the Search tab when a user hasn't connected a wallet yet.** @param {number} chainId- * @param {string} rpcUrl+ * @param {string} [rpcUrl] override; omit to use the chain's failover node list* @returns {Promise<import('ethers').Contract>}*/export async function getReadOnlyRegistry(chainId, rpcUrl) {const { JsonRpcProvider, Contract } = await import('ethers');+ const { readProvider } = await import('./chain-meta.js');const { REGISTRY_DEPLOYMENTS, IDENTITY_REGISTRY_ABI } = await import('./abi.js');const deployment = REGISTRY_DEPLOYMENTS[chainId];if (!deployment?.identityRegistry) {throw new Error(`No registry for chain ${chainId}`);}- const provider = new JsonRpcProvider(rpcUrl);+ // A caller-supplied URL is honoured as-is; otherwise the chain's failover+ // list answers, so an unconnected visitor's search does not depend on one+ // public node staying up.+ const provider = rpcUrl ? new JsonRpcProvider(rpcUrl) : readProvider(chainId);return new Contract(deployment.identityRegistry, IDENTITY_REGISTRY_ABI, provider);}diff --git a/src/erc8004/queries.js b/src/erc8004/queries.jsindex ea2d68252..b2600021d 100644--- a/src/erc8004/queries.js+++ b/src/erc8004/queries.js@@ -8,13 +8,14 @@* the chain is the source of truth.*/-import { BrowserProvider, Contract, JsonRpcProvider } from 'ethers';+import { BrowserProvider, Contract } from 'ethers';import { IDENTITY_REGISTRY_ABI, REGISTRY_DEPLOYMENTS } from './abi.js';-import { CHAIN_META } from './chain-meta.js';+import { CHAIN_META, readProvider } from './chain-meta.js';/*** Return a read-only ethers provider. Uses the connected wallet provider if- * `ethProvider` is given, else falls back to the public RPC from CHAIN_META.+ * `ethProvider` is given, else the chain's public RPC chain from CHAIN_META+ * (readProvider fails over across every keyless node it lists).** @param {number} chainId* @param {any} [ethProvider] EIP-1193 provider (window.ethereum / Privy)@@ -23,7 +24,7 @@ export function getReadProvider(chainId, ethProvider) {if (ethProvider) return new BrowserProvider(ethProvider);const meta = CHAIN_META[chainId];if (!meta) throw new Error(`No RPC configured for chainId ${chainId}`);- return new JsonRpcProvider(meta.rpcUrl, chainId);+ return readProvider(chainId);}/** @param {number} chainId @param {any} [ethProvider] */diff --git a/src/erc8004/reputation-panel.js b/src/erc8004/reputation-panel.jsindex d13957384..e1d1ccc94 100644--- a/src/erc8004/reputation-panel.js+++ b/src/erc8004/reputation-panel.js@@ -15,8 +15,8 @@* than a generic identity card.*/-import { JsonRpcProvider, BrowserProvider } from 'ethers';-import { CHAIN_META, switchChain, txExplorerUrl } from './chain-meta.js';+import { BrowserProvider } from 'ethers';+import { CHAIN_META, switchChain, txExplorerUrl, readProvider } from './chain-meta.js';import { REGISTRY_DEPLOYMENTS } from './abi.js';import { submitReputation, stakeReputation, getTotalStake, getReputation, getRecentReviews } from './reputation.js';import { log } from '../shared/log.js';@@ -86,9 +86,7 @@ export class ReputationPanel {return;}- const provider = new JsonRpcProvider(meta.rpcUrl, this._agent.chainId, {- staticNetwork: true,- });+ const provider = readProvider(this._agent.chainId);try {[this._stats, this._totalStakeWei] = await Promise.all([diff --git a/src/erc8004/resolve-avatar.js b/src/erc8004/resolve-avatar.jsindex a65f5117a..914f1d9d8 100644--- a/src/erc8004/resolve-avatar.js+++ b/src/erc8004/resolve-avatar.js@@ -12,9 +12,9 @@* Chain reads happen through public RPCs (CHAIN_META) so no wallet required.*/-import { JsonRpcProvider, Contract, Interface, isAddress, getAddress } from 'ethers';+import { Contract, Interface, isAddress, getAddress } from 'ethers';import { IDENTITY_REGISTRY_ABI, REGISTRY_DEPLOYMENTS } from './abi.js';-import { CHAIN_META, supportedChainIds } from './chain-meta.js';+import { CHAIN_META, supportedChainIds, readProvider } from './chain-meta.js';import {getReadProvider,getReadRegistry,@@ -379,7 +379,7 @@ export async function resolveByAgentURI(uri, ethProvider) {* @param {string} name*/export async function resolveENSAddress(name) {- const provider = new JsonRpcProvider(CHAIN_META[1].rpcUrl, 1);+ const provider = readProvider(1);const addr = await provider.resolveName(name);if (!addr) throw new Error(`ENS name does not resolve: ${name}`);return getAddress(addr);diff --git a/src/erc8004/user-profile.js b/src/erc8004/user-profile.jsindex 7bcf9d69e..6826d6ef4 100644--- a/src/erc8004/user-profile.js+++ b/src/erc8004/user-profile.js@@ -6,10 +6,10 @@* fetchAgentMetadata, findAvatar3D) — no new backend needed.*/-import { JsonRpcProvider, Contract } from 'ethers';+import { Contract } from 'ethers';import { IDENTITY_REGISTRY_ABI, REGISTRY_DEPLOYMENTS } from './abi.js';import { listAgentsByOwner, fetchAgentMetadata, findAvatar3D } from './queries.js';-import { CHAIN_META, supportedChainIds } from './chain-meta.js';+import { CHAIN_META, supportedChainIds, readProvider } from './chain-meta.js';import { resolveURI } from '../ipfs.js';import { walletChipHTML, wireWalletChips } from '../shared/agent-wallet-chip.js';@@ -172,7 +172,7 @@ async function resolveAgentCard({ chainId, agentId, address }) {const meta = CHAIN_META[chainId];if (!meta) return base;- const provider = new JsonRpcProvider(meta.rpcUrl, chainId);+ const provider = readProvider(chainId);const addr = REGISTRY_DEPLOYMENTS[chainId]?.identityRegistry;if (!addr) return base;