Skip to main content

ERC1155Drop

import "@thirdweb-dev/contracts/extension/Drop1155.sol";

The Drop1155 smart contract is an extension meant for distributing ERC1155 tokens. It allows setting up multiple claim phases unlike ERC1155DropSinglePhase. This series of claim phases is ordered by their respective startTimestamp.

This extension implements the 'Drop' distribution mechanism: set multiple claim phases with restrictions such as a price to charge, an allowlist etc. for the public / allowlisted mint of your tokens.

It is recommended to use this extension alongside the LazyMint extension.

Usage

The Drop1155 extension is an abstract contract, and expects you to implement the following functions by yourself:

NameTypeDescription
_afterClaiminternal virtualRuns after every claim function call.
_beforeClaiminternal virtualRuns before every claim function call.
_collectPriceOnClaiminternal virtualCollects and distributes the primary sale value of NFTs being claimed.
_transferTokensOnClaiminternal virtualTransfers the NFTs being claimed.
_canSetClaimConditionsinternal view virtualRuns on every attempt to set the claim condition on the contract. Returns whether the claim condition can be set in the given execution context.

This is an example smart contract demonstrating how to inherit from this extension and override the functions to add (optional) custom functionality.

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/extension/Drop1155.sol";
import "@thirdweb-dev/contracts/base/ERC1155Base.sol";
import "@thirdweb-dev/contracts/lib/CurrencyTransferLib.sol";

/// This is an EXAMPLE of usage of `Drop1155` for distributing ERC1155 tokens.

contract MyContract is ERC1155Base, Drop1155 {
/*//////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/

constructor(
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC1155Base(_name, _symbol, _royaltyRecipient, _royaltyBps) {}

/*//////////////////////////////////////////////////////////////
Internal (overrideable) functions
//////////////////////////////////////////////////////////////*/

/// @dev Collects and distributes the primary sale value of NFTs being claimed.
function _collectPriceOnClaim(
uint256 _tokenId,
address _primarySaleRecipient,
uint256 _quantityToClaim,
address _currency,
uint256 _pricePerToken
) internal virtual override {
if (_pricePerToken == 0) {
return;
}

uint256 totalPrice = _quantityToClaim * _pricePerToken;

if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
if (msg.value != totalPrice) {
revert("Must send total price.");
}
}

address saleRecipient = _primarySaleRecipient;
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
}

/// @dev Transfers the tokens being claimed.
function _transferTokensOnClaim(address _to, uint256 _tokenId, uint256 _quantityBeingClaimed)
internal
virtual
override
{
_mint(_to, _tokenId, _quantityBeingClaimed, "");
}

/// @dev Checks whether platform fee info can be set in the given execution context.
function _canSetClaimConditions()
internal
view
virtual
override
returns (bool)
{
return msg.sender == owner();
}

/// @dev Runs before every `claim` function call.
function _beforeClaim(
uint256 _tokenId,
address _receiver,
uint256 _quantity,
address _currency,
uint256 _pricePerToken,
AllowlistProof calldata _allowlistProof,
bytes memory _data
) internal virtual {}

/// @dev Runs after every `claim` function call.
function _afterClaim(
uint256 _tokenId,
address _receiver,
uint256 _quantity,
address _currency,
uint256 _pricePerToken,
AllowlistProof calldata _allowlistProof,
bytes memory _data
) internal virtual {}
}

SDK Usage

This extension alone does not unlock anything in the SDK. By combining this extension with LazyMint and ERC1155 extensions you will have the ERC1155ClaimPhases extension detected on your contract which unlocks these features in the SDK:

Base Contracts Implementing This Extension

None of the base contracts implement this extension.

Full API reference

claim
function claim(
address receiver,
uint256 tokenId,
uint256 quantity,
address currency,
uint256 pricePerToken,
AllowlistProof calldata allowlistProof,
bytes memory data
) external payable;
  • Lets an account claim a given quantity of tokens.
  • Parameter receiver: The receiver of the tokens to claim.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter quantity: The quantity of tokens to claim.
  • Parameter currency: The currency in which to pay for the claim.
  • Parameter pricePerToken: The price per token to pay for the claim.
  • Parameter allowlistProof: The proof of the claimer's inclusion in the merkle root allowlist.
  • Parameter data: Arbitrary bytes data that can be leveraged in the implementation of this interface.
setClaimConditions
struct ClaimCondition {
uint256 startTimestamp;
uint256 maxClaimableSupply;
uint256 supplyClaimed;
uint256 quantityLimitPerWallet;
bytes32 merkleRoot;
uint256 pricePerToken;
address currency;
string metadata;
}

function setClaimConditions(uint256 tokenId, ClaimCondition[] calldata phases, bool resetClaimEligibility) external;
  • Lets an authorized wallet set the claim condition for the contract.
  • Parameter tokenId: The token ID for which to set claim conditions.
  • Parameter phases: The array where each phase contains a set of restrictions that will apply to the minting of tokens on the contract.
    • startTimestamp: The unix timestamp after which the claim condition applies. The same claim condition applies until the startTimestamp of the next claim condition.
    • maxClaimableSupply: The maximum total number of tokens that can be claimed under the claim condition.
    • supplyClaimed: At any given point, the number of tokens that have been claimed under the claim condition.
    • quantityLimitPerWallet: The maximum number of tokens that can be claimed by a wallet.
    • merkleRoot: The allowlist of addresses that can claim tokens under the claim condition.
    • pricePerToken: The price required to pay per token claimed.
    • currency: The currency in which the price must be paid.
    • metadata: Claim condition metadata.
  • Parameter resetClaimEligibility: Whether to carry over the restrictions active for wallets that claimed tokens in the incumbent claim condition (e.g. next valid claim timestamp for a given wallet).
  • The _canSetClaimConditions function is run on every call to this function. If the return value of _canSetClaimConditions is false, the setClaimConditions call will revert.
