thirdweb 5.50.1 → 5.51.0-nightly-f9c351c22d9c869770dad13332f9c23d8cb84ed7-20240905000555

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 (68) hide show
  1. package/dist/cjs/exports/extensions/erc721.js +25 -1
  2. package/dist/cjs/exports/extensions/erc721.js.map +1 -1
  3. package/dist/cjs/extensions/erc721/__generated__/IDrop/read/claimCondition.js +76 -0
  4. package/dist/cjs/extensions/erc721/__generated__/IDrop/read/claimCondition.js.map +1 -0
  5. package/dist/cjs/extensions/erc721/drops/read/getActiveClaimCondition.js +28 -6
  6. package/dist/cjs/extensions/erc721/drops/read/getActiveClaimCondition.js.map +1 -1
  7. package/dist/cjs/extensions/erc721/drops/read/getClaimConditions.js +73 -0
  8. package/dist/cjs/extensions/erc721/drops/read/getClaimConditions.js.map +1 -0
  9. package/dist/cjs/extensions/erc721/drops/write/claimTo.js +19 -0
  10. package/dist/cjs/extensions/erc721/drops/write/claimTo.js.map +1 -1
  11. package/dist/cjs/extensions/erc721/drops/write/resetClaimEligibility.js +56 -0
  12. package/dist/cjs/extensions/erc721/drops/write/resetClaimEligibility.js.map +1 -0
  13. package/dist/cjs/extensions/erc721/drops/write/setClaimConditions.js +24 -0
  14. package/dist/cjs/extensions/erc721/drops/write/setClaimConditions.js.map +1 -1
  15. package/dist/cjs/extensions/erc721/write/lazyMint.js +20 -2
  16. package/dist/cjs/extensions/erc721/write/lazyMint.js.map +1 -1
  17. package/dist/cjs/utils/extensions/drops/get-claim-params.js +3 -3
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/cjs/version.js.map +1 -1
  20. package/dist/esm/exports/extensions/erc721.js +17 -6
  21. package/dist/esm/exports/extensions/erc721.js.map +1 -1
  22. package/dist/esm/extensions/erc721/__generated__/IDrop/read/claimCondition.js +70 -0
  23. package/dist/esm/extensions/erc721/__generated__/IDrop/read/claimCondition.js.map +1 -0
  24. package/dist/esm/extensions/erc721/drops/read/getActiveClaimCondition.js +27 -6
  25. package/dist/esm/extensions/erc721/drops/read/getActiveClaimCondition.js.map +1 -1
  26. package/dist/esm/extensions/erc721/drops/read/getClaimConditions.js +69 -0
  27. package/dist/esm/extensions/erc721/drops/read/getClaimConditions.js.map +1 -0
  28. package/dist/esm/extensions/erc721/drops/write/claimTo.js +19 -1
  29. package/dist/esm/extensions/erc721/drops/write/claimTo.js.map +1 -1
  30. package/dist/esm/extensions/erc721/drops/write/resetClaimEligibility.js +52 -0
  31. package/dist/esm/extensions/erc721/drops/write/resetClaimEligibility.js.map +1 -0
  32. package/dist/esm/extensions/erc721/drops/write/setClaimConditions.js +24 -1
  33. package/dist/esm/extensions/erc721/drops/write/setClaimConditions.js.map +1 -1
  34. package/dist/esm/extensions/erc721/write/lazyMint.js +20 -3
  35. package/dist/esm/extensions/erc721/write/lazyMint.js.map +1 -1
  36. package/dist/esm/utils/extensions/drops/get-claim-params.js +4 -4
  37. package/dist/esm/version.js +1 -1
  38. package/dist/esm/version.js.map +1 -1
  39. package/dist/types/exports/extensions/erc721.d.ts +9 -6
  40. package/dist/types/exports/extensions/erc721.d.ts.map +1 -1
  41. package/dist/types/extensions/erc721/__generated__/IDrop/read/claimCondition.d.ts +45 -0
  42. package/dist/types/extensions/erc721/__generated__/IDrop/read/claimCondition.d.ts.map +1 -0
  43. package/dist/types/extensions/erc721/drops/read/getActiveClaimCondition.d.ts +13 -0
  44. package/dist/types/extensions/erc721/drops/read/getActiveClaimCondition.d.ts.map +1 -1
  45. package/dist/types/extensions/erc721/drops/read/getClaimConditions.d.ts +29 -0
  46. package/dist/types/extensions/erc721/drops/read/getClaimConditions.d.ts.map +1 -0
  47. package/dist/types/extensions/erc721/drops/write/claimTo.d.ts +13 -0
  48. package/dist/types/extensions/erc721/drops/write/claimTo.d.ts.map +1 -1
  49. package/dist/types/extensions/erc721/drops/write/resetClaimEligibility.d.ts +33 -0
  50. package/dist/types/extensions/erc721/drops/write/resetClaimEligibility.d.ts.map +1 -0
  51. package/dist/types/extensions/erc721/drops/write/setClaimConditions.d.ts +13 -0
  52. package/dist/types/extensions/erc721/drops/write/setClaimConditions.d.ts.map +1 -1
  53. package/dist/types/extensions/erc721/write/lazyMint.d.ts +13 -0
  54. package/dist/types/extensions/erc721/write/lazyMint.d.ts.map +1 -1
  55. package/dist/types/version.d.ts +1 -1
  56. package/dist/types/version.d.ts.map +1 -1
  57. package/package.json +1 -1
  58. package/src/exports/extensions/erc721.ts +36 -3
  59. package/src/extensions/erc721/__generated__/IDrop/read/claimCondition.ts +76 -0
  60. package/src/extensions/erc721/drop721.test.ts +102 -2
  61. package/src/extensions/erc721/drops/read/getActiveClaimCondition.ts +32 -6
  62. package/src/extensions/erc721/drops/read/getClaimConditions.ts +93 -0
  63. package/src/extensions/erc721/drops/write/claimTo.ts +25 -1
  64. package/src/extensions/erc721/drops/write/resetClaimEligibility.ts +70 -0
  65. package/src/extensions/erc721/drops/write/setClaimConditions.ts +30 -1
  66. package/src/extensions/erc721/write/lazyMint.ts +26 -3
  67. package/src/utils/extensions/drops/get-claim-params.ts +4 -4
  68. package/src/version.ts +1 -1
