Function declaration

Hi All,

I have an issue with this function:

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);

       uint256 newKittenId = kitties.length -1;

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

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

       return newKittenId;

           }

It is saying that mumId and dadId does not match function declaration.

Can someone help me out?

Thank you.

Here is the full code:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

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

contract Kittycontract is IERC721, Ownable {

    string public constant override name = "FilipKitties";
    string public constant  override symbol = "FK";

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


    struct Kitty {
        uint genes;
        uint birthTime;
        uint mumID;
        uint dadID;
        uint generation;
    }

    Kitty [] kitties;

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

    function createKittyGen0(uint256 _genes) public onlyOwner returns(uint256) {
        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(block.timestamp),
            mumId: uint32(_mumId),
            dadId: uint32(_dadId),
            generation: uint16(_generation)
        });

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

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

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

       return newKittenId;
           }


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

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

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

    function transfer(address to, uint256 tokenId) external override {
        require(address(this)!= to);
        require(address(0)!= to);
        require(_owns(msg.sender, tokenId));
        _transfer(msg.sender, to, tokenId);
    }
    function _owns(address _claimant, uint256 _tokenId) internal view returns(bool){
        return kittyIndexToOwner[_tokenId] == _claimant;
    }
    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);
    }
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
 * @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;
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;


contract Ownable {

    address owner;

    modifier onlyOwner(){
        require(owner == msg.sender);
        _;
    }
}

I think the struct declaration is wrong.

    struct Kitty {
        uint genes;
        uint birthTime;
        uint mumID;
        uint dadID;
        uint generation;
    }

but in the function,

        Kitty memory _kitty = Kitty({
            genes: _genes,
            birthTime: uint64(block.timestamp),
            mumId: uint32(_mumId),
            dadId: uint32(_dadId),
            generation: uint16(_generation)
        });

Hope this helps :slight_smile:

2 Likes

Ahh, how easy to miss these things…

Thank you!

3 Likes