diff --git a/packages/thirdweb/src/exports/extensions/erc1155.ts b/packages/thirdweb/src/exports/extensions/erc1155.ts index 0274266b2c3..cb79cc5132a 100644 --- a/packages/thirdweb/src/exports/extensions/erc1155.ts +++ b/packages/thirdweb/src/exports/extensions/erc1155.ts @@ -17,9 +17,9 @@ export { } from "../../extensions/erc1155/read/getOwnedNFTs.js"; export { nextTokenIdToMint } from "../../extensions/erc1155/read/nextTokenIdToMint.js"; export { - tokenURI, + uri as tokenURI, type TokenUriParams, -} from "../../extensions/erc1155/read/tokenURI.js"; +} from "../../extensions/erc1155/read/uri.js"; export { totalSupply, type TotalSupplyParams, diff --git a/packages/thirdweb/src/extensions/erc1155/read/getNFT.test.ts b/packages/thirdweb/src/extensions/erc1155/read/getNFT.test.ts new file mode 100644 index 00000000000..d5e1f0e9ab0 --- /dev/null +++ b/packages/thirdweb/src/extensions/erc1155/read/getNFT.test.ts @@ -0,0 +1,51 @@ +import { describe, it, expect, vi, afterEach } from "vitest"; + +import { getNFT } from "./getNFT.js"; +import { DROP1155_CONTRACT } from "~test/test-contracts.js"; + +const fetchSpy = vi.spyOn(globalThis, "fetch"); + +describe("erc1155.getNFT", () => { + afterEach(() => { + fetchSpy.mockClear(); + }); + it.runIf(process.env.TW_SECRET_KEY)("without owner", async () => { + const nft = await getNFT({ + contract: DROP1155_CONTRACT, + tokenId: 2n, + }); + expect(nft).toMatchInlineSnapshot(` + { + "id": 2n, + "metadata": { + "animation_url": "ipfs://QmYoM63qaumQznBRx38tQjkY4ewbymeFb2KWBhkfMqNHax/3.mp4", + "attributes": [ + { + "trait_type": "Revenue Share", + "value": "15%", + }, + { + "trait_type": "Max Supply", + "value": "5000", + }, + { + "trait_type": "Max Per Wallet", + "value": "10", + }, + ], + "background_color": "", + "description": "", + "external_url": "https://auraexchange.org", + "image": "ipfs://QmYoM63qaumQznBRx38tQjkY4ewbymeFb2KWBhkfMqNHax/2.png", + "name": "Aura Platinum", + }, + "owner": null, + "supply": 2519n, + "tokenURI": "ipfs://QmbMXdbnNUAuGRoY6c6G792c6T9utfaBGqRUaMaRUf52Cb/2", + "type": "ERC1155", + } + `); + // 2 fetch calls: 1 for RPC, 1 for fetching the tokenUri + expect(fetchSpy).toHaveBeenCalledTimes(2); + }); +}); diff --git a/packages/thirdweb/src/extensions/erc1155/read/getNFT.ts b/packages/thirdweb/src/extensions/erc1155/read/getNFT.ts index cd67ff68b1a..c677454b25e 100644 --- a/packages/thirdweb/src/extensions/erc1155/read/getNFT.ts +++ b/packages/thirdweb/src/extensions/erc1155/read/getNFT.ts @@ -1,7 +1,7 @@ import type { BaseTransactionOptions } from "../../../transaction/types.js"; import { fetchTokenMetadata } from "../../../utils/nft/fetchTokenMetadata.js"; import { parseNFT, type NFT } from "../../../utils/nft/parseNft.js"; -import { tokenURI, type TokenUriParams } from "./tokenURI.js"; +import { uri, type TokenUriParams } from "./uri.js"; import { totalSupply } from "./totalSupply.js"; /** @@ -26,19 +26,19 @@ export type GetNFTParams = TokenUriParams; export async function getNFT( options: BaseTransactionOptions, ): Promise> { - const [uri, supply] = await Promise.all([ - tokenURI(options), + const [tokenUri, supply] = await Promise.all([ + uri(options), totalSupply(options), ]); return parseNFT( await fetchTokenMetadata({ client: options.contract.client, tokenId: options.tokenId, - tokenUri: uri, + tokenUri, }), { tokenId: options.tokenId, - tokenUri: uri, + tokenUri, type: "ERC1155", owner: null, supply, diff --git a/packages/thirdweb/src/extensions/erc1155/read/tokenURI.ts b/packages/thirdweb/src/extensions/erc1155/read/uri.ts similarity index 73% rename from packages/thirdweb/src/extensions/erc1155/read/tokenURI.ts rename to packages/thirdweb/src/extensions/erc1155/read/uri.ts index df7e227873a..b29d64e2e84 100644 --- a/packages/thirdweb/src/extensions/erc1155/read/tokenURI.ts +++ b/packages/thirdweb/src/extensions/erc1155/read/uri.ts @@ -10,16 +10,16 @@ export type TokenUriParams = { tokenId: bigint }; * @extension ERC1155 * @example * ```ts - * import { tokenURI } from "thirdweb/extensions/erc155"; - * const uri = await tokenURI({ contract, tokenId: 1n }); + * import { uri } from "thirdweb/extensions/erc155"; + * const tokenUri = await uri({ contract, tokenId: 1n }); * ``` */ -export function tokenURI( +export function uri( options: BaseTransactionOptions, ): Promise { return readContract({ ...options, - method: "function tokenURI(uint256) returns (string)", + method: "function uri(uint256) returns (string)", params: [options.tokenId], }); } diff --git a/packages/thirdweb/test/src/test-contracts.ts b/packages/thirdweb/test/src/test-contracts.ts index bd0249799ab..f58833cdfd8 100644 --- a/packages/thirdweb/test/src/test-contracts.ts +++ b/packages/thirdweb/test/src/test-contracts.ts @@ -29,3 +29,13 @@ export const DOODLES_CONTRACT = getContract({ address: DOODLES_ADDRESS, chain: FORKED_ETHEREUM_CHAIN, }); + +// ERC1155 + +const AURA_ADDRESS = "0x42d3641255C946CC451474295d29D3505173F22A"; + +export const DROP1155_CONTRACT = getContract({ + client: TEST_CLIENT, + address: AURA_ADDRESS, + chain: FORKED_ETHEREUM_CHAIN, +});