@@ -0,0 +1,33 @@
1
+ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
2
+ /**
3
+ * Reset the claim eligibility for all users.
4
+ * @param options
5
+ * @returns the prepared transaction
6
+ * @extension ERC721
7
+ * @example
8
+ * ```ts
9
+ * import { resetClaimEligibility } from "thirdweb/extensions/erc721";
10
+ * import { sendTransaction } from "thirdweb";
11
+ *
12
+ * const transaction = resetClaimEligibility({
13
+ * contract,
14
+ * });
15
+ *
16
+ * await sendTransaction({ transaction, account });
17
+ * ```
18
+ */
19
+ export declare function resetClaimEligibility(options: BaseTransactionOptions): import("../../../../transaction/prepare-transaction.js").PreparedTransaction<any, import("viem").AbiFunction, import("../../../../transaction/prepare-transaction.js").PrepareTransactionOptions>;
20
+ /**
21
+ * Checks if the `resetClaimEligibility` method is supported by the given contract.
22
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
23
+ * @returns A boolean indicating if the `resetClaimEligibility` method is supported.
24
+ * @extension ERC721
25
+ * @example
26
+ * ```ts
27
+ * import { isResetClaimEligibilitySupported } from "thirdweb/extensions/erc721";
28
+ *
29
+ * const supported = isResetClaimEligibilitySupported(["0x..."]);
30
+ * ```
31
+ */
32
+ export declare function isResetClaimEligibilitySupported(availableSelectors: string[]): boolean;
33
+ //# sourceMappingURL=resetClaimEligibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resetClaimEligibility.d.ts","sourceRoot":"","sources":["../../../../../../src/extensions/erc721/drops/write/resetClaimEligibility.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAW/E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,qMAqBpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gCAAgC,CAAC,kBAAkB,EAAE,MAAM,EAAE,WAK5E"}
@@ -34,4 +34,17 @@ export type SetClaimConditionsParams = {
34
34
  * ```
35
35
  */
36
36
  export declare function setClaimConditions(options: BaseTransactionOptions<SetClaimConditionsParams>): import("../../../../transaction/prepare-transaction.js").PreparedTransaction<any, import("abitype").AbiFunction, import("../../../../transaction/prepare-transaction.js").PrepareTransactionOptions>;
37
+ /**
38
+ * Checks if the `setClaimConditions` method is supported by the given contract.
39
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
40
+ * @returns A boolean indicating if the `setClaimConditions` method is supported.
41
+ * @extension ERC721
42
+ * @example
43
+ * ```ts
44
+ * import { isSetClaimConditionsSupported } from "thirdweb/extensions/erc721";
45
+ *
46
+ * const supported = isSetClaimConditionsSupported(["0x..."]);
47
+ * ```
48
+ */
49
+ export declare function isSetClaimConditionsSupported(availableSelectors: string[]): boolean;
37
50
  //# sourceMappingURL=setClaimConditions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setClaimConditions.d.ts","sourceRoot":"","sources":["../../../../../../src/extensions/erc721/drops/write/setClaimConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAGxF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,sBAAsB,CAAC,wBAAwB,CAAC,wMAe1D"}
1
+ {"version":3,"file":"setClaimConditions.d.ts","sourceRoot":"","sources":["../../../../../../src/extensions/erc721/drops/write/setClaimConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AASxF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,sBAAsB,CAAC,wBAAwB,CAAC,wMAe1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,kBAAkB,EAAE,MAAM,EAAE,WASzE"}
@@ -45,5 +45,18 @@ export type LazyMintParams = {
45
45
  * ```
46
46
  */
47
47
  export declare function lazyMint(options: BaseTransactionOptions<LazyMintParams>): import("../../../transaction/prepare-transaction.js").PreparedTransaction<any, import("abitype").AbiFunction, import("../../../transaction/prepare-transaction.js").PrepareTransactionOptions>;
48
+ /**
49
+ * Checks if the `lazyMint` method is supported by the given contract.
50
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
51
+ * @returns A boolean indicating if the `lazyMint` method is supported.
52
+ * @extension ERC721
53
+ * @example
54
+ * ```ts
55
+ * import { isLazyMintSupported } from "thirdweb/extensions/erc721";
56
+ *
57
+ * const supported = isLazyMintSupported(["0x..."]);
58
+ * ```
59
+ */
60
+ export declare function isLazyMintSupported(availableSelectors: string[]): boolean;
48
61
  export {};
49
62
  //# sourceMappingURL=lazyMint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lazyMint.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/erc721/write/lazyMint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAK5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAI7D;;;GAGG;AACH,KAAK,QAAQ,GAAG,QAAQ,CACtB;IACE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACvE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,kMAwBvE"}
1
+ {"version":3,"file":"lazyMint.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/erc721/write/lazyMint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAK5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAO7D;;;GAGG;AACH,KAAK,QAAQ,GAAG,QAAQ,CACtB;IACE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACvE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,kMAwBvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,kBAAkB,EAAE,MAAM,EAAE,WAM/D"}
@@ -1,2 +1,2 @@
1
- export declare const version = "5.50.1";
1
+ export declare const version = "5.51.0-nightly-f9c351c22d9c869770dad13332f9c23d8cb84ed7-20240905000555";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,2EAA2E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thirdweb",
3
- "version": "5.50.1",
3
+ "version": "5.51.0-nightly-f9c351c22d9c869770dad13332f9c23d8cb84ed7-20240905000555",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/thirdweb-dev/js.git#main"
@@ -82,21 +82,54 @@ export {
82
82
  /**
83
83
  * DROPS extension for ERC721
84
84
  */
85
- export { getClaimConditionById } from "../../extensions/erc721/__generated__/IDrop/read/getClaimConditionById.js";
86
- export { claimCondition } from "../../extensions/erc721/__generated__/DropSinglePhase/read/claimCondition.js";
87
- export { getActiveClaimCondition } from "../../extensions/erc721/drops/read/getActiveClaimCondition.js";
85
+ // READ
86
+ // multi-phase --
87
+ export {
88
+ getClaimConditionById,
89
+ isGetClaimConditionByIdSupported,
90
+ } from "../../extensions/erc721/__generated__/IDrop/read/getClaimConditionById.js";
91
+ export {
92
+ getActiveClaimConditionId,
93
+ isGetActiveClaimConditionIdSupported,
94
+ } from "../../extensions/erc721/__generated__/IDrop/read/getActiveClaimConditionId.js";
95
+ export {
96
+ getClaimConditions,
97
+ isGetClaimConditionsSupported,
98
+ } from "../../extensions/erc721/drops/read/getClaimConditions.js";
99
+ // --
100
+ // single phase --
101
+ export {
102
+ claimCondition,
103
+ isClaimConditionSupported,
104
+ } from "../../extensions/erc721/__generated__/DropSinglePhase/read/claimCondition.js";
105
+ // --
106
+ // multi and single phase --
107
+ export {
108
+ getActiveClaimCondition,
109
+ isGetActiveClaimConditionSupported,
110
+ } from "../../extensions/erc721/drops/read/getActiveClaimCondition.js";
111
+ // --
112
+
113
+ // WRITE
88
114
  export {
89
115
  claimTo,
90
116
  type ClaimToParams,
117
+ isClaimToSupported,
91
118
  } from "../../extensions/erc721/drops/write/claimTo.js";
92
119
  export {
93
120
  lazyMint,
94
121
  type LazyMintParams,
122
+ isLazyMintSupported,
95
123
  } from "../../extensions/erc721/write/lazyMint.js";
96
124
  export {
97
125
  setClaimConditions,
98
126
  type SetClaimConditionsParams,
127
+ isSetClaimConditionsSupported,
99
128
  } from "../../extensions/erc721/drops/write/setClaimConditions.js";
129
+ export {
130
+ resetClaimEligibility,
131
+ isResetClaimEligibilitySupported,
132
+ } from "../../extensions/erc721/drops/write/resetClaimEligibility.js";
100
133
 
101
134
  /**
102
135
  * SIGNATURE extension for ERC721
@@ -0,0 +1,76 @@
1
+ import { readContract } from "../../../../../transaction/read-contract.js";
2
+ import type { BaseTransactionOptions } from "../../../../../transaction/types.js";
3
+
4
+ import { decodeAbiParameters } from "viem";
5
+ import type { Hex } from "../../../../../utils/encoding/hex.js";
6
+ import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
7
+
8
+ export const FN_SELECTOR = "0xd637ed59" as const;
9
+ const FN_INPUTS = [] as const;
10
+ const FN_OUTPUTS = [
11
+ {
12
+ type: "uint256",
13
+ name: "currentStartId",
14
+ },
15
+ {
16
+ type: "uint256",
17
+ name: "count",
18
+ },
19
+ ] as const;
20
+
21
+ /**
22
+ * Checks if the `claimCondition` method is supported by the given contract.
23
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
24
+ * @returns A boolean indicating if the `claimCondition` method is supported.
25
+ * @extension ERC721
26
+ * @example
27
+ * ```ts
28
+ * import { isClaimConditionSupported } from "thirdweb/extensions/erc721";
29
+ *
30
+ * const supported = isClaimConditionSupported(["0x..."]);
31
+ * ```
32
+ */
33
+ export function isClaimConditionSupported(availableSelectors: string[]) {
34
+ return detectMethod({
35
+ availableSelectors,
36
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Decodes the result of the claimCondition function call.
42
+ * @param result - The hexadecimal result to decode.
43
+ * @returns The decoded result as per the FN_OUTPUTS definition.
44
+ * @extension ERC721
45
+ * @example
46
+ * ```ts
47
+ * import { decodeClaimConditionResult } from "thirdweb/extensions/erc721";
48
+ * const result = decodeClaimConditionResult("...");
49
+ * ```
50
+ */
51
+ export function decodeClaimConditionResult(result: Hex) {
52
+ return decodeAbiParameters(FN_OUTPUTS, result);
53
+ }
54
+
55
+ /**
56
+ * Calls the "claimCondition" function on the contract.
57
+ * @param options - The options for the claimCondition function.
58
+ * @returns The parsed result of the function call.
59
+ * @extension ERC721
60
+ * @example
61
+ * ```ts
62
+ * import { claimCondition } from "thirdweb/extensions/erc721";
63
+ *
64
+ * const result = await claimCondition({
65
+ * contract,
66
+ * });
67
+ *
68
+ * ```
69
+ */
70
+ export async function claimCondition(options: BaseTransactionOptions) {
71
+ return readContract({
72
+ contract: options.contract,
73
+ method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
74
+ params: [],
75
+ });
76
+ }
@@ -6,6 +6,7 @@ import {
6
6
  TEST_ACCOUNT_A,
7
7
  TEST_ACCOUNT_B,
8
8
  TEST_ACCOUNT_C,
9
+ TEST_ACCOUNT_D,
9
10
  } from "../../../test/src/test-wallets.js";
10
11
  import { type ThirdwebContract, getContract } from "../../contract/contract.js";
11
12
  import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
@@ -16,7 +17,9 @@ import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
16
17
  import { deployERC721Contract } from "../prebuilts/deploy-erc721.js";
17
18
  import { balanceOf } from "./__generated__/IERC721A/read/balanceOf.js";
18
19
  import { nextTokenIdToMint } from "./__generated__/IERC721Enumerable/read/nextTokenIdToMint.js";
20
+ import { getClaimConditions } from "./drops/read/getClaimConditions.js";
19
21
  import { claimTo } from "./drops/write/claimTo.js";
22
+ import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js";
20
23
  import { setClaimConditions } from "./drops/write/setClaimConditions.js";
21
24
  import { getNFT } from "./read/getNFT.js";
22
25
  import { lazyMint } from "./write/lazyMint.js";
@@ -83,6 +86,12 @@ describe.runIf(process.env.TW_SECRET_KEY)(
83
86
  { name: "Test NFT 2" },
84
87
  { name: "Test NFT 3" },
85
88
  { name: "Test NFT 4" },
89
+ { name: "Test NFT 5" },
90
+ { name: "Test NFT 6" },
91
+ { name: "Test NFT 7" },
92
+ { name: "Test NFT 8" },
93
+ { name: "Test NFT 9" },
94
+ { name: "Test NFT 10" },
86
95
  ],
87
96
  });
88
97
  await sendAndConfirmTransaction({
@@ -90,7 +99,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
90
99
  account: TEST_ACCOUNT_A,
91
100
  });
92
101
 
93
- await expect(nextTokenIdToMint({ contract })).resolves.toBe(4n);
102
+ await expect(nextTokenIdToMint({ contract })).resolves.toBe(10n);
94
103
  await expect(
95
104
  getNFT({ contract, tokenId: 0n }),
96
105
  ).resolves.toMatchInlineSnapshot(`
@@ -100,7 +109,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
100
109
  "name": "Test NFT",
101
110
  },
102
111
  "owner": null,
103
- "tokenURI": "ipfs://QmUfspS2uU9roYLJveebbY5geYaNR4KkZAsMkb5pPRtc7a/0",
112
+ "tokenURI": "ipfs://QmY1Rr4C7cYVPAaXykMMxg3AVbatDZ6Rd7u3gzt79CiDSB/0",
104
113
  "type": "ERC721",
105
114
  }
106
115
  `);
@@ -332,5 +341,96 @@ describe.runIf(process.env.TW_SECRET_KEY)(
332
341
  balanceOf({ contract, owner: TEST_ACCOUNT_A.address }),
333
342
  ).resolves.toBe(3n);
334
343
  });
344
+
345
+ it("should be able to retrieve multiple phases", async () => {
346
+ await sendAndConfirmTransaction({
347
+ transaction: setClaimConditions({
348
+ contract,
349
+ phases: [
350
+ {
351
+ maxClaimablePerWallet: 1n,
352
+ startTime: new Date(0),
353
+ },
354
+ {
355
+ maxClaimablePerWallet: 2n,
356
+ startTime: new Date(),
357
+ },
358
+ ],
359
+ }),
360
+ account: TEST_ACCOUNT_A,
361
+ });
362
+
363
+ const phases = await getClaimConditions({ contract });
364
+ expect(phases).toHaveLength(2);
365
+ expect(phases[0]?.quantityLimitPerWallet).toBe(1n);
366
+ expect(phases[1]?.quantityLimitPerWallet).toBe(2n);
367
+ });
368
+
369
+ it("should be able to reset claim eligibility", async () => {
370
+ // set claim conditions to only allow one claim
371
+ await sendAndConfirmTransaction({
372
+ transaction: setClaimConditions({
373
+ contract,
374
+ phases: [
375
+ {
376
+ maxClaimablePerWallet: 1n,
377
+ },
378
+ ],
379
+ }),
380
+ account: TEST_ACCOUNT_A,
381
+ });
382
+ // claim one token
383
+ await sendAndConfirmTransaction({
384
+ transaction: claimTo({
385
+ contract,
386
+ // fresh account to avoid any previous claims
387
+ to: TEST_ACCOUNT_D.address,
388
+ quantity: 1n,
389
+ }),
390
+ // fresh account to avoid any previous claims
391
+ account: TEST_ACCOUNT_D,
392
+ });
393
+ // check that the account has claimed one token
394
+ await expect(
395
+ balanceOf({ contract, owner: TEST_ACCOUNT_D.address }),
396
+ ).resolves.toBe(1n);
397
+ // attempt to claim another token (this should fail)
398
+ await expect(
399
+ sendAndConfirmTransaction({
400
+ transaction: claimTo({
401
+ contract,
402
+ to: TEST_ACCOUNT_D.address,
403
+ quantity: 1n,
404
+ }),
405
+ account: TEST_ACCOUNT_D,
406
+ }),
407
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
408
+ [TransactionError: Error - !Qty
409
+
410
+ contract: 0x6AA2E0148a57EcDdb025C856c4e68682CFfcac78
411
+ chainId: 31337]
412
+ `);
413
+
414
+ // reset claim eligibility
415
+ await sendAndConfirmTransaction({
416
+ transaction: resetClaimEligibility({
417
+ contract,
418
+ }),
419
+ account: TEST_ACCOUNT_A,
420
+ });
421
+ // attempt to claim another token (this should succeed)
422
+ await sendAndConfirmTransaction({
423
+ transaction: claimTo({
424
+ contract,
425
+ to: TEST_ACCOUNT_D.address,
426
+ quantity: 1n,
427
+ }),
428
+ account: TEST_ACCOUNT_D,
429
+ });
430
+ // check that the account has claimed two tokens
431
+ await expect(
432
+ balanceOf({ contract, owner: TEST_ACCOUNT_D.address }),
433
+ ).resolves.toBe(2n);
434
+ });
335
435
  },
336
436
  );
@@ -1,8 +1,8 @@
1
1
  import type { BaseTransactionOptions } from "../../../../transaction/types.js";
2
2
  import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
3
- import { claimCondition } from "../../__generated__/DropSinglePhase/read/claimCondition.js";
4
- import { getActiveClaimConditionId } from "../../__generated__/IDrop/read/getActiveClaimConditionId.js";
5
- import { getClaimConditionById } from "../../__generated__/IDrop/read/getClaimConditionById.js";
3
+ import * as SinglePhase from "../../__generated__/DropSinglePhase/read/claimCondition.js";
4
+ import * as GetActiveId from "../../__generated__/IDrop/read/getActiveClaimConditionId.js";
5
+ import * as ById from "../../__generated__/IDrop/read/getClaimConditionById.js";
6
6
 
7
7
  /**
8
8
  * Retrieves the active claim condition.
@@ -20,8 +20,8 @@ export async function getActiveClaimCondition(
20
20
  options: BaseTransactionOptions,
21
21
  ): Promise<ClaimCondition> {
22
22
  const getActiveClaimConditionMultiPhase = async () => {
23
- const conditionId = await getActiveClaimConditionId(options);
24
- return getClaimConditionById({ ...options, conditionId });
23
+ const conditionId = await GetActiveId.getActiveClaimConditionId(options);
24
+ return ById.getClaimConditionById({ ...options, conditionId });
25
25
  };
26
26
  const getActiveClaimConditionSinglePhase = async () => {
27
27
  const [
@@ -33,7 +33,7 @@ export async function getActiveClaimCondition(
33
33
  pricePerToken,
34
34
  currency,
35
35
  metadata,
36
- ] = await claimCondition(options);
36
+ ] = await SinglePhase.claimCondition(options);
37
37
  return {
38
38
  startTimestamp,
39
39
  maxClaimableSupply,
@@ -58,3 +58,29 @@ export async function getActiveClaimCondition(
58
58
  }
59
59
  throw new Error("Claim condition not found");
60
60
  }
61
+
62
+ /**
63
+ * Checks if the `getActiveClaimCondition` method is supported by the given contract.
64
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
65
+ * @returns A boolean indicating if the `getActiveClaimCondition` method is supported.
66
+ * @extension ERC721
67
+ * @example
68
+ * ```ts
69
+ * import { isGetActiveClaimConditionSupported } from "thirdweb/extensions/erc721";
70
+ *
71
+ * const supported = isGetActiveClaimConditionSupported(["0x..."]);
72
+ * ```
73
+ */
74
+ export function isGetActiveClaimConditionSupported(
75
+ availableSelectors: string[],
76
+ ) {
77
+ // if single phase is supported, return true
78
+ if (SinglePhase.isClaimConditionSupported(availableSelectors)) {
79
+ return true;
80
+ }
81
+ // otherwise check that both multi phase functions are supported
82
+ return (
83
+ GetActiveId.isGetActiveClaimConditionIdSupported(availableSelectors) &&
84
+ ById.isGetClaimConditionByIdSupported(availableSelectors)
85
+ );
86
+ }
@@ -0,0 +1,93 @@
1
+ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
2
+ import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
3
+ import * as SinglePhase from "../../__generated__/DropSinglePhase/read/claimCondition.js";
4
+ import * as MultiPhase from "../../__generated__/IDrop/read/claimCondition.js";
5
+ import * as ById from "../../__generated__/IDrop/read/getClaimConditionById.js";
6
+
7
+ /**
8
+ * Retrieves all claim conditions.
9
+ * @param options - The transaction options.
10
+ * @returns A promise that resolves to all claim conditions.
11
+ * @throws An error if the claim conditions are unsupported by the contract.
12
+ * @extension ERC721
13
+ * @example
14
+ * ```ts
15
+ * import { getClaimConditions } from "thirdweb/extensions/erc721";
16
+ * const conditions = await getClaimConditions({ contract });
17
+ * ```
18
+ */
19
+ export async function getClaimConditions(
20
+ options: BaseTransactionOptions,
21
+ ): Promise<ClaimCondition[]> {
22
+ const [multi, single] = await Promise.allSettled([
23
+ (async () => {
24
+ const [startId, count] = await MultiPhase.claimCondition(options);
25
+
26
+ const conditionPromises: Array<
27
+ ReturnType<typeof ById.getClaimConditionById>
28
+ > = [];
29
+ for (let i = startId; i < count; i++) {
30
+ conditionPromises.push(
31
+ ById.getClaimConditionById({
32
+ ...options,
33
+ conditionId: i,
34
+ }),
35
+ );
36
+ }
37
+ return Promise.all(conditionPromises);
38
+ })(),
39
+ SinglePhase.claimCondition(options).then(
40
+ ([
41
+ startTimestamp,
42
+ maxClaimableSupply,
43
+ supplyClaimed,
44
+ quantityLimitPerWallet,
45
+ merkleRoot,
46
+ pricePerToken,
47
+ currency,
48
+ metadata,
49
+ ]) => ({
50
+ startTimestamp,
51
+ maxClaimableSupply,
52
+ supplyClaimed,
53
+ quantityLimitPerWallet,
54
+ merkleRoot,
55
+ pricePerToken,
56
+ currency,
57
+ metadata,
58
+ }),
59
+ ),
60
+ ]);
61
+ if (multi.status === "fulfilled") {
62
+ return multi.value;
63
+ }
64
+ if (single.status === "fulfilled") {
65
+ return [single.value];
66
+ }
67
+
68
+ throw new Error("Claim condition not found");
69
+ }
70
+
71
+ /**
72
+ * Checks if the `getClaimConditions` method is supported by the given contract.
73
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
74
+ * @returns A boolean indicating if the `getClaimConditions` method is supported.
75
+ * @extension ERC721
76
+ * @example
77
+ * ```ts
78
+ * import { isGetClaimConditionsSupported } from "thirdweb/extensions/erc721";
79
+ *
80
+ * const supported = isGetClaimConditionsSupported(["0x..."]);
81
+ * ```
82
+ */
83
+ export function isGetClaimConditionsSupported(availableSelectors: string[]) {
84
+ // if single phase is supported, return true
85
+ if (SinglePhase.isClaimConditionSupported(availableSelectors)) {
86
+ return true;
87
+ }
88
+ // if multi phase is supported, return true
89
+ return (
90
+ MultiPhase.isClaimConditionSupported(availableSelectors) &&
91
+ ById.isGetClaimConditionByIdSupported(availableSelectors)
92
+ );
93
+ }
@@ -1,7 +1,11 @@
1
1
  import type { Address } from "abitype";
2
2
  import type { BaseTransactionOptions } from "../../../../transaction/types.js";
3
3
  import { getClaimParams } from "../../../../utils/extensions/drops/get-claim-params.js";
4
- import { claim } from "../../__generated__/IDrop/write/claim.js";
4
+ import {
5
+ claim,
6
+ isClaimSupported,
7
+ } from "../../__generated__/IDrop/write/claim.js";
8
+ import { isGetActiveClaimConditionSupported } from "../read/getActiveClaimCondition.js";
5
9
 
6
10
  /**
7
11
  * Represents the parameters for claiming an ERC721 token.
@@ -46,3 +50,23 @@ export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
46
50
  }),
47
51
  });
48
52
  }
53
+
54
+ /**
55
+ * Checks if the `claimTo` method is supported by the given contract.
56
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
57
+ * @returns A boolean indicating if the `claimTo` method is supported.
58
+ * @extension ERC721
59
+ * @example
60
+ * ```ts
61
+ * import { isClaimToSupported } from "thirdweb/extensions/erc721";
62
+ *
63
+ * const supported = isClaimToSupported(["0x..."]);
64
+ * ```
65
+ */
66
+ export function isClaimToSupported(availableSelectors: string[]) {
67
+ return (
68
+ isClaimSupported(availableSelectors) &&
69
+ // required to check if the contract supports the getActiveClaimCondition method
70
+ isGetActiveClaimConditionSupported(availableSelectors)
71
+ );
72
+ }
@@ -0,0 +1,70 @@
1
+ import type { Hex } from "viem";
2
+ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
3
+ import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
4
+ import {
5
+ isSetClaimConditionsSupported,
6
+ setClaimConditions,
7
+ } from "../../__generated__/IDrop/write/setClaimConditions.js";
8
+ import {
9
+ getClaimConditions,
10
+ isGetClaimConditionsSupported,
11
+ } from "../read/getClaimConditions.js";
12
+
13
+ /**
14
+ * Reset the claim eligibility for all users.
15
+ * @param options
16
+ * @returns the prepared transaction
17
+ * @extension ERC721
18
+ * @example
19
+ * ```ts
20
+ * import { resetClaimEligibility } from "thirdweb/extensions/erc721";
21
+ * import { sendTransaction } from "thirdweb";
22
+ *
23
+ * const transaction = resetClaimEligibility({
24
+ * contract,
25
+ * });
26
+ *
27
+ * await sendTransaction({ transaction, account });
28
+ * ```
29
+ */
30
+ export function resetClaimEligibility(options: BaseTransactionOptions) {
31
+ // download existing conditions
32
+ return setClaimConditions({
33
+ contract: options.contract,
34
+ asyncParams: async () => {
35
+ // get existing conditions
36
+ const existingConditions = await getClaimConditions(options);
37
+
38
+ // then simply return the exact same ones, but with the resetClaimEligibility flag set to true
39
+ return {
40
+ // type is necessary because of viem hex shenanigans (strict vs non-strict `0x` prefix string)
41
+ phases: existingConditions as Array<
42
+ ClaimCondition & {
43
+ currency: Hex;
44
+ merkleRoot: Hex;
45
+ }
46
+ >,
47
+ resetClaimEligibility: true,
48
+ };
49
+ },
50
+ });
51
+ }
52
+
53
+ /**
54
+ * Checks if the `resetClaimEligibility` method is supported by the given contract.
55
+ * @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
56
+ * @returns A boolean indicating if the `resetClaimEligibility` method is supported.
57
+ * @extension ERC721
58
+ * @example
59
+ * ```ts
60
+ * import { isResetClaimEligibilitySupported } from "thirdweb/extensions/erc721";
61
+ *
62
+ * const supported = isResetClaimEligibilitySupported(["0x..."]);
63
+ * ```
64
+ */
65
+ export function isResetClaimEligibilitySupported(availableSelectors: string[]) {
66
+ return (
67
+ isGetClaimConditionsSupported(availableSelectors) &&
68
+ isSetClaimConditionsSupported(availableSelectors)
69
+ );
70
+ }