简体   繁体   English

如何烧录erc721 token?

[英]How to burn erc721 token?

I am trying to burn erc721 token.我正在尝试刻录 erc721 令牌。 I have inherited ERC721Burnable contract,but the transaction gets failed.While debugging I found that in ERC721URIStorage contract,it reverts back at:我已经继承了ERC721Burnable合约,但是交易失败了。在调试时我发现在ERC721URIStorage合约中,它恢复到:

if (bytes(_tokenURIs[tokenId]).length != 0) {
    delete _tokenURIs[tokenId];
}

Also I want the owner of the contract to have the ability to modify the attributes of metadata,even after the token is minted and transferred.此外,我希望合同的所有者能够修改元数据的属性,即使在令牌被铸造和转移之后也是如此。 This is my contract:这是我的合同:

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

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract MyNFT is ERC721, ERC721Enumerable, ERC721URIStorage, ERC721Burnable, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;
    uint MAX_SUPPLY=1;

    constructor() ERC721("MyNFT", "MNFT") {}

    function safeMint(address to, string memory uri) public onlyOwner {
        require(totalSupply() < MAX_SUPPLY, "Can be minted only one time.");
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    // The following functions are overrides required by Solidity.

    function _beforeTokenTransfer(address from, address to, uint256 tokenId)
        internal
        override(ERC721, ERC721Enumerable)
    {
        super._beforeTokenTransfer(from, to, tokenId);
    }

The code you provided works (although it's missing an ending } ).您提供的代码有效(尽管它缺少结尾 } )。 You must be trying to burn a token that doesn't exist (maybe it's already been burned)?您一定是在尝试销毁一个不存在的令牌(也许它已经被销毁了)?

To change the props of the NFT after it's already been minted, all you need to do is just return different properties in the return value from the token URI.要在 NFT 生成后更改其属性,您只需在令牌 URI 的返回值中返回不同的属性即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM