基础的定义必须先于派生合约的定义(ERC721 实现)

Definition of base has to precede definition of derived contract (ERC721 implementation)

or ETH Stack Exchange 个答案似乎不适用于我的情况(当然我可能是错的)

我在这个文件的标题中得到了错误描述符:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./ERC721Metadata.sol";
import "./ERC721.sol";

contract ERC721Connector is ERC721Metadata, ERC721 {
                                         // ^^^^^^^ (Definition of base has to precede definition of derived contract)
    constructor(string memory name, string memory symbol) ERC721Metadata(name, symbol) {}
}

这是 ERC721Metadadata 的样子:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ERC721Metadata {
    string private _name;
    string private _symbol;

    constructor(string memory named, string memory symbolified) {
        _name = named;
        _symbol = symbolified;
    }

    function name() external view returns (string memory) {
        return _name;
    }

    function symbol() external view returns (string memory) {
        return _symbol;
    }
}

这是 ERC721 的样子:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./ERC721Metadata.sol";
import "./ERC721Connector.sol";

contract ERC721 {
    event Transfer(
        address indexed from,
        address indexed to,
        uint256 indexed tokenId
    );

    mapping(uint256 => address) private _tokenOwner;
    mapping(address => uint256) private _OwnedTokensCount;

    function _exists(uint256 tokenId) internal view returns (bool) {
        address owner = _tokenOwner[tokenId];
        return owner != address(0);
    }

    function _mint(address to, uint256 tokenId) internal {
        require(to != address(0), "ERC721: minting to the zero address");
        require(
            !_exists(tokenId),
            "ERC721: minting a token that already exists (been minted)"
        );
        _tokenOwner[tokenId] = to;
        _OwnedTokensCount[to] += 1;

        emit Transfer(address(0), to, tokenId);
    }
}

您的 ERC721 合同中是否需要导入 ERC721Connector 合同?如果没有,您可以删除

import "./ERC721Connector.sol"; // line 4, ERC721.sol

来自您的文件,它应该可以正常工作。您的导入导致了问题,

ERC721Connector 尝试导入 ERC721,但是 ERC721 还需要 ERC721Connector 所以编译器说

Definition of base has to precede definition of derived contract

因为基础合同不先于定义的合同。