Docs

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.

View on GitHub

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();
    }
}

Base Contracts Implementing This Extension

Full API reference