Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-ravens-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Expose `canClaim` extension function for erc20/721/1155 drops
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"function setMaxTotalSupply(uint256 _tokenId, uint256 _maxTotalSupply)",
"function setSaleRecipientForToken(uint256 _tokenId, address _saleRecipient)",
"function updateBatchBaseURI(uint256 _index, string calldata _uri)",
"function freezeBatchBaseURI(uint256 _index)"
"function freezeBatchBaseURI(uint256 _index)",
"function verifyClaim(uint256 _conditionId, address _claimer, uint256 _tokenId, uint256 _quantity, address _currency, uint256 _pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) _allowlistProof) view returns (bool isOverride)"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"function verifyClaim(uint256 _conditionId, address _claimer, uint256 _quantity, address _currency, uint256 _pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) _allowlistProof) view returns (bool isOverride)"
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"function updateBatchBaseURI(uint256 _index, string calldata _uri)",
"function freezeBatchBaseURI(uint256 _index)",
"function setMaxTotalSupply(uint256 _maxTotalSupply)"
"function setMaxTotalSupply(uint256 _maxTotalSupply)",
"function verifyClaim(uint256 _conditionId, address _claimer, uint256 _quantity, address _currency, uint256 _pricePerToken, (bytes32[] proof, uint256 quantityLimitPerWallet, uint256 pricePerToken, address currency) _allowlistProof) view returns (bool isOverride)"
]
5 changes: 5 additions & 0 deletions packages/thirdweb/src/exports/extensions/erc1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export {
type GetClaimConditionsParams,
isGetClaimConditionsSupported,
} from "../../extensions/erc1155/drops/read/getClaimConditions.js";
export {
canClaim,
type CanClaimParams,
type CanClaimResult,
} from "../../extensions/erc1155/drops/read/canClaim.js";

// WRITE
export {
Expand Down
5 changes: 5 additions & 0 deletions packages/thirdweb/src/exports/extensions/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export {
getActiveClaimCondition,
isGetActiveClaimConditionSupported,
} from "../../extensions/erc20/drops/read/getActiveClaimCondition.js";
export {
canClaim,
type CanClaimParams,
type CanClaimResult,
} from "../../extensions/erc20/drops/read/canClaim.js";

// WRITE
export {
Expand Down
5 changes: 5 additions & 0 deletions packages/thirdweb/src/exports/extensions/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export {
getActiveClaimCondition,
isGetActiveClaimConditionSupported,
} from "../../extensions/erc721/drops/read/getActiveClaimCondition.js";
export {
canClaim,
type CanClaimParams,
type CanClaimResult,
} from "../../extensions/erc721/drops/read/canClaim.js";

// WRITE
export {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions packages/thirdweb/src/extensions/erc1155/drop1155.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
import { canClaim } from "./drops/read/canClaim.js";
import { getActiveClaimCondition } from "./drops/read/getActiveClaimCondition.js";
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
import { claimTo } from "./drops/write/claimTo.js";
Expand Down Expand Up @@ -130,6 +131,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
}),
account: TEST_ACCOUNT_C,
});

expect(
await canClaim({
contract,
claimer: TEST_ACCOUNT_C.address,
quantity: 1n,
tokenId: 0n,
}),
).toMatchInlineSnapshot(`
{
"result": true,
}
`);

const claimTx = claimTo({
contract,
to: TEST_ACCOUNT_C.address,
Expand Down Expand Up @@ -205,6 +220,33 @@ describe.runIf(process.env.TW_SECRET_KEY)(
balanceOf({ contract, owner: TEST_ACCOUNT_B.address, tokenId }),
).resolves.toBe(0n);

expect(
await canClaim({
contract,
claimer: TEST_ACCOUNT_C.address,
quantity: 1n,
tokenId,
}),
).toMatchInlineSnapshot(`
{
"result": true,
}
`);

expect(
await canClaim({
contract,
claimer: TEST_ACCOUNT_B.address,
quantity: 1n,
tokenId,
}),
).toMatchInlineSnapshot(`
{
"reason": "DropClaimExceedLimit - 0,1",
"result": false,
}
`);

await sendAndConfirmTransaction({
account: TEST_ACCOUNT_C,
transaction: claimTo({
Expand Down
Loading
Loading