diff --git a/platforms/src/NFT/Providers/__tests__/nft.test.ts b/platforms/src/NFT/Providers/__tests__/nft.test.ts index c308ecd9b6..15fb3c25ce 100644 --- a/platforms/src/NFT/Providers/__tests__/nft.test.ts +++ b/platforms/src/NFT/Providers/__tests__/nft.test.ts @@ -1,6 +1,6 @@ /* eslint-disable */ // ---- Test subject -import { alchemyGetNFTsUrl, NFTProvider } from "../nft"; +import { getNFTEndpoint, NFTProvider } from "../nft"; import { RequestPayload } from "@gitcoin/passport-types"; @@ -45,7 +45,7 @@ describe("Attempt verification", function () { // Check the request to get the NFTs expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(alchemyGetNFTsUrl, { + expect(mockedAxios.get).toBeCalledWith(getNFTEndpoint(), { params: { withMetadata: "false", owner: MOCK_ADDRESS_LOWER, @@ -81,4 +81,10 @@ describe("Attempt verification", function () { expect(axios.get).toHaveBeenCalledTimes(1); expect(nftPayload).toMatchObject({ valid: false }); }); + + it("should return the nft endpoint given an alchemy url", () => { + expect(getNFTEndpoint("https://eth-mainnet.alchemyapi.io/v2/123")).toBe( + "https://eth-mainnet.g.alchemy.com/nft/v2/123/getNFTs" + ); + }); }); diff --git a/platforms/src/NFT/Providers/nft.ts b/platforms/src/NFT/Providers/nft.ts index 695bf5c041..56415e0501 100644 --- a/platforms/src/NFT/Providers/nft.ts +++ b/platforms/src/NFT/Providers/nft.ts @@ -17,6 +17,12 @@ type NFTsResponse = { totalCount: number; }; +export function getNFTEndpoint(rpcUrl?: string): string { + const nftAPIKey = rpcUrl ? rpcUrl.split("/").pop() : apiKey; + + return `https://eth-mainnet.g.alchemy.com/nft/v2/${nftAPIKey}/getNFTs`; +} + // Export a NFT Provider export class NFTProvider implements Provider { // Give the provider a type so that we can select it with a payload @@ -41,7 +47,7 @@ export class NFTProvider implements Provider { totalCount: 0, }; - const providerUrl = alchemyGetNFTsUrl || payload.rpcUrl; + const providerUrl = getNFTEndpoint(payload.rpcUrl); try { const requestResponse = await axios.get(providerUrl, {