thirdweb 5.29.4 → 5.29.5-nightly-2d7ebe2111d24448dd85ace25fc9fdbef987a57d-20240617204223

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/exports/extensions/erc721.js +3 -1
  2. package/dist/cjs/exports/extensions/erc721.js.map +1 -1
  3. package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js +116 -0
  4. package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js.map +1 -0
  5. package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js +116 -0
  6. package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js.map +1 -0
  7. package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js +123 -0
  8. package/dist/cjs/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js.map +1 -0
  9. package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js +89 -0
  10. package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js.map +1 -0
  11. package/dist/cjs/react/core/design-system/CustomThemeProvider.js +1 -6
  12. package/dist/cjs/react/core/design-system/CustomThemeProvider.js.map +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/version.js.map +1 -1
  15. package/dist/esm/exports/extensions/erc721.js +1 -0
  16. package/dist/esm/exports/extensions/erc721.js.map +1 -1
  17. package/dist/esm/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js +109 -0
  18. package/dist/esm/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.js.map +1 -0
  19. package/dist/esm/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js +109 -0
  20. package/dist/esm/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.js.map +1 -0
  21. package/dist/esm/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js +116 -0
  22. package/dist/esm/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.js.map +1 -0
  23. package/dist/esm/extensions/erc721/drops/write/updateMetadata.js +84 -0
  24. package/dist/esm/extensions/erc721/drops/write/updateMetadata.js.map +1 -0
  25. package/dist/esm/react/core/design-system/CustomThemeProvider.js +1 -6
  26. package/dist/esm/react/core/design-system/CustomThemeProvider.js.map +1 -1
  27. package/dist/esm/version.js +1 -1
  28. package/dist/esm/version.js.map +1 -1
  29. package/dist/types/exports/extensions/erc721.d.ts +1 -0
  30. package/dist/types/exports/extensions/erc721.d.ts.map +1 -1
  31. package/dist/types/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.d.ts +80 -0
  32. package/dist/types/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.d.ts.map +1 -0
  33. package/dist/types/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.d.ts +80 -0
  34. package/dist/types/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.d.ts.map +1 -0
  35. package/dist/types/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.d.ts +87 -0
  36. package/dist/types/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.d.ts.map +1 -0
  37. package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts +37 -0
  38. package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts.map +1 -0
  39. package/dist/types/react/core/design-system/CustomThemeProvider.d.ts.map +1 -1
  40. package/dist/types/version.d.ts +1 -1
  41. package/dist/types/version.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/exports/extensions/erc721.ts +4 -0
  44. package/src/extensions/erc721/__generated__/DropERC721/write/freezeBatchBaseURI.ts +141 -0
  45. package/src/extensions/erc721/__generated__/DropERC721/write/setMaxTotalSupply.ts +144 -0
  46. package/src/extensions/erc721/__generated__/DropERC721/write/updateBatchBaseURI.ts +149 -0
  47. package/src/extensions/erc721/drops/write/updateMetadata.test.ts +127 -0
  48. package/src/extensions/erc721/drops/write/updateMetadata.ts +123 -0
  49. package/src/react/core/design-system/CustomThemeProvider.tsx +1 -6
  50. package/src/version.ts +1 -1
