8

I'm getting the error:

Contract "StarNotary" should be marked as abstract.

pragma solidity >=0.4.24;

import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";


contract StarNotary is ERC721 {
    struct Star {
        string name;
    }

    mapping(uint256 => Star) public tokenIdToStarInfo;
    mapping(uint256 => uint256) public starsForSale;

    // Create Star using the Struct
    function createStar(string memory _name, uint256 _tokenId) public {
        Star memory newStar = Star(_name);
        tokenIdToStarInfo[_tokenId] = newStar;
        _mint(msg.sender, _tokenId);
    }

    // Putting an Star for sale (Adding the star tokenid into the mapping starsForSale, first verify that the sender is the owner)
    function putStarUpForSale(uint256 _tokenId, uint256 _price) public {
        require(
            ownerOf(_tokenId) == msg.sender,
            "You can't sale the Star you don't owned"
        );
        starsForSale[_tokenId] = _price;
    }

    function _make_payable(address x) internal pure returns (address payable) {
        return address(uint160(x));
    }

    function buyStar(uint256 _tokenId) public payable {
        require(starsForSale[_tokenId] > 0, "The Star should be up for sale");
        uint256 starCost = starsForSale[_tokenId];
        address ownerAddress = ownerOf(_tokenId);
        require(msg.value > starCost, "You need to have enough Ether");
        transferFrom(ownerAddress, msg.sender, _tokenId);
        address payable ownerAddressPayable = _make_payable(ownerAddress);
        ownerAddressPayable.transfer(starCost);
        if (msg.value > starCost) {
            msg.sender.transfer(msg.value - starCost);
        }
    }
}

What I know of abstract contracts is that they have to do with interfaces. I have a suspicion that it has to do with the inheritance from ERC721 of the Open Zeppelin library.

ERC721 has three interfaces it's inheriting from: IERC721, IERC721Metadata, IERC721Enumerable. Do I have to go through the entire list of functions from those three interfaces and fill in what's missing in either the StarNotary contract or ERC721?

15

You are missing the constructor call. Even if you don't want to change the original ERC721 constructor, you still need one in your contract. Therefore you get the error of declaring it 'an abstract' contract. Abstract contracts cannot be instantiated.

constructor() ERC721("GameItem", "ITM") public { }

is already enough. You can always check the docs to see how to use a contract: https://docs.openzeppelin.com/contracts/3.x/erc721

1
  • wow that worked. Thank you so much
    – Kevvv
    May 11 '20 at 14:14
8

@Markus's answer is correct. But you should also be sure that there isn't a

Missing implementation: function ...

line hiding just beneath the error message. In my case I was inheriting from an Interface, but forgetting to implement one of the necessary functions.

1
  • 2
    nice suggestion to add
    – Jeevanjot
    Feb 10 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.