Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit e6c5213

Browse files
expose edition.claimConditions.setBatch() to set claim conditions on multiple tokenIds at once (#468)
expoer edition.claimConditions.setBatch() to set claim conditions on multiple tokenIds at once
1 parent 4b999a8 commit e6c5213

File tree

6 files changed

+137
-12
lines changed

6 files changed

+137
-12
lines changed

docs/sdk.droperc1155claimconditions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export declare class DropErc1155ClaimConditions
2626
| [getActive(tokenId)](./sdk.droperc1155claimconditions.getactive.md) | | Get the currently active claim condition |
2727
| [getAll(tokenId)](./sdk.droperc1155claimconditions.getall.md) | | Get all the claim conditions |
2828
| [getClaimIneligibilityReasons(tokenId, quantity, addressToCheck)](./sdk.droperc1155claimconditions.getclaimineligibilityreasons.md) | | For any claim conditions that a particular wallet is violating, this function returns human-readable information about the breaks in the condition that can be used to inform the user. |
29-
| [set(tokenId, claimConditionInputs, resetClaimEligibilityForAll)](./sdk.droperc1155claimconditions.set.md) | | Set public mint conditions on a NFT |
29+
| [set(tokenId, claimConditionInputs, resetClaimEligibilityForAll)](./sdk.droperc1155claimconditions.set.md) | | Set claim conditions on a single NFT |
30+
| [setBatch(tokenIds, claimConditionInputs, resetClaimEligibilityForAll)](./sdk.droperc1155claimconditions.setbatch.md) | | Set claim conditions on multiple NFTs at once |
3031
| [update(tokenId, index, claimConditionInput)](./sdk.droperc1155claimconditions.update.md) | | Update a single claim condition with new data. |
3132

docs/sdk.droperc1155claimconditions.set.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## DropErc1155ClaimConditions.set() method
66

7-
Set public mint conditions on a NFT
7+
Set claim conditions on a single NFT
88

99
<b>Signature:</b>
1010

@@ -26,7 +26,7 @@ Promise&lt;[TransactionResult](./sdk.transactionresult.md)<!-- -->&gt;
2626

2727
## Remarks
2828

29-
Sets the public mint conditions that need to be fulfilled by users to claim a particular NFT in this bundle.
29+
Sets the public mint conditions that need to be fulfilled by users to claim a particular NFT in this contract.
3030

3131
## Example
3232

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [DropErc1155ClaimConditions](./sdk.droperc1155claimconditions.md) &gt; [setBatch](./sdk.droperc1155claimconditions.setbatch.md)
4+
5+
## DropErc1155ClaimConditions.setBatch() method
6+
7+
Set claim conditions on multiple NFTs at once
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
setBatch(tokenIds: BigNumberish[], claimConditionInputs: ClaimConditionInput[], resetClaimEligibilityForAll?: boolean): Promise<{
13+
receipt: ethers.providers.TransactionReceipt;
14+
}>;
15+
```
16+
17+
## Parameters
18+
19+
| Parameter | Type | Description |
20+
| --- | --- | --- |
21+
| tokenIds | BigNumberish\[\] | the token ids to set the claim conditions on |
22+
| claimConditionInputs | [ClaimConditionInput](./sdk.claimconditioninput.md)<!-- -->\[\] | The claim conditions |
23+
| resetClaimEligibilityForAll | boolean | <i>(Optional)</i> Whether to reset the state of who already claimed NFTs previously |
24+
25+
<b>Returns:</b>
26+
27+
Promise&lt;{ receipt: ethers.providers.TransactionReceipt; }&gt;
28+
29+
## Remarks
30+
31+
Sets the claim conditions that need to be fulfilled by users to claim the given NFTs in this contract.
32+
33+
## Example
34+
35+
36+
```javascript
37+
const presaleStartTime = new Date();
38+
const publicSaleStartTime = new Date(Date.now() + 60 * 60 * 24 * 1000);
39+
const claimConditions = [
40+
{
41+
startTime: presaleStartTime, // start the presale now
42+
maxQuantity: 2, // limit how many mints for this presale
43+
price: 0.01, // presale price
44+
snapshot: ['0x...', '0x...'], // limit minting to only certain addresses
45+
},
46+
{
47+
startTime: publicSaleStartTime, // 24h after presale, start public sale
48+
price: 0.08, // public sale price
49+
}
50+
]);
51+
52+
const tokenIds = [0,1,2]; // the ids of the NFTs to set claim conditions on
53+
await dropContract.claimConditions.setBatch(tokenIds, claimConditions);
54+
```
55+

etc/sdk.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ export class DropErc1155ClaimConditions {
935935
getAll(tokenId: BigNumberish): Promise<ClaimCondition[]>;
936936
getClaimIneligibilityReasons(tokenId: BigNumberish, quantity: BigNumberish, addressToCheck?: string): Promise<ClaimEligibility[]>;
937937
set(tokenId: BigNumberish, claimConditionInputs: ClaimConditionInput[], resetClaimEligibilityForAll?: boolean): Promise<TransactionResult>;
938+
setBatch(tokenIds: BigNumberish[], claimConditionInputs: ClaimConditionInput[], resetClaimEligibilityForAll?: boolean): Promise<{
939+
receipt: ethers.providers.TransactionReceipt;
940+
}>;
938941
update(tokenId: BigNumberish, index: number, claimConditionInput: ClaimConditionInput): Promise<TransactionResult>;
939942
}
940943

src/core/classes/drop-erc1155-claim-conditions.ts

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ export class DropErc1155ClaimConditions {
267267
*****************************************/
268268

269269
/**
270-
* Set public mint conditions on a NFT
270+
* Set claim conditions on a single NFT
271271
*
272-
* @remarks Sets the public mint conditions that need to be fulfilled by users to claim a particular NFT in this bundle.
272+
* @remarks Sets the public mint conditions that need to be fulfilled by users to claim a particular NFT in this contract.
273273
*
274274
* @example
275275
* ```javascript
@@ -301,6 +301,48 @@ export class DropErc1155ClaimConditions {
301301
claimConditionInputs: ClaimConditionInput[],
302302
resetClaimEligibilityForAll = false,
303303
): Promise<TransactionResult> {
304+
return this.setBatch(
305+
[tokenId],
306+
claimConditionInputs,
307+
resetClaimEligibilityForAll,
308+
);
309+
}
310+
311+
/**
312+
* Set claim conditions on multiple NFTs at once
313+
*
314+
* @remarks Sets the claim conditions that need to be fulfilled by users to claim the given NFTs in this contract.
315+
*
316+
* @example
317+
* ```javascript
318+
* const presaleStartTime = new Date();
319+
* const publicSaleStartTime = new Date(Date.now() + 60 * 60 * 24 * 1000);
320+
* const claimConditions = [
321+
* {
322+
* startTime: presaleStartTime, // start the presale now
323+
* maxQuantity: 2, // limit how many mints for this presale
324+
* price: 0.01, // presale price
325+
* snapshot: ['0x...', '0x...'], // limit minting to only certain addresses
326+
* },
327+
* {
328+
* startTime: publicSaleStartTime, // 24h after presale, start public sale
329+
* price: 0.08, // public sale price
330+
* }
331+
* ]);
332+
*
333+
* const tokenIds = [0,1,2]; // the ids of the NFTs to set claim conditions on
334+
* await dropContract.claimConditions.setBatch(tokenIds, claimConditions);
335+
* ```
336+
*
337+
* @param tokenIds - the token ids to set the claim conditions on
338+
* @param claimConditionInputs - The claim conditions
339+
* @param resetClaimEligibilityForAll - Whether to reset the state of who already claimed NFTs previously
340+
*/
341+
public async setBatch(
342+
tokenIds: BigNumberish[],
343+
claimConditionInputs: ClaimConditionInput[],
344+
resetClaimEligibilityForAll = false,
345+
) {
304346
// process inputs
305347
const { snapshotInfos, sortedConditions } =
306348
await processClaimConditionInputs(
@@ -340,13 +382,14 @@ export class DropErc1155ClaimConditions {
340382
);
341383
}
342384

343-
encoded.push(
344-
this.contractWrapper.readContract.interface.encodeFunctionData(
345-
"setClaimConditions",
346-
[tokenId, sortedConditions, resetClaimEligibilityForAll],
347-
),
348-
);
349-
385+
tokenIds.forEach((tokenId) => {
386+
encoded.push(
387+
this.contractWrapper.readContract.interface.encodeFunctionData(
388+
"setClaimConditions",
389+
[tokenId, sortedConditions, resetClaimEligibilityForAll],
390+
),
391+
);
392+
});
350393
return {
351394
receipt: await this.contractWrapper.multiCall(encoded),
352395
};

test/edition-drop.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,29 @@ describe("Edition Drop Contract", async () => {
376376
await bdContract.claim("0", 1);
377377
});
378378

379+
it("should set multiple claim conditions at once", async () => {
380+
await bdContract.createBatch([
381+
{
382+
name: "test1",
383+
description: "test1",
384+
},
385+
{
386+
name: "test2",
387+
description: "test2",
388+
},
389+
]);
390+
await bdContract.claimConditions.setBatch(
391+
[0, 1],
392+
[
393+
{
394+
price: 1,
395+
},
396+
],
397+
);
398+
await bdContract.claim("0", 1);
399+
await bdContract.claim("1", 1);
400+
});
401+
379402
describe("eligibility", () => {
380403
beforeEach(async () => {
381404
await bdContract.createBatch([

0 commit comments

Comments
 (0)