javascript 从坚固性:类型错误:合同"ConcreteNFTmarketplace"应标记为摘要

wkftcu5l  于 2023-02-15  发布在  Java
关注(0)|答案(2)|浏览(82)

我有这个智能合约..但它给了我这个错误..我知道有很多问题有关于这件事,但没有找到答案,包括两个合同
从坚固性:类型错误:合同"ConcreteNFTmarketplace"应标记为摘要。
即使NFTmarketplace被标记为抽象,为什么

pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

abstract contract NFTmarketplace is ERC721URIStorage, IERC721Receiver {

    constructor() ERC721("astro market", "astro"){
        owner = payable(msg.sender);
    }
}

contract ConcreteNFTmarketplace is NFTmarketplace {

    function onERC721Received(address _from, uint256 _tokenId) external  {
        // Transfer the received ERC721 token to the owner
        transferFrom(_from, address(this), _tokenId);
    }
}
oipij1gg

oipij1gg1#

我已经编辑了你的代码,一切正常.关于嵌入IERC721Receiver,实际上没有必要,因为要接收nfts,你可以像我在ConcreteNFTmarketplace中那样在ERC721Received上实现函数,但你也可以继承它,没有任何错误.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract NFTmarketplace is ERC721URIStorage {
address public owner; 

constructor() ERC721("astro market", "astro"){
    owner = payable(msg.sender);
}

function mint(address to, uint tokenId) public {
    _mint(to, tokenId);
}
}

contract ConcreteNFTmarketplace is NFTmarketplace {

// function onERC721Received(address _from, uint256 _tokenId) external  {
//     // Transfer the received ERC721 token to the owner
//     transferFrom(_from, address(this), _tokenId);
// }

function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
    return this.onERC721Received.selector;
} 
}
ne5o7dgx

ne5o7dgx2#

不需要从IERC721Receiver继承。

contract NFTmarketplace is ERC721URIStorage {your contract}

相关问题