0

As it's not been minted yet, it doesn't exist, right?

However, what if I had an idea to create a future collection of 333 NFT. And I wanted to allow certain users to mint certain NFTs. Meaning, future ones.

Would this be possible? Could I refer to an id-s of the NFTs that haven't been minted yet, to create a mapping, and would this work?

    mapping(uint => address) private _nftsUsersWhiteList;
    //mapping(uint => address[]) private _nftsUsersWhiteList;

Would there be downsides?


Both ERC721 and ERC1155

1 Answer 1

1

Yes, you can make a whitelist contract and have users join the whitelist before you launch your NFT collection. The whitelist contract can look something like this:

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

import "@openzeppelin/contracts/access/Ownable.sol";

error TransactionFailed();
error SpendMoreETH();

/**
 * @title Whitelist
 * @dev A contract that manages a whitelist of addresses.
 */
contract Whitelist is Ownable {
  address[] private _whitelisted;
  uint256 public immutable WHITELIST_FEES = 1274577610908013100; // about 1.3 ETH

  event Whitelist__Joined(address indexed);

  /**
   * @dev Allows an address to join the whitelist by paying the required fees.
   * Emits a Whitelist__Joined event upon successful registration.
   */
  function joinWhitelist() public payable {
    if (msg.value <= WHITELIST_FEES) {
      revert SpendMoreETH();
    }
    _whitelisted.push(msg.sender);

    emit Whitelist__Joined(msg.sender);
  }

  /**
   * @dev Allows the owner to withdraw the contract's balance.
   * Emits a TransactionFailed error if the withdrawal fails.
   */
  function withdraw() public onlyOwner {
    address receiver = msg.sender;
    (bool sent, ) = receiver.call{value: address(this).balance}("");
    if (sent != true) {
      revert TransactionFailed();
    }
  }

  /**
   * @dev Checks if an address is whitelisted.
   * @param _addr The address to check.
   * @return A boolean value indicating whether the address is whitelisted.
   */
  function isWhitelisted(address _addr) public view returns (bool) {
    for (uint i = 0; i < _whitelisted.length; i++) {
      if (_whitelisted[i] == _addr) {
        return true;
      }
    }
    return false;
  }
}

Later, in your NFT contract you can access the whitelisted members and do some action (discounts / rewards). Your mint function could look something like this:

function mintNft() public payable returns (uint256 requestId) {
        if(whitelistContract.isWhitelisted(msg.sender)){
            // do something
        }
}
1
  • wrong. re-read my question
    – DankenN
    Jun 8, 2023 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.