thirdweb 5.29.6-nightly-c13ffc5f8bbf88998a9bf96730a85ba1713f761a-20240618004239 → 5.30.0-nightly-991cb72bdb1b94fcf0f9a3de36b2ec8ee07ae5ec-20240619000538

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 (136) hide show
  1. package/dist/cjs/exports/extensions/erc1155.js +3 -1
  2. package/dist/cjs/exports/extensions/erc1155.js.map +1 -1
  3. package/dist/cjs/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.js +28 -0
  4. package/dist/cjs/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.js.map +1 -0
  5. package/dist/cjs/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.js +71 -0
  6. package/dist/cjs/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.js.map +1 -0
  7. package/dist/cjs/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js +115 -0
  8. package/dist/cjs/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js.map +1 -0
  9. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.js +116 -0
  10. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.js.map +1 -0
  11. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.js +126 -0
  12. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.js.map +1 -0
  13. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.js +126 -0
  14. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.js.map +1 -0
  15. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.js +123 -0
  16. package/dist/cjs/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.js.map +1 -0
  17. package/dist/cjs/extensions/erc1155/drops/write/updateMetadata.js +89 -0
  18. package/dist/cjs/extensions/erc1155/drops/write/updateMetadata.js.map +1 -0
  19. package/dist/cjs/pay/buyWithCrypto/getQuote.js +19 -21
  20. package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
  21. package/dist/cjs/pay/buyWithCrypto/getStatus.js.map +1 -1
  22. package/dist/cjs/pay/buyWithFiat/getQuote.js +19 -20
  23. package/dist/cjs/pay/buyWithFiat/getQuote.js.map +1 -1
  24. package/dist/cjs/pay/buyWithFiat/getStatus.js.map +1 -1
  25. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  26. package/dist/cjs/react/native/hooks/wallets/useActiveWalletChain.js +1 -1
  27. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +1 -0
  28. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  29. package/dist/cjs/react/web/hooks/wallets/useActiveWalletChain.js +1 -1
  30. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +3 -0
  31. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/useConnectModal.js.map +1 -1
  33. package/dist/cjs/react/web/ui/components/CopyIcon.js +2 -1
  34. package/dist/cjs/react/web/ui/components/CopyIcon.js.map +1 -1
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/cjs/wallets/wallet-connect/controller.js +6 -6
  37. package/dist/cjs/wallets/wallet-connect/controller.js.map +1 -1
  38. package/dist/esm/exports/extensions/erc1155.js +1 -0
  39. package/dist/esm/exports/extensions/erc1155.js.map +1 -1
  40. package/dist/esm/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.js +24 -0
  41. package/dist/esm/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.js.map +1 -0
  42. package/dist/esm/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.js +65 -0
  43. package/dist/esm/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.js.map +1 -0
  44. package/dist/esm/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js +107 -0
  45. package/dist/esm/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js.map +1 -0
  46. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.js +109 -0
  47. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.js.map +1 -0
  48. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.js +119 -0
  49. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.js.map +1 -0
  50. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.js +119 -0
  51. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.js.map +1 -0
  52. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.js +116 -0
  53. package/dist/esm/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.js.map +1 -0
  54. package/dist/esm/extensions/erc1155/drops/write/updateMetadata.js +84 -0
  55. package/dist/esm/extensions/erc1155/drops/write/updateMetadata.js.map +1 -0
  56. package/dist/esm/pay/buyWithCrypto/getQuote.js +19 -21
  57. package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
  58. package/dist/esm/pay/buyWithCrypto/getStatus.js.map +1 -1
  59. package/dist/esm/pay/buyWithFiat/getQuote.js +19 -20
  60. package/dist/esm/pay/buyWithFiat/getQuote.js.map +1 -1
  61. package/dist/esm/pay/buyWithFiat/getStatus.js.map +1 -1
  62. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  63. package/dist/esm/react/native/hooks/wallets/useActiveWalletChain.js +1 -1
  64. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +1 -0
  65. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  66. package/dist/esm/react/web/hooks/wallets/useActiveWalletChain.js +1 -1
  67. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +3 -0
  68. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  69. package/dist/esm/react/web/ui/ConnectWallet/useConnectModal.js.map +1 -1
  70. package/dist/esm/react/web/ui/components/CopyIcon.js +2 -1
  71. package/dist/esm/react/web/ui/components/CopyIcon.js.map +1 -1
  72. package/dist/esm/version.js +1 -1
  73. package/dist/esm/wallets/wallet-connect/controller.js +6 -6
  74. package/dist/esm/wallets/wallet-connect/controller.js.map +1 -1
  75. package/dist/types/exports/extensions/erc1155.d.ts +1 -0
  76. package/dist/types/exports/extensions/erc1155.d.ts.map +1 -1
  77. package/dist/types/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.d.ts +29 -0
  78. package/dist/types/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.d.ts.map +1 -0
  79. package/dist/types/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.d.ts +46 -0
  80. package/dist/types/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.d.ts.map +1 -0
  81. package/dist/types/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.d.ts +85 -0
  82. package/dist/types/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.d.ts.map +1 -0
  83. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.d.ts +80 -0
  84. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.d.ts.map +1 -0
  85. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.d.ts +87 -0
  86. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.d.ts.map +1 -0
  87. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.d.ts +87 -0
  88. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.d.ts.map +1 -0
  89. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.d.ts +87 -0
  90. package/dist/types/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.d.ts.map +1 -0
  91. package/dist/types/extensions/erc1155/drops/write/updateMetadata.d.ts +37 -0
  92. package/dist/types/extensions/erc1155/drops/write/updateMetadata.d.ts.map +1 -0
  93. package/dist/types/pay/buyWithCrypto/getQuote.d.ts +6 -0
  94. package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
  95. package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -0
  96. package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
  97. package/dist/types/pay/buyWithFiat/getQuote.d.ts +11 -1
  98. package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
  99. package/dist/types/pay/buyWithFiat/getStatus.d.ts +4 -0
  100. package/dist/types/pay/buyWithFiat/getStatus.d.ts.map +1 -1
  101. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +1 -0
  102. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  103. package/dist/types/react/native/hooks/wallets/useActiveWalletChain.d.ts +1 -1
  104. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  105. package/dist/types/react/web/hooks/wallets/useActiveWalletChain.d.ts +1 -1
  106. package/dist/types/react/web/ui/ConnectWallet/ConnectButtonProps.d.ts +44 -4
  107. package/dist/types/react/web/ui/ConnectWallet/ConnectButtonProps.d.ts.map +1 -1
  108. package/dist/types/react/web/ui/ConnectWallet/useConnectModal.d.ts +1 -1
  109. package/dist/types/react/web/ui/components/CopyIcon.d.ts.map +1 -1
  110. package/dist/types/version.d.ts +1 -1
  111. package/dist/types/wallets/wallet-connect/controller.d.ts.map +1 -1
  112. package/package.json +2 -2
  113. package/src/exports/extensions/erc1155.ts +5 -0
  114. package/src/extensions/erc1155/__generated__/BatchMintMetadata/events/BatchMetadataUpdate.ts +25 -0
  115. package/src/extensions/erc1155/__generated__/BatchMintMetadata/read/getBaseURICount.ts +74 -0
  116. package/src/extensions/erc1155/__generated__/BatchMintMetadata/read/getBatchIdAtIndex.ts +131 -0
  117. package/src/extensions/erc1155/__generated__/DropERC1155/write/freezeBatchBaseURI.ts +141 -0
  118. package/src/extensions/erc1155/__generated__/DropERC1155/write/setMaxTotalSupply.ts +155 -0
  119. package/src/extensions/erc1155/__generated__/DropERC1155/write/setSaleRecipientForToken.ts +157 -0
  120. package/src/extensions/erc1155/__generated__/DropERC1155/write/updateBatchBaseURI.ts +149 -0
  121. package/src/extensions/erc1155/drops/write/updateMetadata.test.ts +127 -0
  122. package/src/extensions/erc1155/drops/write/updateMetadata.ts +125 -0
  123. package/src/pay/buyWithCrypto/getQuote.ts +27 -27
  124. package/src/pay/buyWithCrypto/getStatus.ts +1 -0
  125. package/src/pay/buyWithFiat/getQuote.ts +33 -27
  126. package/src/pay/buyWithFiat/getStatus.ts +5 -0
  127. package/src/react/core/hooks/transaction/useSendTransaction.ts +1 -0
  128. package/src/react/native/hooks/wallets/useActiveWalletChain.ts +1 -1
  129. package/src/react/web/hooks/transaction/useSendTransaction.tsx +1 -0
  130. package/src/react/web/hooks/wallets/useActiveWalletChain.ts +1 -1
  131. package/src/react/web/ui/ConnectWallet/ConnectButtonProps.ts +45 -4
  132. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +3 -0
  133. package/src/react/web/ui/ConnectWallet/useConnectModal.tsx +1 -1
  134. package/src/react/web/ui/components/CopyIcon.tsx +5 -6
  135. package/src/version.ts +1 -1
  136. package/src/wallets/wallet-connect/controller.ts +6 -5
