我如何在 NFT 铸造时披露它们?

发布于 2025-01-09 18:22:59 字数 1320 浏览 0 评论 0原文

我的目标是让我的揭示函数只在 NFT 被购买/铸造时揭示它,而不是揭示整个集合,这样人们就不必等待,但我只是继续把它搞砸。

这是我

string baseURI;
  string public baseExtension = ".json";
  uint256 public cost = 0.05 ether;
  uint256 public maxSupply = 10000;
  uint256 public maxMintAmount = 20;
  bool public paused = true;
  bool public revealed = false;
  string public notRevealedUri;
  bool public onlyWhitelisted = true;
  address[] public whitelistedAddresses;
  mapping(address => uint256) public addressMintedBalance;
  uint256 public nftPerAddressLimit = 100;
  mapping(uint256 => string) private _tokenURI;
  

  constructor(
    string memory _name,
    string memory _symbol,
    string memory _initBaseURI,
    string memory _initNotRevealedUri
  ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
  }

现在所掌握的内容,

function reveal() public onlyOwner {
      revealed = false;
  }

我似乎想不出一种方法可以在特定代币被铸造时改变它们的 bool 值。

我的想法是它应该位于 mint 函数本身的末尾,尽管我对此一点信心都没有。

for (uint256 i = 1; i <= _mintAmount; i++) {
      addressMintedBalance[msg.sender]++;
      _safeMint(msg.sender, supply + i);
      _tokenURI[supply].revealed = true; <-- *I know this wont work if anyone ever mints more than one at a time.*
    }

My goal is to get my reveal function to only reveal the NFT as it gets bought/minted and not reveal the whole collection so that people don't have to wait, however I just keep mucking it up.

Here is what I've got

string baseURI;
  string public baseExtension = ".json";
  uint256 public cost = 0.05 ether;
  uint256 public maxSupply = 10000;
  uint256 public maxMintAmount = 20;
  bool public paused = true;
  bool public revealed = false;
  string public notRevealedUri;
  bool public onlyWhitelisted = true;
  address[] public whitelistedAddresses;
  mapping(address => uint256) public addressMintedBalance;
  uint256 public nftPerAddressLimit = 100;
  mapping(uint256 => string) private _tokenURI;
  

  constructor(
    string memory _name,
    string memory _symbol,
    string memory _initBaseURI,
    string memory _initNotRevealedUri
  ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
  }

now for the reveal

function reveal() public onlyOwner {
      revealed = false;
  }

I can't seem to think of a way that would change the bool for specific tokens as they get minted.

My thought was that it should be at the end of the mint function itself, though I am not at all confident in that.

for (uint256 i = 1; i <= _mintAmount; i++) {
      addressMintedBalance[msg.sender]++;
      _safeMint(msg.sender, supply + i);
      _tokenURI[supply].revealed = true; <-- *I know this wont work if anyone ever mints more than one at a time.*
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨轻弹 2025-01-16 18:22:59

您可以包含一个映射来保存您的 nfts 的显示状态。我不确定您是否只希望管理员每次都调用此显示函数,在这种情况下这样做就可以了!

....
mapping(address => mapping(uint256 => bool)) private reveals;


constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
    ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
}

function reveal(address _nftContract, uint256 tokenId, bool _reveal) external onlyOwner {
    bool revealed  = reveals[_nftContract][tokenId];
    require(!revealed, 'Token Already revealed');
    reveals[_nftContract][tokenId] = true;

  }

You can include a mapping to hold the reveal states of your nfts. I am not sure whether you intended only admin to call this reveal function every time, in this case this would do!

....
mapping(address => mapping(uint256 => bool)) private reveals;


constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
    ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
}

function reveal(address _nftContract, uint256 tokenId, bool _reveal) external onlyOwner {
    bool revealed  = reveals[_nftContract][tokenId];
    require(!revealed, 'Token Already revealed');
    reveals[_nftContract][tokenId] = true;

  }
美羊羊 2025-01-16 18:22:59

做我要求的最好方法,实际上是不要自己铸造任何东西,并在网站上有一个D应用程序,这样总供应量只是已铸造的,因此只能指向baseURI

The best method of doing what I asked, is in fact to not mint any yourself, and have a D-app on a website so that total supply is only that of what has been minted, thus can only point to the baseURI then

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文