Assignment - Get Kitty

hey @Maia! do you want to compile or deploy.
You can use simple truffle migrate --reset command and if you are getting the same error is because you need to run the cmd console as administrator.

When I run my program I am able to compile. However when I get into truffle and try to run createKittyGen0(101), it gives me an error saying revert and reason: You are not the owner. Can I get help?

KittyContract.sol

pragma solidity ^0.5.16;

import "./IERC721.sol";
import "./Ownable.sol";

contract KittyContract is IERC721, Ownable {

    uint16 private constant CREATION_LIMIT_GEN0 = 10;

    string public constant name = "SeanCats";

    string public constant symbol = "SC";

    event Birth (
        address owner,
        uint256 kittenId,
        uint256 momId,
        uint256 dadId,
        uint256 genes
    );

    struct Kitty { 
        uint256 genes;
        uint64 birthTime;
        uint32 momId;
        uint32 dadId;
        uint16 generation;
    }

    Kitty[] kitties;

    mapping (uint256 => address) public kittyIndexToOwner;
    mapping (address => uint256) ownershipTokenCount;

    uint256 public gen0Counter;

    function getKitty (uint256 _id) external view returns (
        uint256 genes,
        uint256 birthTime,
        uint256 momId,
        uint256 dadId,
        uint256 generation
    )
    { 
        Kitty storage kitty = kitties[_id];

        birthTime = uint256(kitty.birthTime);
        momId = uint256(kitty.momId);
        dadId = uint256(kitty.dadId);
        generation = uint256(kitty.generation);
        genes = kitty.genes;
    }

    function createKittyGen0(uint256 _genes) public onlyOwner returns (uint256) { 
        require(gen0Counter < CREATION_LIMIT_GEN0);

        gen0Counter++;

        return _createKitty(0, 0, 0, _genes, msg.sender);
    }

    function _createKitty(
        uint256 _genes,
        uint256 _momId,
        uint256 _dadId,
        uint256 _generation,
        address _owner
    ) private returns (uint256){
        Kitty memory _kitty = Kitty({
            genes: uint64(_genes),
            birthTime: uint64(now),
            momId: uint32(_momId),
            dadId: uint32(_dadId),
            generation: uint16(_generation)
        });
    
        kitties.push(_kitty);

        uint256 newKittenId = kitties.length - 1;

        emit Birth(_owner, newKittenId, _momId, _dadId, _genes);

        _transfer(address(0), _owner, newKittenId);

        return newKittenId;
    }
     
    function balanceOf(address owner) external view returns (uint256 balance) {
        return ownershipTokenCount[owner];
    }

    function totalSupply() external view returns (uint) {
        return kitties.length;
    }

    function ownerOf(uint256 _tokenId) external view returns (address) { 
        return kittyIndexToOwner[_tokenId];
    }

    function transfer(address _to, uint256 _tokenId) external {
        require(_to != address(0));
        require(_to != address(this));
        require(_owns(msg.sender, _tokenId));
       
       _transfer(msg.sender, _to, _tokenId);
    }

    function _transfer(address _from, address _to, uint256 _tokenId) internal {
        ownershipTokenCount[_to]++;

        kittyIndexToOwner[_tokenId] = _to;

        if(_from != address(0)) {
            ownershipTokenCount[_from]--;
        }

        emit Transfer(_from, _to, _tokenId);
    }

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

}

Ownable.sol

pragma solidity ^0.5.16;

contract Ownable {

    address public owner = msg.sender;

    modifier onlyOwner() {
        require (msg.sender == owner, "You are not the owner");
        _;
    }
}

hey @Sean_Kim! In this case make sure that you are using the same account you used to deploy the contract. When you deploy, it will use the first account in your local blockchain. When you are running ganache, you can see the accounts and import the private key to your metamask. So you can call this function with owner account.

Ok, it doesn’t compile and it says it requires a different compiler version. However, even when I change for 0.8.7 version both IERC721 and Kittycontract files still do not compile. Could you please check what am I missing? Thank you.
kittycontract.sol

pragma solidity ^0.5.16;

import"./IERC271.sol";
import"./Owable.sol";


