Ethereum 升级智能合约时出错“坚固性”类型错误:合约;IERC721“;应标记为抽象

Ethereum 升级智能合约时出错“坚固性”类型错误:合约;IERC721“;应标记为抽象,ethereum,solidity,Ethereum,Solidity,我正在尝试将我的合同版本从0.5.0升级到0.8.0。我将向操作员授予此智能合同的权限。稍后通过这个智能合约,我将进行NFT代币转账。这是0.5.0版的合同 pragma solidity ^0.5.0; interface IERC165 { function supportsInterface(bytes4 interfaceId) external view returns (bool); } contract IERC721 is IERC165 { event Tr

我正在尝试将我的合同版本从0.5.0升级到0.8.0。我将向操作员授予此智能合同的权限。稍后通过这个智能合约,我将进行NFT代币转账。这是0.5.0版的合同

pragma solidity ^0.5.0;

interface IERC165 {
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

contract IERC721 is IERC165 {
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    function balanceOf(address owner) public view returns (uint256 balance);
    function ownerOf(uint256 tokenId) public view returns (address owner);
    function safeTransferFrom(address from, address to, uint256 tokenId) public;
    function transferFrom(address from, address to, uint256 tokenId) public;
    function approve(address to, uint256 tokenId) public;
    function getApproved(uint256 tokenId) public view returns (address operator);
    function setApprovalForAll(address operator, bool _approved) public;
    function isApprovedForAll(address owner, address operator) public view returns (bool);
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public;
}

contract TransferProxy {

    function erc721safeTransferFrom(IERC721 token, address from, address to, uint256 tokenId) external {
        token.safeTransferFrom(from, to, tokenId);
    }
}
但当我将solidity版本更改为0.8.0时,我得到以下错误:

TypeError: Contract "IERC721" should be marked as abstract.
 --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:7:1:
  |
7 | contract IERC721 is IERC165 {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:16:5:
   |
16 |     function approve(address to, uint256 tokenId) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:12:5:
   |
12 |     function balanceOf(address owner) public view returns (uint256 balance);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:17:5:
   |
17 |     function getApproved(uint256 tokenId) public view returns (address operator);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:19:5:
   |
19 |     function isApprovedForAll(address owner, address operator) public view returns (bool);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:13:5:
   |
13 |     function ownerOf(uint256 tokenId) public view returns (address owner);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:14:5:
   |
14 |     function safeTransferFrom(address from, address to, uint256 tokenId) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:20:5:
   |
20 |     function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:18:5:
   |
18 |     function setApprovalForAll(address operator, bool _approved) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
 --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:4:5:
  |
4 |     function supportsInterface(bytes4 interfaceId) external view returns (bool);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation:
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:15:5:
   |
15 |     function transferFrom(address from, address to, uint256 tokenId) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:12:5:
   |
12 |     function balanceOf(address owner) public view returns (uint256 balance);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:13:5:
   |
13 |     function ownerOf(uint256 tokenId) public view returns (address owner);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:14:5:
   |
14 |     function safeTransferFrom(address from, address to, uint256 tokenId) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:15:5:
   |
15 |     function transferFrom(address from, address to, uint256 tokenId) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:16:5:
   |
16 |     function approve(address to, uint256 tokenId) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:17:5:
   |
17 |     function getApproved(uint256 tokenId) public view returns (address operator);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/delete/transfer-proxy/contracts/TransferProxy.sol:18:5:
   |
18 |     function setApprovalForAll(address operator, bool _approved) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/transfer-proxy/contracts/TransferProxy.sol:19:5:
   |
19 |     function isApprovedForAll(address owner, address operator) public view returns (bool);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Functions without implementation must be marked virtual.
  --> /Users/transfer-proxy/contracts/TransferProxy.sol:20:5:
   |
20 |     function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Compilation failed. See above.
Truffle v5.3.1 (core: 5.3.1)
Node v12.14.0

请帮助我解决此问题。

在Solidity 0.6中引入了抽象合同。与许多其他编程语言一样,抽象类允许使用部分实现定义接口

因此,您可以将合同标记为
abstract

abstract contract IERC721 is IERC165 {
interface IERC721 is IERC165 {
并将没有实现的函数标记为
外部虚拟
(而不是
公共


因为您的
IERC721
没有实现任何功能,所以它也可以标记为
接口
(而不是
摘要

这还将在冗余的
虚拟
修改器上向您发出警告,因此您也可以将其删除(但可见性修改器需要保持在
外部

interface IERC721 is IERC165 {
function balanceOf(address owner) external view returns (uint256 balance);