soliditysmartcontractsnftopenzeppelin

Using Strings for uint256 not working with ERC721EnumerableUpgradeable


just like the title says I cannot get using Strings to compile, I keep getting the identifier not found. This is the start of my .sol contract

import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";

contract NFT is Initializable, StringsUpgradeable, ERC721EnumerableUpgradeable, OwnableUpgradeable {
using Strings for uint256; 

Please help!

Thank you!


Solution

  • The imported StringsUpgradeable.sol file contains a library named StringsUpgradeable - not Strings.

    Also, since it's a library, it cannot be inherited from, so you need to remove it from the list of the NFT parents.

    pragma solidity ^0.8;
    
    import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
    import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
    import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
    import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
    
    // removed `StringsUpgradable` from the parents list
    contract NFT is Initializable, ERC721EnumerableUpgradeable, OwnableUpgradeable {
    
        // replaced `Strings` to `StringsUpgradable`
        using StringsUpgradeable for uint256; 
    }