@@ -0,0 +1,149 @@
1
+ import type { AbiParameterToPrimitiveType } from "abitype";
2
+ import type {
3
+ BaseTransactionOptions,
4
+ WithOverrides,
5
+ } from "../../../../../transaction/types.js";
6
+ import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
7
+ import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
8
+ import { once } from "../../../../../utils/promise/once.js";
9
+ import type { ThirdwebContract } from "../../../../../contract/contract.js";
10
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
11
+
12
+ /**
13
+ * Represents the parameters for the "updateBatchBaseURI" function.
14
+ */
15
+ export type UpdateBatchBaseURIParams = WithOverrides<{
16
+ index: AbiParameterToPrimitiveType<{ type: "uint256"; name: "_index" }>;
17
+ uri: AbiParameterToPrimitiveType<{ type: "string"; name: "_uri" }>;
18
+ }>;
19
+
20
+ export const FN_SELECTOR = "0xde903ddd" as const;
21
+ const FN_INPUTS = [
22
+ {
23
+ type: "uint256",
24
+ name: "_index",
25
+ },
26
+ {
27
+ type: "string",
28
+ name: "_uri",
29
+ },
30
+ ] as const;
31
+ const FN_OUTPUTS = [] as const;
32
+
33
+ /**
34
+ * Checks if the `updateBatchBaseURI` method is supported by the given contract.
35
+ * @param contract The ThirdwebContract.
36
+ * @returns A promise that resolves to a boolean indicating if the `updateBatchBaseURI` method is supported.
37
+ * @extension ERC721
38
+ * @example
39
+ * ```ts
40
+ * import { isUpdateBatchBaseURISupported } from "thirdweb/extensions/erc721";
41
+ *
42
+ * const supported = await isUpdateBatchBaseURISupported(contract);
43
+ * ```
44
+ */
45
+ export async function isUpdateBatchBaseURISupported(
46
+ contract: ThirdwebContract<any>,
47
+ ) {
48
+ return detectMethod({
49
+ contract,
50
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Encodes the parameters for the "updateBatchBaseURI" function.
56
+ * @param options - The options for the updateBatchBaseURI function.
57
+ * @returns The encoded ABI parameters.
58
+ * @extension ERC721
59
+ * @example
60
+ * ```ts
61
+ * import { encodeUpdateBatchBaseURIParams } "thirdweb/extensions/erc721";
62
+ * const result = encodeUpdateBatchBaseURIParams({
63
+ * index: ...,
64
+ * uri: ...,
65
+ * });
66
+ * ```
67
+ */
68
+ export function encodeUpdateBatchBaseURIParams(
69
+ options: UpdateBatchBaseURIParams,
70
+ ) {
71
+ return encodeAbiParameters(FN_INPUTS, [options.index, options.uri]);
72
+ }
73
+
74
+ /**
75
+ * Encodes the "updateBatchBaseURI" function into a Hex string with its parameters.
76
+ * @param options - The options for the updateBatchBaseURI function.
77
+ * @returns The encoded hexadecimal string.
78
+ * @extension ERC721
79
+ * @example
80
+ * ```ts
81
+ * import { encodeUpdateBatchBaseURI } "thirdweb/extensions/erc721";
82
+ * const result = encodeUpdateBatchBaseURI({
83
+ * index: ...,
84
+ * uri: ...,
85
+ * });
86
+ * ```
87
+ */
88
+ export function encodeUpdateBatchBaseURI(options: UpdateBatchBaseURIParams) {
89
+ // we do a "manual" concat here to avoid the overhead of the "concatHex" function
90
+ // we can do this because we know the specific formats of the values
91
+ return (FN_SELECTOR +
92
+ encodeUpdateBatchBaseURIParams(options).slice(
93
+ 2,
94
+ )) as `${typeof FN_SELECTOR}${string}`;
95
+ }
96
+
97
+ /**
98
+ * Prepares a transaction to call the "updateBatchBaseURI" function on the contract.
99
+ * @param options - The options for the "updateBatchBaseURI" function.
100
+ * @returns A prepared transaction object.
101
+ * @extension ERC721
102
+ * @example
103
+ * ```ts
104
+ * import { updateBatchBaseURI } from "thirdweb/extensions/erc721";
105
+ *
106
+ * const transaction = updateBatchBaseURI({
107
+ * contract,
108
+ * index: ...,
109
+ * uri: ...,
110
+ * overrides: {
111
+ * ...
112
+ * }
113
+ * });
114
+ *
115
+ * // Send the transaction
116
+ * ...
117
+ *
118
+ * ```
119
+ */
120
+ export function updateBatchBaseURI(
121
+ options: BaseTransactionOptions<
122
+ | UpdateBatchBaseURIParams
123
+ | {
124
+ asyncParams: () => Promise<UpdateBatchBaseURIParams>;
125
+ }
126
+ >,
127
+ ) {
128
+ const asyncOptions = once(async () => {
129
+ return "asyncParams" in options ? await options.asyncParams() : options;
130
+ });
131
+
132
+ return prepareContractCall({
133
+ contract: options.contract,
134
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
135
+ params: async () => {
136
+ const resolvedOptions = await asyncOptions();
137
+ return [resolvedOptions.index, resolvedOptions.uri] as const;
138
+ },
139
+ value: async () => (await asyncOptions()).overrides?.value,
140
+ accessList: async () => (await asyncOptions()).overrides?.accessList,
141
+ gas: async () => (await asyncOptions()).overrides?.gas,
142
+ gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
143
+ maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
144
+ maxPriorityFeePerGas: async () =>
145
+ (await asyncOptions()).overrides?.maxPriorityFeePerGas,
146
+ nonce: async () => (await asyncOptions()).overrides?.nonce,
147
+ extraGas: async () => (await asyncOptions()).overrides?.extraGas,
148
+ });
149
+ }
@@ -0,0 +1,127 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+ import { ANVIL_CHAIN } from "~test/chains.js";
3
+ import { TEST_CLIENT } from "~test/test-clients.js";
4
+ import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
5
+
6
+ import {
7
+ type ThirdwebContract,
8
+ getContract,
9
+ } from "../../../../contract/contract.js";
10
+ import { deployERC721Contract } from "../../../../extensions/prebuilts/deploy-erc721.js";
11
+ import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js";
12
+ import type { NFTInput } from "../../../../utils/nft/parseNft.js";
13
+ import { getNFT } from "../../read/getNFT.js";
14
+ import { getNFTs } from "../../read/getNFTs.js";
15
+ import { lazyMint } from "../../write/lazyMint.js";
16
+ import { getUpdateMetadataParams, updateMetadata } from "./updateMetadata.js";
17
+
18
+ let contract: ThirdwebContract;
19
+ const account = TEST_ACCOUNT_A;
20
+ const client = TEST_CLIENT;
21
+ const chain = ANVIL_CHAIN;
22
+
23
+ describe("erc721: updateMetadata", () => {
24
+ beforeEach(async () => {
25
+ const address = await deployERC721Contract({
26
+ client,
27
+ chain,
28
+ account,
29
+ type: "DropERC721",
30
+ params: {
31
+ name: "NFTDrop",
32
+ },
33
+ });
34
+ contract = getContract({
35
+ address,
36
+ client,
37
+ chain,
38
+ });
39
+ });
40
+
41
+ it("should update the metadata for the selected token | case 1", async () => {
42
+ const metadatas: NFTInput[] = [
43
+ { name: "token 0" },
44
+ { name: "token 1" },
45
+ { name: "token 2" },
46
+ ];
47
+
48
+ const lazyMintTx = lazyMint({ contract, nfts: metadatas });
49
+ await sendAndConfirmTransaction({ transaction: lazyMintTx, account });
50
+
51
+ const transaction = updateMetadata({
52
+ contract,
53
+ targetTokenId: 0n,
54
+ newMetadata: { name: "token 0 - updated" },
55
+ client,
56
+ });
57
+ await sendAndConfirmTransaction({ transaction, account });
58
+ const nfts = await getNFTs({ contract });
59
+ expect(nfts[0]?.metadata.name).toBe("token 0 - updated");
60
+
61
+ // The other tokens should not change
62
+ expect(nfts[1]?.metadata.name).toBe("token 1");
63
+ expect(nfts[2]?.metadata.name).toBe("token 2");
64
+ });
65
+
66
+ it("should update the metadata for the selected token | case 2", async () => {
67
+ const nftBatch1: NFTInput[] = [
68
+ { name: "token 0" },
69
+ { name: "token 1" },
70
+ { name: "token 2" },
71
+ ];
72
+
73
+ const batch1 = lazyMint({ contract, nfts: nftBatch1 });
74
+ await sendAndConfirmTransaction({ transaction: batch1, account });
75
+
76
+ const nftBatch2: NFTInput[] = [
77
+ { name: "token 3" },
78
+ { name: "token 4" },
79
+ { name: "token 5" },
80
+ ];
81
+ const batch2 = lazyMint({ contract, nfts: nftBatch2 });
82
+ await sendAndConfirmTransaction({ transaction: batch2, account });
83
+
84
+ // firstly, update the token in the first batch
85
+ const transaction1 = updateMetadata({
86
+ contract,
87
+ targetTokenId: 0n,
88
+ newMetadata: { name: "token 0 - updated" },
89
+ client,
90
+ });
91
+ await sendAndConfirmTransaction({ transaction: transaction1, account });
92
+ const nft = await getNFT({ contract, tokenId: 0n });
93
+ expect(nft.metadata.name).toBe("token 0 - updated");
94
+
95
+ const tokenUriAfterUpdatedFirstTime = nft.tokenURI;
96
+
97
+ // Update token in the second batch
98
+ const transaction2 = updateMetadata({
99
+ contract,
100
+ targetTokenId: 5n,
101
+ newMetadata: { name: "token 5 - updated" },
102
+ client,
103
+ });
104
+ await sendAndConfirmTransaction({ transaction: transaction2, account });
105
+
106
+ const allNfts = await getNFTs({ contract });
107
+ expect(allNfts[0]?.metadata.name).toBe("token 0 - updated");
108
+ expect(allNfts.at(-1)?.metadata.name).toBe("token 5 - updated");
109
+
110
+ // The tokenUri of tokenId#0 after the second updateMetadata should still be the same
111
+ // since it belong to another batch
112
+ expect(allNfts[0]?.tokenURI).toBe(tokenUriAfterUpdatedFirstTime);
113
+ });
114
+
115
+ it("should throw error if there's no batch", async () => {
116
+ await expect(() =>
117
+ getUpdateMetadataParams({
118
+ contract,
119
+ targetTokenId: 0n,
120
+ newMetadata: { name: "token 0 - updated" },
121
+ client,
122
+ }),
123
+ ).rejects.toThrowError(
124
+ "No base URI set. Please set a base URI before updating metadata",
125
+ );
126
+ });
127
+ });
@@ -0,0 +1,123 @@
1
+ import type { ThirdwebClient } from "../../../../client/client.js";
2
+ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
3
+ import type { NFT, NFTInput } from "../../../../utils/nft/parseNft.js";
4
+ import {
5
+ type UpdateBatchBaseURIParams,
6
+ updateBatchBaseURI,
7
+ } from "../../__generated__/DropERC721/write/updateBatchBaseURI.js";
8
+ import { getBaseURICount } from "../../__generated__/IBatchMintMetadata/read/getBaseURICount.js";
9
+
10
+ export type UpdateMetadataParams = {
11
+ targetTokenId: bigint;
12
+ newMetadata: NFTInput;
13
+ client: ThirdwebClient;
14
+ };
15
+
16
+ /**
17
+ * @internal
18
+ */
19
+ export async function getUpdateMetadataParams(
20
+ options: BaseTransactionOptions<UpdateMetadataParams>,
21
+ ): Promise<UpdateBatchBaseURIParams> {
22
+ const { contract, targetTokenId, newMetadata, client } = options;
23
+ const batchCount = await getBaseURICount(options);
24
+ if (batchCount === 0n) {
25
+ throw new Error(
26
+ "No base URI set. Please set a base URI before updating metadata",
27
+ );
28
+ }
29
+
30
+ // Look for the batchId & determine the start + end tokenId of the batch
31
+ const [{ getBatchIdAtIndex }, { getNFT }] = await Promise.all([
32
+ import("../../__generated__/IBatchMintMetadata/read/getBatchIdAtIndex.js"),
33
+ import("../../read/getNFT.js"),
34
+ ]);
35
+ let startTokenId = 0n;
36
+ let endTokenId = 0n;
37
+ let batchIndex = 0n;
38
+ for (let i = 0n; i < batchCount; i += 1n) {
39
+ batchIndex = i;
40
+ endTokenId = await getBatchIdAtIndex({ contract, index: batchIndex });
41
+ if (endTokenId > targetTokenId) {
42
+ break;
43
+ }
44
+ startTokenId = endTokenId;
45
+ }
46
+
47
+ const range = Array.from(
48
+ { length: Number(endTokenId - startTokenId) },
49
+ (_, k) => BigInt(k) + startTokenId,
50
+ );
51
+
52
+ const currentMetadatas = await Promise.all(
53
+ range.map((id) => getNFT({ contract, tokenId: id, includeOwner: false })),
54
+ );
55
+
56
+ // Abort if any of the items failed to load
57
+ if (currentMetadatas.some((item) => item === undefined || !item.tokenURI)) {
58
+ throw new Error(
59
+ `Failed to load all ${range.length} items from batchIndex: ${batchIndex}`,
60
+ );
61
+ }
62
+
63
+ const newMetadatas: NFTInput[] = [];
64
+ for (let i = 0; i < currentMetadatas.length; i++) {
65
+ const { id, metadata } = currentMetadatas[i] as NFT;
66
+ if (targetTokenId === id) {
67
+ newMetadatas.push(newMetadata);
68
+ } else {
69
+ newMetadatas.push(metadata);
70
+ }
71
+ }
72
+
73
+ const { uploadOrExtractURIs } = await import("../../../../utils/ipfs.js");
74
+ const batchOfUris = await uploadOrExtractURIs(
75
+ newMetadatas,
76
+ client,
77
+ Number(startTokenId),
78
+ );
79
+
80
+ if (!batchOfUris || !batchOfUris.length || !batchOfUris[0]) {
81
+ throw new Error("Failed to upload batch of new metadatas");
82
+ }
83
+
84
+ const baseUri = batchOfUris[0].substring(0, batchOfUris[0].lastIndexOf("/"));
85
+
86
+ // IMPORTANT: The new ipfs URI must have the trailing slash at the end
87
+ // this is required by the Drop contract
88
+ const uri = `${baseUri}/`;
89
+
90
+ return { index: batchIndex, uri };
91
+ }
92
+
93
+ /**
94
+ * Update the metadata of the single token in an NFT Drop (DropERC721) collection
95
+ * For NFT Collection, please use `setTokenURI`
96
+ * @param options
97
+ * @returns the prepared transaction
98
+ * @extension ERC721
99
+ * @example
100
+ * ```ts
101
+ * import { updateMetadata } from "thirdweb/extensions/erc721";
102
+ *
103
+ * const transaction = updateMetadata({
104
+ * contract,
105
+ * targetTokenId: 0n,
106
+ * newMetadata: {
107
+ * name: "this is the new nft name",
108
+ * description: "...",
109
+ * image: "new image uri"
110
+ * // ...
111
+ * }
112
+ * });
113
+ * ```
114
+ */
115
+ export function updateMetadata(
116
+ options: BaseTransactionOptions<UpdateMetadataParams>,
117
+ ) {
118
+ const { contract } = options;
119
+ return updateBatchBaseURI({
120
+ contract,
121
+ asyncParams: async () => getUpdateMetadataParams(options),
122
+ });
123
+ }
@@ -41,12 +41,7 @@ export function isValidTheme(theme: unknown): theme is Theme {
41
41
  return (
42
42
  theme === "dark" ||
43
43
  theme === "light" ||
44
- (typeof theme === "object" &&
45
- theme !== null &&
46
- "colors" in theme &&
47
- "fontSizes" in theme &&
48
- "radii" in theme &&
49
- "space" in theme)
44
+ (typeof theme === "object" && theme !== null && "colors" in theme)
50
45
  );
51
46
  }
52
47
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.29.4";
1
+ export const version = "5.29.5-nightly-2d7ebe2111d24448dd85ace25fc9fdbef987a57d-20240617204223";