contract kittycontract is IERC721, Ownable {
    
    uint256 public constant CREATION_LIMIT_GEN0 = 10;
    string public constant Name = "CreepyKitty";
    string public constant Symbol = "CRPY";

    event Birth(
        address owner,
        uint256 kittenId,
        uint256 mumId,
        uint256 dadId,
        uint256 genes
    )

    struct kitty {
        uint256 genes;
        uint64 birthtime;
        uint32 mumId;
        uint32 dadId;
        uint16 generation;
    }

    Kitty[] creepykitty;

    mapping(uint256=> address) public kittyIndexToOwner;
    mapping(address => uint256) ownershipTokenCount;

    uint256 public gen0counter;

    function getKitty(uint256 _id) external view return(
        uint256 genes,
        uint256 birthtime,
        uint256 mumId,
        uint256 dadId,
        uint256 generation,
    )
    {
        kitty storage kitty = kitties[_id];

        
        birthtime = uint256(kitty.birthTime);
        mumId = uint256(kitty.mumId);
        dadId = uint256(kitty.dadId);
        generation = uint256(kitty.generation);
        genes = kitty.genes
    }

    function createKittyGen0(uint256 _genes) public onlyOwner returns (uint256) {
        require (gen0counter < CREATION_LIMIT_GEN0);

        gen0Counter++;

        //Gen0 have no owners they are own by the contract
        return _createKitty(0,0,0, _genes, msg.sender);
    }

    function _createKitty(
        uint256 _mumId,
        uint256 _dadId,
        uint256 _generation,
        uint256 _genes,
        address _owner,
    ) private returns (uint256) {
        kitty memory _kitty = kitty({
            genes: _genes,
            birthTime: uint64(now),
            mumId: uint32(_mumId),
            dadId: uint32(_dadId),
            generation: uint16(_generation),
        });

        uint256 newKittenId = kitty.push(_kitty) - 1;

        emit Birth(_owner, _newKittenId, _mumId, _dadId, _genes);

        _transfer(address(0)), _owner, newKittenId)
             return newKittenId;

    }
          
    function balanceOf(address owner) external view returns (uint256 balance);
        return ownershipTokenCount [owner];

    
    function totalSupply() public view returns (uint) {
        return creepykitty.length;   
    }
         
    function ownerOf(uint256 tokenId) external view returns (address)
    {
        return kittyIndexToOwner[_tokenId];
    }

    function transfer(address _to, uint256 _tokenId) external 
    {
        require(_to != address(0));
        require(_to != address(this));
        require(_owns(msg.sender, _to, _tokenId));

        _transfer(msg.sender, _to, _tokenId);
    }

    function _transfer(address _from, address _to, uint256 _tokenId) internal {

        ownershipTokenCount[_to]++;

        kittyIndexToOwner[_tokenId] = _to;

        if (_from != address(0)) {
            ownershipTokenCount[_from]--;
        }
        emit transfer(_from,_to, _tokenId);
    }

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

migrations.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Migrations {
  address public owner = msg.sender;
  uint public last_completed_migration; 

  modifier restricted() {
    require(
      msg.sender == owner,
      "This function is restricted to the contract's owner"
    );
  }
  function setCompleted(uint completed) public restricted (
    last_completed_migration = completed;
    )
}

IERC721.sol

