Skip to main content

ERC1155 Delayed Reveal

import "@thirdweb-dev/contracts/base/ERC1155DelayedReveal.sol";

ERC1155DelayedReveal adds the Delayed Reveal feature to the ERC1155LazyMint base contract.

Delayed reveal allows you to distribute NFTs to your audience with placeholder metadata, and reveal the real metadata of the distributed NFTs at a later time using a password.

Detected Extensions

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.

Usage

Import the contract and inherit from it.

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

import "@thirdweb-dev/contracts/base/ERC1155DelayedReveal.sol";

contract MyNFT is ERC1155DelayedReveal {
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC1155DelayedReveal(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {}
}

Functions to Override

The following functions have been implemented on this contract & are available to be overridden to add custom logic:

uri
    /**
* @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 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()));
}
}
lazyMint
    /**
* @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 super.lazyMint(_amount, _baseURIForTokens, _data);
}
reveal
    /**
* @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) external 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);
}

/// @dev Checks whether NFTs can be revealed in the given execution context.
function _canReveal() internal view virtual returns (bool) {
return msg.sender == owner();
}