0

So I know that in the past there used to be an ERC721Full.sol inside the token directory of openzeppelin but now it seems that they have added an extensions folder that I just can't seem to understand. I want and URI storage _setTokenURI() for my NFTs and the Enumerable extension so I can access my totalSupply() but I have not been able to find anywhere a good answer. Thanks a lot!

2

You just can use multiple inheritance. Inheriting from multiple base classes can be tricky, you have to fulfill each base class' method requirements. A simple example is in the Solidity docs. Basically you'll override virtual methods of base classes, and you have to specify which base class you're overriding. Alternatively you may use Openzeppelin's ERC721PresetMinterPauserAutoId class, this may satisfy ERC721Full you've mentioned.

Here is a little bit detailed example, if you want to mix it with other base contracts.

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Pausable.sol";

contract TestContract is ERC721Burnable, ERC721Enumerable, ERC721Pausable {
    constructor() 
    ERC721("Test Nft", "TNFT")
    {
    }
    
    /**
     * override(ERC721, ERC721Enumerable, ERC721Pausable) 
     * here you're overriding _beforeTokenTransfer method of
     * three Base classes namely ERC721, ERC721Enumerable, ERC721Pausable
     * */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal
      override(ERC721, ERC721Enumerable, ERC721Pausable) {
        super._beforeTokenTransfer(from, to, tokenId);
    }
    
    /**
     * override(ERC721, ERC721Enumerable) -> here you're specifying only two base classes ERC721, ERC721Enumerable
     * */
    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721Enumerable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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