pragma solidity ^0.5.0;
/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 {
    /**
     * @dev Emitted when `tokenId` token is transfered from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /*
     * @dev Returns the total number of tokens in circulation.
     */
    function totalSupply() external view returns (uint256 total);

    /*
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory tokenName);

    /*
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory tokenSymbol);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);


     /* @dev Transfers `tokenId` token from `msg.sender` to `to`.
     *
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `to` can not be the contract address.
     * - `tokenId` token must be owned by `msg.sender`.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 tokenId) external;
}

Pics of errors on Visual when trying truffle compile :frowning_face:

Shot 0017 Shot 0018

The issue here is in the brackets, you are sing “( )” when you shold use " { } "
Should be like:

 function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
    }

Hello Guys,

Have a little issue I do not understand, I think it is with ganache.

So code here:

//SPDX-License-Identifier: MIT

pragma solidity 0.8.7;

import "./IERC721.sol";
import "./Ownable.sol";

contract Kittycontract is IERC721, Ownable {


    string public constant tokenName = "RikiKitties";
    string public constant tokenSymbol = "RK";

    uint256 public constant Creation_Limit_Gen = 10;
    uint256 public gencounter = 0;

    event Birth(
        address owner, 
        uint256 kittenId, 
        uint256 mumId, 
        uint256 dadId, 
        uint256 genes);

    struct Kitty {
        uint256 genes;
        uint64 birthTime;
        uint32 mumId;
        uint32 dadId;
        uint16 generation;
    }

    Kitty [] kitties;

    mapping(address => uint256) ownershipTokenCount; // how many token this address has
    mapping(uint256 => address) ownerOfToken; // who owns this token

    function createKittyGen0(uint256 _genes) public onlyOwner returns(uint256){
        //require(gencounter < Creation_Limit_Gen);

        //gencounter++;
        
        return _createKitty(0,0,0,_genes,msg.sender);

    }

    function getKitty(uint256 
    ) public view returns(
        uint256 _mumId,
        uint256 _dadId,
        uint256 _generation,
        uint256 _genes,
        address owner
    ){
    }


    function _createKitty(
        uint256 _mumId,
        uint256 _dadId,
        uint256 _generation,
        uint256 _genes,
        address owner
    ) private returns(uint256){
        Kitty memory _kitty = Kitty({
            genes: _genes,
            birthTime: uint64(block.timestamp),
            mumId: uint32(_mumId),
            dadId: uint32(_dadId),
            generation: uint16(_generation)
        });

       
       
        kitties.push(_kitty);
        uint newKittenId = kitties.length -1;

       _transfer(address(0), owner, newKittenId);

       emit Birth(owner, newKittenId, _mumId, _dadId, _genes);

       return newKittenId;
    }

    function balanceOf(address owner) external override view returns (uint256){
        return ownershipTokenCount[owner];
    }

    function totalSupply() override external view returns (uint256 total){
        return kitties.length;
    }

    function name() external override pure returns (string memory){
        return tokenName;
    }

    function symbol() external override pure returns (string memory){
        return tokenSymbol;
    }

    function ownerOf(uint256 tokenId) external override view returns (address){
        return ownerOfToken[tokenId];
    }

    function transfer(address to, uint256 tokenId) external override {
        require(msg.sender != to, "you cannot send a tokenId to yourself");
        require(msg.sender != address(0),"sender address cannot be 0");
        _own(msg.sender, tokenId);
        
        _transfer(msg.sender, to, tokenId);       
    }

    function _own(address owner, uint256 _tokenId) internal view{
        require(ownerOfToken[_tokenId] == owner);
    }

    function _transfer(address from, address to, uint _tokenId) internal{

        ownerOfToken[_tokenId] = to;

        if(from != address(0)){
            ownershipTokenCount[from]--;
        }      
        ownershipTokenCount[to]++;

        emit Transfer(from, to, _tokenId);
    }

    
}

when I am running truffle and would like to run instance.createKittyGen0(10) or whatever number I add in there I got the following error:

data: {
    '0xf925051658d95a5442dd21056f14261b4a314e2bf9d7b5a195d13a61024717b4': { error: 'revert', program_counter: 1351, return: '0x' },
    stack: 'RuntimeError: VM Exception while processing transaction: revert\n' +
      '    at Function.RuntimeError.fromResults (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\ganache-core\\lib\\utils\\runtimeerror.js:94:1)\n' +
      '    at BlockchainDouble.processBlock (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\ganache-core\\lib\\blockchain_double.js:627:1)\n' +
      '    at runMicrotasks (<anonymous>)\n' +
      '    at processTicksAndRejections (internal/process/task_queues.js:95:5)',
    name: 'RuntimeError'
  },
  hijackedStack: 'Error: Returned error: VM Exception while processing transaction: revert\n' +
    '    at Object.ErrorResponse (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-core-helpers\\lib\\errors.js:28:1)\n' +
    '    at C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3\\node_modules\\web3-core-requestmanager\\lib\\index.js:303:1\n' +
    '    at C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:107:1\n' +
    '    at XMLHttpRequest.request.onreadystatechange (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3\\node_modules\\web3-providers-http\\lib\\index.js:98:1)\n' +
    '    at XMLHttpRequestEventTarget.dispatchEvent (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request-event-target.js:34:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:208:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:318:1)\n' +      
    '    at IncomingMessage.<anonymous> (C:\\Users\\Riki\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:289:47)\n' +
    '    at IncomingMessage.emit (events.js:388:22)\n' +
    '    at IncomingMessage.emit (domain.js:532:15)\n' +
    '    at endReadableNT (internal/streams/readable.js:1336:12)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:82:21)'
}

My suspicion is that it is with ganache but not 100%. Filip told in the beginning in that contract part the he already told us how to run ganache but I do not find a video for that. So I cannot really check my code in this case, can someone lend me a hand?

Thank you.

hey @Riki ! Can you write the command you are using wich produce this error?
If the contract is deployed and you are using the truffe console, this might be because you have to declare the instance first or use await before calling the create function
.

hey @kenn.eth

First I am doing this.

pic1

then I am doing this pic 2

then I am getting the above error.

great! Try await instance.createKittyGen0().
Also make sure that you are using the owner account.
Remember that only the owner of the contract (first account) can create gen0 cats.

I couldn’t compile my contract before I added override to functions. I guess that got to do with the new compiler version?

pragma solidity ^0.8.7;

import "./IERC721.sol";

contract DoggiesContract is IERC721 {

    string public constant override name = "Crypto Doggies";
    string public constant override symbol = "CD";

    struct Doggie{
        uint256 genes;
        uint64 birthTime;
        uint32 mumId;
        uint32 dadId;
        uint16 generation;
    }

    Doggie[] doggies;

    mapping (uint256 => address) public doggieIndexToOwner;
    mapping(address => uint) ownershiptokenCount;

    function balanceOf(address owner) external view override returns (uint256 balance) {
        return ownershiptokenCount[owner];
    }
    
    function totalSupply() external view override returns (uint256 total){
        return doggies.length;
    }

    function ownerOf(uint256 tokenId) external view override returns (address) {
        return doggieIndexToOwner[tokenId];
    }

    /* @dev Transfers `tokenId` token from `msg.sender` to `to`.
     *
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `to` can not be the contract address.
     * - `tokenId` token must be owned by `msg.sender`.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address _to, uint256 _tokenId) external override{
        require(_to != address(0));
        require(_to != address(this));
        require(_owes(msg.sender, _tokenId));

        _transfer(msg.sender, _to, _tokenId);

    }

    function _transfer(address _from, address _to, uint _tokenId) internal {
        ownershiptokenCount[_to]++;
        doggieIndexToOwner[_tokenId] = _to;

        if(_from != address(0)){
            ownershiptokenCount[_from]--;
        }

        emit Transfer(_from, _to, _tokenId);


    }
    
    function _owes(address _claimant, uint _tokenId) internal view returns(bool) {
        doggieIndexToOwner[_tokenId] == _claimant;

    }
}


Microsoft Windows [Version 10.0.19041.1165]
(c) Microsoft Corporation. All rights reserved.

C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2>truffle compile

Compiling your contracts...
===========================
> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\cryptodoggies.sol

/C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.8.7;
^---------------------^
,/C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.8.7;
^---------------------^

Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.8.7".    
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.
Truffle v5.3.7 (core: 5.3.7)
Node v16.2.0

C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2>truffle compile

Compiling your contracts...
===========================
√ Fetching solc version list from solc-bin. Attempt #1
√ Downloading compiler. Attempt #1.
> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\Migrations.sol   
> Compiling .\contracts\cryptodoggies.sol
> Compiling .\contracts\IERC721.sol      

> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol    

,Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol


DeclarationError: Undeclared identifier. Did you mean "_owes"?
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:60:17:
   |
60 |         require(_owns(msg.sender, tokenId));
   |                 ^^^^^

,DeclarationError: Undeclared identifier. Did you mean "_tokenId"?
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:60:35:
   |
60 |         require(_owns(msg.sender, tokenId));
   |                                   ^^^^^^^

Compilation failed. See above.
Truffle v5.3.7 (core: 5.3.7)
Node v16.2.0

C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2>truffle compile

Compiling your contracts...
===========================
> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\cryptodoggies.sol
> Compiling .\contracts\IERC721.sol

> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol    

,Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol


DeclarationError: Event with same name and parameter types defined twice.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:15:5:
   |
15 |     event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Other declaration is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:14:5:
   |
14 |     event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,DeclarationError: Event with same name and parameter types defined twice.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:10:5:
   |
10 |     event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Other declaration is here:
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:9:5:
  |
9 |     event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Overriding function is missing "override" specifier.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:34:5:
   |
34 |     function balanceOf(address owner) external view returns (uint256 balance) {   |     ^ (Relevant source part starts here and spans across multiple lines).      
Note: Overridden function is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:19:5:
   |
19 |     function balanceOf(address owner) external view returns (uint256 balance); 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

,TypeError: Overriding function is missing "override" specifier.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:38:5:
   |
38 |     function totalSupply() external view returns (uint256 total){
   |     ^ (Relevant source part starts here and spans across multiple lines).      
Note: Overridden function is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:24:5:
   |
24 |     function totalSupply() external view returns (uint256 total);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Overriding function is missing "override" specifier.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:42:5:
   |
42 |     function ownerOf(uint256 tokenId) external view returns (address) {        
   |     ^ (Relevant source part starts here and spans across multiple lines).      
Note: Overridden function is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:44:5:
   |
44 |     function ownerOf(uint256 tokenId) external view returns (address owner);   
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   

,TypeError: Overriding function is missing "override" specifier.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:57:5:
   |
57 |     function transfer(address _to, uint256 _tokenId) external{
   |     ^ (Relevant source part starts here and spans across multiple lines).      
Note: Overridden function is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:58:5:
   |
58 |     function transfer(address to, uint256 tokenId) external;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Overriding public state variable is missing "override" specifier.       
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:18:5:
   |
18 |     string public constant name = "Crypto Doggies";
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Overridden public state variable is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:30:5:
   |
30 |     function name() external view returns (string memory tokenName);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Overriding public state variable is missing "override" specifier.       
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:19:5:
   |
19 |     string public constant symbol = "CD";
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Overridden public state variable is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:35:5:
   |
35 |     function symbol() external view returns (string memory tokenSymbol);       
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       

Compilation failed. See above.
Truffle v5.3.7 (core: 5.3.7)
Node v16.2.0

C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2>truffle compile

Compiling your contracts...
===========================
> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\Migrations.sol   
> Compiling .\contracts\cryptodoggies.sol
> Compiling .\contracts\IERC721.sol      

> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol    

,Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol


TypeError: Overriding public state variable is missing "override" specifier.        
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:7:5:
  |
7 |     string public constant name = "Crypto Doggies";
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Overridden public state variable is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:30:5:
   |
30 |     function name() external view returns (string memory tokenName);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Overriding public state variable is missing "override" specifier.       
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:8:5:
  |
8 |     string public constant symbol = "CD";
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Overridden public state variable is here:
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:35:5:
   |
35 |     function symbol() external view returns (string memory tokenSymbol);       
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       

Compilation failed. See above.
Truffle v5.3.7 (core: 5.3.7)
Node v16.2.0

C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2>truffle compile

Compiling your contracts...
===========================
> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\Migrations.sol   
> Compiling .\contracts\cryptodoggies.sol
> Compiling .\contracts\IERC721.sol      
> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol    

,Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol

,Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
  --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:68:76:
   |
68 |     function _owes(address _claimant, uint _tokenId) internal view returns(bool) {
   |                                                                            ^^^^

> Artifacts written to C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2\build\contracts
> Compiled successfully using:
   - solc: 0.8.7+commit.e28d00a7.Emscripten.clang


C:\Users\kamil\Documents\Ethereum-201\Crypto Doggies 2>

hey @Kamil37! Yeah the could be the compiler version, please send a photo or code from your truffle.config file.

Also I notice that there was a lot of code to fix like name duplications.
Make sure you are using the same solidity version like in the Filips tutorials for each file.

hey guys, I had same issue and came up with same solution as CryptoXyz, but may I know what was your solution? Thanks

Hi Kenn thanks for your reply. I did change compiler version cos if I keep old I’m still getting error of compiler and cant migrate my contract

/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * trufflesuite.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura accounts
 * are available for free at: infura.io/register.
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

// const HDWalletProvider = require('@truffle/hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  /**
   * Networks define how you connect to your ethereum client and let you set the
   * defaults web3 uses to send transactions. If you don't specify one truffle
   * will spin up a development blockchain for you on port 9545 when you
   * run `develop` or `test`. You can ask a truffle command to use a specific
   * network from the command line, e.g
   *
   * $ truffle test --network <network-name>
   */

  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
    // development: {
    //  host: "127.0.0.1",     // Localhost (default: none)
    //  port: 8545,            // Standard Ethereum port (default: none)
    //  network_id: "*",       // Any network (default: none)
    // },
    // Another network with more advanced options...
    // advanced: {
    // port: 8777,             // Custom port
    // network_id: 1342,       // Custom network
    // gas: 8500000,           // Gas sent with each transaction (default: ~6700000)
    // gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)
    // from: <address>,        // Account to send txs from (default: accounts[0])
    // websocket: true        // Enable EventEmitter interface for web3 (default: false)
    // },
    // Useful for deploying to a public network.
    // NB: It's important to wrap the provider as a function.
    // ropsten: {
    // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
    // network_id: 3,       // Ropsten's id
    // gas: 5500000,        // Ropsten has a lower block limit than mainnet
    // confirmations: 2,    // # of confs to wait between deployments. (default: 0)
    // timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
    // skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    // },
    // Useful for private networks
    // private: {
    // provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
    // network_id: 2111,   // This network is yours, in the cloud.
    // production: true    // Treats this network as if it was a public net. (default: false)
    // }
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.7",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

  // Truffle DB is currently disabled by default; to enable it, change enabled: false to enabled: true
  //
  // Note: if you migrated your contracts prior to enabling this field in your Truffle project and want
  // those previously migrated contracts available in the .db directory, you will need to run the following:
  // $ truffle migrate --reset --compile-all

  db: {
    enabled: false
  }
};

