1

I am working on a NFT project using the ERC721 token standard, and I cannot get the ERC721 contract to deploy in remix.

Here is the ERC721 contract:

   contract ERC721 {
  event Transfer(address indexed _from, address indexed _to, uint256 _tokenId);
  event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);

  function totalSupply() constant returns (uint256 totalSupply); //implemented
  function implementsERC721() public pure returns (bool); //implemented
  function balanceOf(address _owner) public view returns (uint256 _balance); //implemented
  function ownerOf(uint256 _tokenId) public view returns (address _owner); //implemented
  function transfer(address _to, uint256 _tokenId) public; //implemented
  function approve(address _to, uint256 _tokenId) public; //implemented
  function takeOwnership(uint256 _tokenId) public; //implemented
  function transferFrom(address _from, address _to, uint _tokenId) public; //implemented
}

Here is the contract that implements all of the functions:

    contract OwlOwnership is ERC721, OwlHatchery {


  using SafeMath for uint256;

  modifier onlyOwnerOf(uint _owlId) {
    require(msg.sender == owlToOwner[_owlId]);
    _;
  }

  mapping (uint => address) owlApprovals;

  function implementsERC721() public pure returns (bool) {
        return true;
    }

  function balanceOf(address _owner) public view returns (uint256 _balance) {
    return ownerOwlCount[_owner];
  }

  function ownerOf(uint256 _tokenId) public view returns (address _owner) {
    return owlToOwner[_tokenId];
  }


    function _owns(address _claimant, uint256 _tokenId) internal view returns (bool){
        return owlToOwner[_tokenId] == _claimant;
    }


    function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool){
        return owlApprovals[_tokenId] == _claimant;
    }

  function _transfer(address _from, address _to, uint256 _tokenId) private {
    ownerOwlCount[_to] = ownerOwlCount[_to].add(1);
    ownerOwlCount[msg.sender] = ownerOwlCount[msg.sender].sub(1);
    owlToOwner[_tokenId] = _to;
    Transfer(_from, _to, _tokenId);
  }

  function transfer(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
    _transfer(msg.sender, _to, _tokenId);
  }

  function transferFrom(address _from, address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
        require(_to != address(0));
        require(_to != address(this));
        require(_approvedFor(msg.sender, _tokenId));
        require(_owns(_from, _tokenId));
        _transfer(_from, _to, _tokenId);
    }

  function approve(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
    owlApprovals[_tokenId] = _to;
    Approval(msg.sender, _to, _tokenId);
  }

  function takeOwnership(uint256 _tokenId) public {
    require(owlApprovals[_tokenId] == msg.sender);
    address owner = ownerOf(_tokenId);
    _transfer(owner, msg.sender, _tokenId);
  }
}

I can deploy all other contracts in my project besides the ERC721 contract. I keep getting "This contract does not implement all functions and thus cannot be created.". Any ideas?

0

In the contract code you provided, you haven't implemented the totalSupply function,

function totalSupply() constant returns (uint256 totalSupply); //implemented

which is most likely why you're receiving the error.

However, there appears to be a larger issue with your code, which is that you're working to an incorrect or outdated version of the ERC-721 standard.

The final version can be found here, and this is the only one you should be working to. If you were following a tutorial, or borrowing code from another project, it was most likely out of date.

This matters, because if you don't follow the standard in its finalised form, then your contract won't be ERC-721 compliant, which defeats the purpose of working to a standard at all.

  • good catch, I missed that function. And yes, I do know the standard I'm using is outdated, this particular project is just a test for a concept I will later migrate to the latest standard. Thanks so much for your help. – colyerfs Aug 22 '18 at 18:08

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.