ERC1155Drop
import "@thirdweb-dev/contracts/base/ERC1155Drop.sol";
The ERC1155Drop
base contract is the foundation for an Edition (ERC1155) NFT Drop that other wallets can claim.
It implements the ERC1155 standard with Lazy Mint, Delayed Reveal and Drop extensions; allowing you to batch lazy-mint NFTs, and allow other wallets to claim them under the criteria of claim conditions, with an optional delayed reveal.
View on GitHub
Import the contract and inherit from it.
// SPDX-License-Identifier: Apache-2.0pragma solidity ^0.8.0;import "@thirdweb-dev/contracts/base/ERC1155Drop.sol";contract MyNFT is ERC1155Drop {constructor(address _defaultAdmin,string memory _name,string memory _symbol,address _royaltyRecipient,uint128 _royaltyBps,address _primarySaleRecipient)ERC1155Drop(_defaultAdmin,_name,_symbol,_royaltyRecipient,_royaltyBps,_primarySaleRecipient){}}
Once deployed, you can use the features made available by these extensions on the SDK and dashboard:
Click on each feature to learn more about what functions are available.
- ERC1155
- ERC1155LazyMintableV2
- ERC1155Burnable
- ERC1155Enumerable
- ERC1155ClaimConditionsV2
- PrimarySale
- Royalty
- ContractMetadata
- Ownable
The following functions have been implemented on this contract & are available to be overridden to add custom logic:
/*** @notice Lets an owner or approved operator burn NFTs of the given tokenId.** @param _owner The owner of the NFT to burn.* @param _tokenId The tokenId of the NFT to burn.* @param _amount The amount of the NFT to burn.*/function burn(address _owner,uint256 _tokenId,uint256 _amount) external virtual {address caller = msg.sender;require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved caller");require(balanceOf[_owner][_tokenId] >= _amount, "Not enough tokens owned");_burn(_owner, _tokenId, _amount);}
/*** @notice Lets an owner or approved operator burn NFTs of the given tokenIds.** @param _owner The owner of the NFTs to burn.* @param _tokenIds The tokenIds of the NFTs to burn.* @param _amounts The amounts of the NFTs to burn.*/function burnBatch(address _owner,uint256[] memory _tokenIds,uint256[] memory _amounts) external virtual {address caller = msg.sender;require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved caller");require(_tokenIds.length == _amounts.length, "Length mismatch");for (uint256 i = 0; i < _tokenIds.length; i += 1) {require(balanceOf[_owner][_tokenIds[i]] >= _amounts[i], "Not enough tokens owned");}_burnBatch(_owner, _tokenIds, _amounts);}
/*** @notice Returns the metadata URI for an NFT.* @dev See `BatchMintMetadata` for handling of metadata in this contract.** @param _tokenId The tokenId of an NFT.*/function uri(uint256 _tokenId) public view virtual override returns (string memory) {(uint256 batchId, ) = _getBatchId(_tokenId);string memory batchUri = _getBaseURI(_tokenId);if (isEncryptedBatch(batchId)) {return string(abi.encodePacked(batchUri, "0"));} else {return string(abi.encodePacked(batchUri, _tokenId.toString()));}}
/*** @notice Lets an authorized address reveal a batch of delayed reveal NFTs.** @param _index The ID for the batch of delayed-reveal NFTs to reveal.* @param _key The key with which the base URI for the relevant batch of NFTs was encrypted.*/function reveal(uint256 _index, bytes calldata _key) public virtual override returns (string memory revealedURI) {require(_canReveal(), "Not authorized");uint256 batchId = getBatchIdAtIndex(_index);revealedURI = getRevealURI(batchId, _key);_setEncryptedData(batchId, "");_setBaseURI(batchId, revealedURI);emit TokenURIRevealed(_index, revealedURI);}
/*** @notice Lets an authorized address lazy mint a given amount of NFTs.** @param _amount The number of NFTs to lazy mint.* @param _baseURIForTokens The placeholder base URI for the 'n' number of NFTs being lazy minted, where the* metadata for each of those NFTs is `${baseURIForTokens}/${tokenId}`.* @param _data The encrypted base URI + provenance hash for the batch of NFTs being lazy minted.* @return batchId A unique integer identifier for the batch of NFTs lazy minted together.*/function lazyMint(uint256 _amount,string calldata _baseURIForTokens,bytes calldata _data) public virtual override returns (uint256 batchId) {if (_data.length > 0) {(bytes memory encryptedURI, bytes32 provenanceHash) = abi.decode(_data, (bytes, bytes32));if (encryptedURI.length != 0 && provenanceHash != "") {_setEncryptedData(nextTokenIdToLazyMint + _amount, _data);}}return LazyMint.lazyMint(_amount, _baseURIForTokens, _data);}
/// @dev Runs before every `claim` function call.function _beforeClaim(uint256 _tokenId,address,uint256,address,uint256,AllowlistProof calldata,bytes memory) internal view virtual override {if (_tokenId >= nextTokenIdToLazyMint) {revert("Not enough minted tokens");}}
/// @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 == address(0) ? primarySaleRecipient() : _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 Runs before every token transfer / mint / burn.function _beforeTokenTransfer(address operator,address from,address to,uint256[] memory ids,uint256[] memory amounts,bytes memory data) internal virtual override {super._beforeTokenTransfer(operator, from, to, ids, amounts, data);if (from == address(0)) {for (uint256 i = 0; i < ids.length; ++i) {totalSupply[ids[i]] += amounts[i];}}if (to == address(0)) {for (uint256 i = 0; i < ids.length; ++i) {totalSupply[ids[i]] -= amounts[i];}}}