简体   繁体   English

继承多个 ERC721 扩展

[英]Inheriting multiple ERC721 extensions

I would like to use both ERC721URIStorage for setting token URI easily but I would also like the methods in ERC721Enumberable to fetch the number of tokens made by an address.我想同时使用 ERC721URIStorage 来轻松设置令牌 URI,但我也希望使用 ERC721Enumberable 中的方法来获取地址生成的令牌数量。
I get this error when trying to use both:尝试同时使用两者时出现此错误:

Derived contract must override function "_beforeTokenTransfer". Two or more base classes define function with same name and parameter types.
Derived contract must override function "_burn". Two or more base classes define function with same name and parameter types.
Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.
Derived contract must override function "tokenURI". Two or more base classes define function with same name and parameter types.

is this just not possible at all or is there a way to Override the duplicated functions?这是根本不可能的,还是有办法覆盖重复的功能?

Below code overrides the overlapping functions from the two extensions下面的代码覆盖了两个扩展的重叠函数


pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";


contract NameOfContract is ERC721URIStorage, ERC721Enumerable {

    // Contract Code ....
    
    function _beforeTokenTransfer(address from, address to, uint256 tokenId)
        internal
        override(ERC721, ERC721Enumerable)
    {
        super._beforeTokenTransfer(from, to, tokenId);
    }

    function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
        super._burn(tokenId);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721Enumerable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }

}

Update _beforeTokenTransfer has a new parameter and argument更新 _beforeTokenTransfer 有一个新的参数和参数

Now it is like现在就像

 function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
    internal
    override(ERC721, ERC721Enumerable)
{
    super._beforeTokenTransfer(from, to, tokenId, batchSize);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM