A
A
Alexander Gerasimov2022-03-13 16:02:00
Programming
Alexander Gerasimov, 2022-03-13 16:02:00

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);
    }
}

So, the transaction with the burning of the token does not go through. It rolls over and has the following error:
Warning! Error encountered during contract execution [stack underflow (1 <=> 8)

] type 0 - 1 falls out on the border. If I wrote the functional myself, then it would be a different matter, but I use basic functions that, in my opinion, should work without any magic.

Who faced similar? What solution did you find?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chtulhu, 2022-03-13
@agerasimov

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 question

Ask a Question

731 491 924 answers to any question