使用 uint256 的字符串不适用于 ERC721EnumerableUpgradeable

问题描述 投票:0回答:2

就像标题说我无法使用字符串进行编译一样,我不断收到找不到标识符的信息。 这是我的 .sol 合约的开始

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; 

请帮忙!

谢谢!

solidity smartcontracts nft openzeppelin
2个回答
2
投票

导入的

StringsUpgradeable.sol
文件包含一个名为
StringsUpgradeable
的库 - 而不是
Strings

此外,由于它是一个库,因此无法继承它,因此您需要将其从

NFT
父级列表中删除。

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

0
投票

我想编译合同,它给了我这个错误。感谢您的帮助 以前的版本编译没有错误,现在就不行了?

© www.soinside.com 2019 - 2024. All rights reserved.