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.

fix(nft): resolve testnet collectibles and stop leaking the missing pinning secret to anonymous callers

nirholas72b0ded95454
diff --git a/api/_lib/env.js b/api/_lib/env.js
index 399a81c58..12ef79499 100644
--- a/api/_lib/env.js
+++ b/api/_lib/env.js
@@ -1390,14 +1390,17 @@ export const env = {
return opt('CLUB_BASE_RPC_URL', 'https://mainnet.base.org');
},
- // NFT.Storage API token — required for MintScene tool (uploads GLB + thumbnail + metadata to IPFS).
- // Obtain at https://nft.storage. When unset, /api/nft/mint-scene returns 503 not_configured.
+ // NFT.Storage API token, read by api/erc8004/[action].js only. Obtain at
+ // https://nft.storage. The MintScene tool no longer touches it: /api/nft/mint-scene
+ // pins through api/_lib/ipfs-pin.js (Pinata/web3.storage), so its 503 not_configured
+ // tracks PINATA_JWT, not this variable.
get NFT_STORAGE_TOKEN() {
return opt('NFT_STORAGE_TOKEN');
},
- // Metaplex Bubblegum compressed-NFT tree config — optional. When both are set, MintScene
- // uses the cNFT path (Bubblegum); otherwise falls back to a regular MPL Core NFT.
+ // Metaplex Bubblegum compressed-NFT tree config, optional and currently unread:
+ // /api/nft/mint-scene always mints a regular MPL Core asset (createV1). Setting
+ // these does not switch it to the cNFT path.
get BUBBLEGUM_MERKLE_TREE() {
return opt('BUBBLEGUM_MERKLE_TREE');
},
diff --git a/api/nft/mint-scene.js b/api/nft/mint-scene.js
index 52d07a676..c5ebf7669 100644
--- a/api/nft/mint-scene.js
+++ b/api/nft/mint-scene.js
@@ -53,9 +53,6 @@ export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'POST,OPTIONS', credentials: true })) return;
if (!method(req, res, ['POST'])) return;
- if (!ipfsPinningConfigured())
- return error(res, 503, 'not_configured', 'no IPFS pinning provider configured (set PINATA_JWT)');
-
const rl = await limits.authIp(clientIp(req));
if (!rl.success) return rateLimited(res, rl);
@@ -67,6 +64,14 @@ export default wrap(async (req, res) => {
return error(res, 401, 'unauthorized', 'sign in or provide a valid bearer token');
}
+ // Auth first, then configuration. This check used to run ahead of both the
+ // rate limiter and the auth gate, so an anonymous caller was told the exact
+ // deployment secret the platform is missing (503 "set PINATA_JWT") and got
+ // there without spending a rate-limit token. A signed-in minter is who this
+ // message is for.
+ if (!ipfsPinningConfigured())
+ return error(res, 503, 'not_configured', 'no IPFS pinning provider configured (set PINATA_JWT)');
+
// A scene GLB plus its PNG thumbnail, base64-inflated by 4/3, comfortably
// clears readJson's 1 MB default, which rejected every real mint with a 413
// before the handler saw a byte. 8 MB matches server/index.mjs BODY_LIMIT, the
diff --git a/api/nft/resolve.js b/api/nft/resolve.js
index f6d210faf..f21975cd0 100644
--- a/api/nft/resolve.js
+++ b/api/nft/resolve.js
@@ -17,13 +17,6 @@ const RESOLVE_TTL_SECONDS = 6 * 60 * 60; // 6h
// descriptor during a Helius/Alchemy outage is correct, far better than a 502.
const RESOLVE_STALE_TTL_SECONDS = 30 * 24 * 60 * 60; // 30d
-// Alchemy NFT API host per EVM chainId. An id of the form
-// "chainId:contract:tokenId" (exactly what api/users/[username]/collectibles.js
-// emits for every EVM collectible) used to have its chainId parsed and then
-// thrown away, so a Base or Polygon NFT was always looked up on Ethereum
-// mainnet and came back as a 404 or, worse, as an unrelated Ethereum token that
-// happens to share the contract/tokenId pair. Keep this list aligned with the
-// hosts in api/_lib/evm/rpc.js ALCHEMY_SUBDOMAIN.
// A provider that answers but never finishes must not hold the request open
// until the platform's own timeout fires; both upstreams are read-only lookups.
const UPSTREAM_TIMEOUT_MS = 15000;
@@ -114,6 +107,19 @@ function pickModel(doc) {
return { model: null, mime: null };
}
+// Alchemy NFT API host per EVM chainId. An id of the form
+// "chainId:contract:tokenId" (exactly what api/users/[username]/collectibles.js
+// emits for every EVM collectible) used to have its chainId parsed and then
+// thrown away, so a Base or Polygon NFT was always looked up on Ethereum
+// mainnet and came back as a 404 or, worse, as an unrelated Ethereum token that
+// happens to share the contract/tokenId pair.
+//
+// This map is also the endpoint's supported-chain gate: a chainId missing here
+// is rejected 400 before either rung runs, so an omission costs the caller the
+// keyless on-chain read too, which needs no Alchemy key at all. Keep it aligned
+// with api/_lib/evm/rpc.js ALCHEMY_SUBDOMAIN, which is what let polygon-amoy and
+// avax-fuji drop out: both are in that map and in the chain registry with public
+// RPCs, and both answered "unsupported evm chainId" here regardless.
const ALCHEMY_NFT_HOST = {
1: 'eth-mainnet',
10: 'opt-mainnet',
@@ -125,8 +131,11 @@ const ALCHEMY_NFT_HOST = {
43114: 'avax-mainnet',
59144: 'linea-mainnet',
534352: 'scroll-mainnet',
+ // testnets
84532: 'base-sepolia',
421614: 'arb-sepolia',
+ 43113: 'avax-fuji',
+ 80002: 'polygon-amoy',
11155111: 'eth-sepolia',
11155420: 'opt-sepolia',
};