Skip to main content

ERC1155ClaimPhases

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

Allow other wallets to claim/mint tokens from the contract under the criteria of claim conditions by implementing ERC1155 and Drop.

Unlike ERC1155ClaimCondition, this extension allows you to set multiple claim phases.

This is an extension which is detectable in the dashboard if the smart contract implements the ERC1155 and Drop extensions.

Usage

This is an example smart contract demonstrating how to inherit from the extensions which make up the ERC1155ClaimPhases detectable extension. The functions which are available to be (optionally) overridden are also detailed.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract Contract is ERC1155, LazyMint, Drop1155 {
constructor(
string memory _name,
string memory _symbol
)
ERC1155(
_name,
_symbol
)
{}

function _canLazyMint() internal view override returns (bool) {
// Your custom implementation here
}

/// @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 {}

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

SDK Usage

By adding this extension to a smart contract, the following features, hooks and functions are unlocked in the SDK:

Base Contracts Implementing This Extension

None of the base contracts implement this extension.