Skip to main content

DropSinglePhase (ERC1155)

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

The DropSinglePhase1155 smart contract is an extension meant for distributing ERC1155 tokens.

This extension implements the 'Drop' distribution mechanism: set 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 DropSinglePhase1155 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/base/ERC1155Base.sol";
import "@thirdweb-dev/contracts/extension/DropSinglePhase1155.sol";
import "@thirdweb-dev/contracts/lib/CurrencyTransferLib.sol";

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

contract ERC1155Drop is
ERC1155Base,
DropSinglePhase1155
{

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

/// @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 override {
// Your custom implementation logic here
}

/// @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 override {
// Your custom implementation logic here
}

/// @dev Collects and distributes the primary sale value of NFTs being claimed.
function _collectPriceOnClaim(
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 NFTs 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();
}
}

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 ERC1155ClaimConditions extension detected on your contract which unlocks these features in the SDK:

Base Contracts Implementing 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 NFTs to claim.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • Parameter quantity: The quantity of NFTs 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 phase,
bool resetClaimEligibility
) external;
  • Lets an authorized wallet set the claim condition for the contract.
  • Parameter tokenId: The tokenId for which to set the claim condition.
  • Parameter phase: The set of restrictions that will apply to the minting of tokens on the contract.
    • startTimestamp: The unix timestamp after which the claim condition applies.
    • 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.
  • 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 tokenId,
address claimer,
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 tokenId: The tokenId of the NFTs to claim.
  • Parameter claimer: The wallet claiming tokens.
  • Parameter quantity: The quantity of NFTs 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.
getSupplyClaimedByWallet
function getSupplyClaimedByWallet(uint256 tokenId, address claimer)
public
view
returns (uint256);
  • Returns the number of tokens claimed by a wallet under the active condition.
  • Parameter tokenId: The tokenId of the NFTs to claim.
  • 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 NFTs to claim.
  • Parameter quantity: The quantity of NFTs 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 NFTs to claim.
  • Parameter quantity: The quantity of NFTs 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(
address primarySaleRecipient,
uint256 quantityToClaim,
address currency,
uint256 pricePerToken
) internal virtual;
  • Collects and distributes the primary sale value of NFTs being claimed.
  • Parameter primarySaleRecipient: The recipient of the primary sale value generated from a claim.
  • Parameter quantityToClaim: The quantity of NFTs 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
returns (uint256 startTokenId);
  • Transfers the NFTs being claimed to the appropriate recipient.
  • Parameter to: The recipient of the tokens for a claim.
  • Parameter tokenId: The tokenId of the NFTs being claimed.
  • Parameter quantityBeingClaimed: The quantity of NFTs 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.