@@ -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 ERC1155
38
+ * @example
39
+ * ```ts
40
+ * import { isUpdateBatchBaseURISupported } from "thirdweb/extensions/erc1155";
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 ERC1155
59
+ * @example
60
+ * ```ts
61
+ * import { encodeUpdateBatchBaseURIParams } "thirdweb/extensions/erc1155";
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 ERC1155
79
+ * @example
80
+ * ```ts
81
+ * import { encodeUpdateBatchBaseURI } "thirdweb/extensions/erc1155";
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 ERC1155
102
+ * @example
103
+ * ```ts
104
+ * import { updateBatchBaseURI } from "thirdweb/extensions/erc1155";
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 { deployERC1155Contract } from "../../../../extensions/prebuilts/deploy-erc1155.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.runIf(process.env.TW_SECRET_KEY)("erc1155: updateMetadata", () => {
24
+ beforeEach(async () => {
25
+ const address = await deployERC1155Contract({
26
+ client,
27
+ chain,
28
+ account,
29
+ type: "DropERC1155",
30
+ params: {
31
+ name: "EditionDrop",
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,125 @@
1
+ import { getBaseURICount } from "../../../erc721/__generated__/IBatchMintMetadata/read/getBaseURICount.js";
2
+ import {
3
+ type UpdateBatchBaseURIParams,
4
+ updateBatchBaseURI,
5
+ } from "../../__generated__/DropERC1155/write/updateBatchBaseURI.js";
6
+
7
+ import type { ThirdwebClient } from "../../../../client/client.js";
8
+ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
9
+ import type { NFT, NFTInput } from "../../../../utils/nft/parseNft.js";
10
+
11
+ export type UpdateMetadataParams = {
12
+ targetTokenId: bigint;
13
+ newMetadata: NFTInput;
14
+ client: ThirdwebClient;
15
+ };
16
+
17
+ /**
18
+ * @internal
19
+ */
20
+ export async function getUpdateMetadataParams(
21
+ options: BaseTransactionOptions<UpdateMetadataParams>,
22
+ ): Promise<UpdateBatchBaseURIParams> {
23
+ const { contract, targetTokenId, newMetadata, client } = options;
24
+ const batchCount = await getBaseURICount(options);
25
+ if (batchCount === 0n) {
26
+ throw new Error(
27
+ "No base URI set. Please set a base URI before updating metadata",
28
+ );
29
+ }
30
+
31
+ // Look for the batchId & determine the start + end tokenId of the batch
32
+ const [{ getBatchIdAtIndex }, { getNFT }] = await Promise.all([
33
+ import("../../__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js"),
34
+ import("../../read/getNFT.js"),
35
+ ]);
36
+
37
+ let startTokenId = 0n;
38
+ let endTokenId = 0n;
39
+ let batchIndex = 0n;
40
+ for (let i = 0n; i < batchCount; i += 1n) {
41
+ batchIndex = i;
42
+ endTokenId = await getBatchIdAtIndex({ contract, index: batchIndex });
43
+ if (endTokenId > targetTokenId) {
44
+ break;
45
+ }
46
+ startTokenId = endTokenId;
47
+ }
48
+
49
+ const range = Array.from(
50
+ { length: Number(endTokenId - startTokenId) },
51
+ (_, k) => BigInt(k) + startTokenId,
52
+ );
53
+
54
+ const currentMetadatas = await Promise.all(
55
+ range.map((id) => getNFT({ contract, tokenId: id })),
56
+ );
57
+
58
+ // Abort if any of the items failed to load
59
+ if (currentMetadatas.some((item) => item === undefined || !item.tokenURI)) {
60
+ throw new Error(
61
+ `Failed to load all ${range.length} items from batchIndex: ${batchIndex}`,
62
+ );
63
+ }
64
+
65
+ const newMetadatas: NFTInput[] = [];
66
+ for (let i = 0; i < currentMetadatas.length; i++) {
67
+ const { id, metadata } = currentMetadatas[i] as NFT;
68
+ if (targetTokenId === id) {
69
+ newMetadatas.push(newMetadata);
70
+ } else {
71
+ newMetadatas.push(metadata);
72
+ }
73
+ }
74
+
75
+ const { uploadOrExtractURIs } = await import("../../../../utils/ipfs.js");
76
+ const batchOfUris = await uploadOrExtractURIs(
77
+ newMetadatas,
78
+ client,
79
+ Number(startTokenId),
80
+ );
81
+
82
+ if (!batchOfUris || !batchOfUris.length || !batchOfUris[0]) {
83
+ throw new Error("Failed to upload batch of new metadatas");
84
+ }
85
+
86
+ const baseUri = batchOfUris[0].substring(0, batchOfUris[0].lastIndexOf("/"));
87
+
88
+ // IMPORTANT: The new ipfs URI must have the trailing slash at the end
89
+ // this is required by the Drop contract
90
+ const uri = `${baseUri}/`;
91
+
92
+ return { index: batchIndex, uri };
93
+ }
94
+
95
+ /**
96
+ * Update the metadata of the single token in an Edition Drop (DropERC1155) collection
97
+ * For Edition contracts, use `setTokenURI`
98
+ * @param options
99
+ * @returns the prepared transaction
100
+ * @extension ERC1155
101
+ * @example
102
+ * ```ts
103
+ * import { updateMetadata } from "thirdweb/extensions/erc1155";
104
+ *
105
+ * const transaction = updateMetadata({
106
+ * contract,
107
+ * targetTokenId: 0n,
108
+ * newMetadata: {
109
+ * name: "this is the new nft name",
110
+ * description: "...",
111
+ * image: "new image uri"
112
+ * // ...
113
+ * }
114
+ * });
115
+ * ```
116
+ */
117
+ export function updateMetadata(
118
+ options: BaseTransactionOptions<UpdateMetadataParams>,
119
+ ) {
120
+ const { contract } = options;
121
+ return updateBatchBaseURI({
122
+ contract,
123
+ asyncParams: async () => getUpdateMetadataParams(options),
124
+ });
125
+ }
@@ -65,6 +65,13 @@ export type GetBuyWithCryptoQuoteParams = {
65
65
  */
66
66
  toTokenAddress: string;
67
67
 
68
+ /**
69
+ * Extra details to store with the purchase.
70
+ *
71
+ * This details will be stored with the purchase and can be retrieved later via the status API or Webhook
72
+ */
73
+ purchaseData?: object;
74
+
68
75
  /**
69
76
  * The maximum slippage in basis points (bps) allowed for the swap.
70
77
  * For example, if you want to allow a maximum slippage of 0.5%, you should specify `50` bps.
@@ -229,34 +236,27 @@ export async function getBuyWithCryptoQuote(
229
236
  params: GetBuyWithCryptoQuoteParams,
230
237
  ): Promise<BuyWithCryptoQuote> {
231
238
  try {
232
- const queryParams = new URLSearchParams({
233
- fromAddress: params.fromAddress,
234
- fromChainId: params.fromChainId.toString(),
235
- fromTokenAddress: params.fromTokenAddress.toLowerCase(),
236
- toChainId: params.toChainId.toString(),
237
- toTokenAddress: params.toTokenAddress.toLowerCase(),
238
- });
239
-
240
- if ("fromAmount" in params && params.fromAmount) {
241
- queryParams.append("fromAmount", params.fromAmount);
242
- }
243
-
244
- if ("toAmount" in params && params.toAmount) {
245
- queryParams.append("toAmount", params.toAmount);
246
- }
247
-
248
- if (params.maxSlippageBPS) {
249
- queryParams.append("maxSlippageBPS", params.maxSlippageBPS.toString());
250
- }
251
-
252
- if (params.intentId) {
253
- queryParams.append("intentId", params.intentId);
254
- }
255
-
256
- const queryString = queryParams.toString();
257
- const url = `${getPayBuyWithCryptoQuoteEndpoint()}?${queryString}`;
239
+ const clientFetch = getClientFetch(params.client);
258
240
 
259
- const response = await getClientFetch(params.client)(url);
241
+ const response = await clientFetch(getPayBuyWithCryptoQuoteEndpoint(), {
242
+ method: "POST",
243
+ headers: {
244
+ Accept: "application/json",
245
+ "Content-Type": "application/json",
246
+ },
247
+ body: JSON.stringify({
248
+ fromAddress: params.fromAddress,
249
+ fromChainId: params.fromChainId.toString(),
250
+ fromTokenAddress: params.fromTokenAddress,
251
+ toChainId: params.toChainId.toString(),
252
+ toTokenAddress: params.toTokenAddress,
253
+ fromAmount: params.fromAmount,
254
+ toAmount: params.toAmount,
255
+ maxSlippageBPS: params.maxSlippageBPS,
256
+ intentId: params.intentId,
257
+ purchaseData: params.purchaseData,
258
+ }),
259
+ });
260
260
 
261
261
  // Assuming the response directly matches the SwapResponse interface
262
262
  if (!response.ok) {
@@ -70,6 +70,7 @@ export type BuyWithCryptoStatus =
70
70
  toAddress: string;
71
71
  failureMessage?: string;
72
72
  bridge?: string;
73
+ purchaseData?: object;
73
74
  };
74
75
 
75
76
  export type ValidBuyWithCryptoStatus = Exclude<
@@ -15,10 +15,15 @@ export type GetBuyWithFiatQuoteParams = {
15
15
  client: ThirdwebClient;
16
16
 
17
17
  /**
18
- * The address of the wallet to which the tokens will be sent.
18
+ * The address of the wallet where the tokens will be sent.
19
19
  */
20
20
  toAddress: string;
21
21
 
22
+ /**
23
+ * The address of the wallet which will be used to buy the token.
24
+ */
25
+ fromAddress: string;
26
+
22
27
  /**
23
28
  * Chain id of the token to buy.
24
29
  */
@@ -62,6 +67,13 @@ export type GetBuyWithFiatQuoteParams = {
62
67
  * Defaults to `false`
63
68
  */
64
69
  isTestMode?: boolean;
70
+
71
+ /**
72
+ * Extra details to store with the purchase.
73
+ *
74
+ * This details will be stored with the purchase and can be retrieved later via the status API or Webhook
75
+ */
76
+ purchaseData?: object;
65
77
  };
66
78
 
67
79
  /**
@@ -236,33 +248,27 @@ export async function getBuyWithFiatQuote(
236
248
  params: GetBuyWithFiatQuoteParams,
237
249
  ): Promise<BuyWithFiatQuote> {
238
250
  try {
239
- const queryParams = new URLSearchParams({
240
- toAddress: params.toAddress,
241
- fromCurrencySymbol: params.fromCurrencySymbol,
242
- toChainId: params.toChainId.toString(),
243
- toTokenAddress: params.toTokenAddress.toLowerCase(),
244
- });
245
-
246
- if (params.fromAmount) {
247
- queryParams.append("fromAmount", params.fromAmount);
248
- }
249
-
250
- if (params.toAmount) {
251
- queryParams.append("toAmount", params.toAmount);
252
- }
253
-
254
- if (params.maxSlippageBPS) {
255
- queryParams.append("maxSlippageBPS", params.maxSlippageBPS.toString());
256
- }
251
+ const clientFetch = getClientFetch(params.client);
257
252
 
258
- if (params.isTestMode) {
259
- queryParams.append("isTestMode", params.isTestMode.toString());
260
- }
261
-
262
- const queryString = queryParams.toString();
263
- const url = `${getPayBuyWithFiatQuoteEndpoint()}?${queryString}`;
264
-
265
- const response = await getClientFetch(params.client)(url);
253
+ const response = await clientFetch(getPayBuyWithFiatQuoteEndpoint(), {
254
+ method: "POST",
255
+ headers: {
256
+ Accept: "application/json",
257
+ "Content-Type": "application/json",
258
+ },
259
+ body: JSON.stringify({
260
+ toAddress: params.toAddress,
261
+ fromCurrencySymbol: params.fromCurrencySymbol,
262
+ toChainId: params.toChainId.toString(),
263
+ toTokenAddress: params.toTokenAddress,
264
+ fromAmount: params.fromAmount,
265
+ toAmount: params.toAmount,
266
+ maxSlippageBPS: params.maxSlippageBPS,
267
+ isTestMode: params.isTestMode,
268
+ purchaseData: params.purchaseData,
269
+ fromAddress: params.fromAddress,
270
+ }),
271
+ });
266
272
 
267
273
  // Assuming the response directly matches the SwapResponse interface
268
274
  if (!response.ok) {
@@ -116,6 +116,11 @@ export type BuyWithFiatStatus =
116
116
  * Message indicating the reason for failure
117
117
  */
118
118
  failureMessage?: string;
119
+
120
+ /**
121
+ * Arbitrary data sent at the time of fetching the quote
122
+ */
123
+ purchaseData?: object;
119
124
  };
120
125
 
121
126
  /**
@@ -47,6 +47,7 @@ export type SendTransactionPayModalConfig =
47
47
  | {
48
48
  testMode?: boolean;
49
49
  };
50
+ purchaseData?: object;
50
51
  }
51
52
  | false;
52
53
 
@@ -8,7 +8,7 @@ import { connectionManager } from "../../index.js";
8
8
  * ```jsx
9
9
  * import { useActiveWalletChain } from "thirdweb/react";
10
10
  *
11
- * const chainId = useActiveWalletChain();
11
+ * const activeChain = useActiveWalletChain();
12
12
  * ```
13
13
  * @walletConnection
14
14
  */
@@ -92,6 +92,7 @@ export function useSendTransaction(config: SendTransactionConfig = {}) {
92
92
  payOptions={{
93
93
  buyWithCrypto: payModal?.buyWithCrypto,
94
94
  buyWithFiat: payModal?.buyWithFiat,
95
+ purchaseData: payModal?.purchaseData,
95
96
  }}
96
97
  />,
97
98
  );
@@ -8,7 +8,7 @@ import { connectionManager } from "../../index.js";
8
8
  * ```jsx
9
9
  * import { useActiveWalletChain } from "thirdweb/react";
10
10
  *
11
- * const chainId = useActiveWalletChain();
11
+ * const activeChain = useActiveWalletChain();
12
12
  * ```
13
13
  * @walletConnection
14
14
  */