Answer the question
In order to leave comments, you need to log in
NFT token burn or what's wrong?
Hello!
I will not pull the "rubber" and get straight to the point. After reviewing several different smart contracts, I was surprised that few people pawn burn tokens or it does not work at all. Out of the box, I didn't manage to do it either. There is the simplest Smart Contract:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract SFFContract is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("SFF NFT", "SFFNFT") {}
function mint(address recipient, string memory uri) public returns (uint256) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, uri);
return newItemId;
}
function burn(uint256 tokenId) public virtual {
_burn(tokenId);
}
}
Answer the question
In order to leave comments, you need to log in
https://github.com/OpenZeppelin/openzeppelin-contr...
You use _burn without checking if this token exists at all, as it is done in the extension
https://github.com/OpenZeppelin/openzeppelin-contr...
I advise you not to be smart in this case and use the erc721 wizard from the same openzeppelin
https://docs.openzeppelin.com/contracts/4.x/wizard (there is a burnable option)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question