This is what I get when I change all to version 0.5.12

truffle(develop)> migrate --reset

Compiling your contracts...
===========================
> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\cryptodoggies.sol

ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:1:1:
  |
1 | pragma solidity ^0.5.12;
  | ^^^^^^^^^^^^^^^^^^^^^^^^

,ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:1:1:
  |
1 | pragma solidity ^0.5.12;
  | ^^^^^^^^^^^^^^^^^^^^^^^^


Error: Truffle is currently using solc 0.8.7, but one or more of your contracts specify "pragma solidity ^0.5.12".
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on    
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.

truffle(develop)>

In this case you should use this version all around the project and change the compilier version also to this one. Remember that we should use same version from the videos in order to make it work.

Hi thanks for your reply, I understand what you mean, but what I am trying to say is that when I change a compiler version all around my contracts and also truffle-config.js file I get this error (I think you said in previous reply to someone that this is due to VS sniped and to just ignore it, but I can’t compile my contract with that error so how can I ignore it? is there a way to change that sniped):

> Compiling .\contracts\IERC721.sol
> Compiling .\contracts\cryptodoggies.sol

ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/IERC721.sol:1:1:
  |
1 | pragma solidity ^0.5.12;
  | ^^^^^^^^^^^^^^^^^^^^^^^^

,ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
 --> /C/Users/kamil/Documents/Ethereum-201/Crypto Doggies 2/contracts/cryptodoggies.sol:1:1:
  |
