From 1a19e1484580ca2d07750df61a7f53b8ae2f82ce Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 13 Oct 2025 19:58:30 +0000 Subject: [PATCH] SDK: Fix getNFT tests, Playground: Fix build (#8242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR primarily focuses on updating the `tokenAddress` format in the tests and modifying the instantiation of the `thirdwebAI` and `thirdwebClient` to use a consistent `SECRET_KEY` variable for better readability and maintainability. ### Detailed summary - Updated `tokenAddress` format in `getNFT.test.ts` and `getNFTs.test.ts`. - Changed `thirdwebAI` instantiation in `route.ts` to use `SECRET_KEY` variable. - Modified `thirdwebClient` instantiation in `paywall/route.ts` to use `SECRET_KEY` variable. - Maintained existing environment variable usage for wallet addresses and API URLs. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit * **New Features** * Added a new public GET paywall endpoint. * **Tests** * Updated NFT test snapshots to correct token address casing. * Removed an obsolete single-line test comment. * **Chores** * API handlers now initialize needed services per request and read required environment secrets. --- apps/playground-web/src/app/api/chat/route.ts | 12 ++++--- .../src/app/api/paywall/route.ts | 34 ++++++++++--------- .../src/extensions/erc721/read/getNFT.test.ts | 2 +- .../extensions/erc721/read/getNFTs.test.ts | 11 +++--- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/apps/playground-web/src/app/api/chat/route.ts b/apps/playground-web/src/app/api/chat/route.ts index 6ad9617c4be..550b5e3a3ff 100644 --- a/apps/playground-web/src/app/api/chat/route.ts +++ b/apps/playground-web/src/app/api/chat/route.ts @@ -4,12 +4,14 @@ import { convertToModelMessages, streamText, type UIMessage } from "ai"; // Allow streaming responses up to 5 minutes export const maxDuration = 300; -const thirdwebAI = createThirdwebAI({ - baseURL: `https://${process.env.NEXT_PUBLIC_API_URL}`, - secretKey: process.env.THIRDWEB_SECRET_KEY, -}); - export async function POST(req: Request) { + const SECRET_KEY = process.env.THIRDWEB_SECRET_KEY as string; + + const thirdwebAI = createThirdwebAI({ + baseURL: `https://${process.env.NEXT_PUBLIC_API_URL}`, + secretKey: SECRET_KEY, + }); + const body = await req.json(); const { messages, id }: { messages: UIMessage[]; id: string } = body; diff --git a/apps/playground-web/src/app/api/paywall/route.ts b/apps/playground-web/src/app/api/paywall/route.ts index 96a7534f573..ec084cea428 100644 --- a/apps/playground-web/src/app/api/paywall/route.ts +++ b/apps/playground-web/src/app/api/paywall/route.ts @@ -7,25 +7,27 @@ import { token } from "../../payments/x402/components/constants"; // Allow streaming responses up to 5 minutes export const maxDuration = 300; -const client = createThirdwebClient({ - secretKey: process.env.THIRDWEB_SECRET_KEY as string, -}); +export async function GET(request: NextRequest) { + const SECRET_KEY = process.env.THIRDWEB_SECRET_KEY as string; -const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string; -// const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_SMART_WALLET as string; -const ENGINE_VAULT_ACCESS_TOKEN = process.env - .ENGINE_VAULT_ACCESS_TOKEN as string; -// const API_URL = `https://${process.env.NEXT_PUBLIC_API_URL || "api.thirdweb.com"}`; -const API_URL = "http://localhost:3030"; + const client = createThirdwebClient({ + secretKey: SECRET_KEY, + }); -const twFacilitator = facilitator({ - baseUrl: `${API_URL}/v1/payments/x402`, - client, - serverWalletAddress: BACKEND_WALLET_ADDRESS, - vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN, -}); + const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string; + // const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_SMART_WALLET as string; + const ENGINE_VAULT_ACCESS_TOKEN = process.env + .ENGINE_VAULT_ACCESS_TOKEN as string; + // const API_URL = `https://${process.env.NEXT_PUBLIC_API_URL || "api.thirdweb.com"}`; + const API_URL = "http://localhost:3030"; + + const twFacilitator = facilitator({ + baseUrl: `${API_URL}/v1/payments/x402`, + client, + serverWalletAddress: BACKEND_WALLET_ADDRESS, + vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN, + }); -export async function GET(request: NextRequest) { const paymentData = request.headers.get("X-PAYMENT"); const queryParams = request.nextUrl.searchParams; diff --git a/packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts b/packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts index 77ad899d233..b4726532290 100644 --- a/packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts +++ b/packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts @@ -44,7 +44,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => { "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1", }, "owner": null, - "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e", + "tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e", "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1", "type": "ERC721", } diff --git a/packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts b/packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts index e4c437eccfa..7b55f32d77f 100644 --- a/packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts +++ b/packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts @@ -13,7 +13,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => { }); expect(nfts.length).toBe(5); - // TODO (insight): re-enable once insight fixes the client id caching issue expect(nfts).toMatchInlineSnapshot(` [ { @@ -49,7 +48,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => { "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/0", }, "owner": null, - "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e", + "tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e", "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/0", "type": "ERC721", }, @@ -86,7 +85,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => { "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1", }, "owner": null, - "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e", + "tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e", "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1", "type": "ERC721", }, @@ -123,7 +122,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => { "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/2", }, "owner": null, - "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e", + "tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e", "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/2", "type": "ERC721", }, @@ -160,7 +159,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => { "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/3", }, "owner": null, - "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e", + "tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e", "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/3", "type": "ERC721", }, @@ -197,7 +196,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => { "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/4", }, "owner": null, - "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e", + "tokenAddress": "0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e", "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/4", "type": "ERC721", },