verifyClaim
struct AllowlistProof {
bytes32[] proof;
uint256 quantityLimitPerWallet;
uint256 pricePerToken;
address currency;
}

function verifyClaim(
uint256 conditionId,
address claimer,
uint256 tokenId,
uint256 quantity,
address currency,
uint256 pricePerToken,
AllowlistProof calldata allowlistProof
) public view returns (bool isOverride);
  • Checks a request to claim tokens against the active claim condition's criteria.
  • Parameter conditionId: Id of the active claim condition.
  • Parameter claimer: The wallet claiming tokens.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter quantity: The quantity of tokens to claim.
  • Parameter currency: The currency in which to pay the price for the claim.
  • Parameter pricePerToken: The price to pay per token claimed.
  • Parameter allowlistProof: Struct containing below elements:
    • proof: Proof of concerned wallet's inclusion in an allowlist.
    • quantityLimitPerWallet: The total quantity of tokens the allowlisted wallet is eligible to claim over time.
    • pricePerToken: The price per token the allowlisted wallet must pay to claim tokens.
    • currency: The currency in which the allowlisted wallet must pay the price for claiming tokens.
getActiveClaimConditionId
function getActiveClaimConditionId(uint256 tokenId) public view returns (uint256);
  • Returns the Id of currently active claim condition.
  • Parameter tokenId: The token ID for which to check active claim condition.
getClaimConditionById
function getClaimConditionById(uint256 tokenId, uint256 conditionId) external view returns (ClaimCondition memory);
  • Returns the claim condition for a given condition Id.
  • Parameter tokenId: The token ID for which check claim condition.
  • Parameter conditionId: Id of the claim condition being viewed.
getSupplyClaimedByWallet
function getSupplyClaimedByWallet(uint256 tokenId, uint256 conditionId, address claimer) public view returns (uint256);
  • Returns the number of tokens claimed by a wallet under the given condition.
  • Parameter tokenId: The token ID for which check claimed supply.
  • Parameter conditionId: Id of the claim condition under which to check the supply claimed.
  • Parameter claimer: The wallet claiming tokens.
_dropMsgSender
function _dropMsgSender() internal virtual returns (address);
  • Exposes the ability to override the msg sender.
_beforeClaim
function _beforeClaim(
uint256 tokenId,
address receiver,
uint256 quantity,
address currency,
uint256 pricePerToken,
AllowlistProof calldata allowlistProof,
bytes memory data
) internal virtual
  • Runs before every claim function call. Exposes the ability to add custom logic that runs before every claim of tokens.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter receiver: The receiver of the tokens to claim.
  • Parameter quantity: The quantity of tokens to claim.
  • Parameter currency: The currency in which to pay for the claim.
  • Parameter pricePerToken: The price per token to pay for the claim.
  • Parameter allowlistProof: The proof of the claimer's inclusion in the merkle root allowlist.
  • Parameter data: Arbitrary bytes data that can be leveraged in the implementation of this interface.
_afterClaim
function _afterClaim(
uint256 tokenId,
address receiver,
uint256 quantity,
address currency,
uint256 pricePerToken,
AllowlistProof calldata allowlistProof,
bytes memory data
) internal virtual
  • Runs after every claim function call. Exposes the ability to add custom logic that runs after every claim of tokens.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter receiver: The receiver of the tokens to claim.
  • Parameter quantity: The quantity of tokens to claim.
  • Parameter currency: The currency in which to pay for the claim.
  • Parameter pricePerToken: The price per token to pay for the claim.
  • Parameter allowlistProof: The proof of the claimer's inclusion in the merkle root allowlist.
  • Parameter data: Arbitrary bytes data that can be leveraged in the implementation of this interface.
_collectPriceOnClaim
function _collectPriceOnClaim(
uint256 tokenId,
address primarySaleRecipient,
uint256 quantityToClaim,
address currency,
uint256 pricePerToken
) internal virtual;
  • Collects and distributes the primary sale value of tokens being claimed.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter primarySaleRecipient: The recipient of the primary sale value generated from a claim.
  • Parameter quantityToClaim: The quantity of tokens being claimed.
  • Parameter currency: The currency used to pay for the claim.
  • Parameter pricePerToken: The price per token to pay for the claim.
_transferTokensOnClaim
function _transferTokensOnClaim(address to, uint256 tokenId, uint256 quantityBeingClaimed)
internal
virtual;
  • Transfers the tokens being claimed to the appropriate recipient.
  • Parameter to: The recipient of the tokens for a claim.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter quantityBeingClaimed: The quantity of tokens being claimed.
_canSetClaimConditions
function _canSetClaimConditions() internal view virtual returns (bool);
  • Runs on every setClaimConditions function call.
  • Returns whether the claim condition can be set in the given execution context.
  • For example, this function can check whether the wallet calling setClaimConditions is the contract owner, and enforce that only the owner should be able to successfully call setClaimConditions.