1 | pragma solidity ^0.5.12;
  | ^^^^^^^^^^^^^^^^^^^^^^^^


Error: Truffle is currently using solc 0.8.7, but one or more of your contracts specify "pragma solidity ^0.5.12".
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on    
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.

truffle(develop)>

Here’s my getDoggie funciton:

function getDoggie(uint _doggieId) public view returns(uint, uint64, uint32, uint32, uint16){
        Doggie memory doggieToReturn = doggies[_doggieId];
        return (
            doggieToReturn.genes, 
            doggieToReturn.birthTime, 
            doggieToReturn.mumId, 
            doggieToReturn.dadId, 
            doggieToReturn.generation
            );
    }

this is what I get when calling getDoggie function (looks correct to me, but don’t understand the Time Stamp resoult):

truffle(develop)> instance.getDoggie(0)
Result {
  '0': BN {
    negative: 0,
    words: [ 1002, <1 empty item> ],
    length: 1,
    red: null
  },
  '1': BN {
    negative: 0,
    words: [ 20918362, 24, <1 empty item> ],
    length: 2,
    red: null
  },
  '2': BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  '3': BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  },
  '4': BN {
    negative: 0,
    words: [ 0, <1 empty item> ],
    length: 1,
    red: null
  }
}
truffle(develop)>

I think I am doing that. I just migrate the contract and just doing the await instance.createKittyGen0(whatever number here). and them I am getting the same error. If I don’t change anything isn’t the owner is the account I am using from the start?

Should I upload my contract to github?

Just in case I have done it.

https://github.com/Riki0923/CritpoKitty

For this, you can assign it to a variable and then convert property into readable format.
Example:

let newDog = await instance.getDoggie(0)
newDog[0].toNumber()
//Should result 0 
//OR
newDog[1].toNumber()
//Should return timestamp

1 Like

hey @Riki ! In your github is just the contract folder. I will need the full project with the truffle-config.js file, package.json and migrations folder, in order to run your project with same configuration.
Please upload it to same repo and i will check.