0

I have been following a course, and, I followed their code, somehow, when I compile my code, it gave me an error, and the course I followed didn't get an error, somebody help me please.

pragma solidity ^0.8.7;


import './ERC165.sol';
import './IERC721.sol';

contract ERC721 is ERC165, IERC721 {

        function ownerOf(uint256 _tokenId) public override view returns (address) {
            address owner = _tokenOwner[_tokenId];
            require(owner != address(0), 'owner query for non-existent token');
            return owner;
        }

    // mapping in solidity creates a hash table of key pair values

    // Mapping from token id to the owner
    mapping(uint => address) private _tokenOwner;


    // Mapping from owner to number of owned tokens
    mapping(address => uint256) private _OwnedTokensCount;

    mapping(uint256 => address) private _tokenApprovals;

    constructor() {
        _registerInterface(bytes4(keccak256('balanceOf(bytes4)')^
        keccak256('ownerOf(bytes4)')^keccak256('transferFrom(bytes4)')));
    }

    function balanceOf(address _owner) public override view returns (uint256) {
        require(_owner != address(0), 'owner query for non-existant token');
        return _OwnedTokensCount[_owner];
    }
    
    function _exists(uint256 tokenId) internal view returns(bool) {
       // setting the address of nft owner to check the mapping
       // of the address from tokenOwner at the tokenId
       address owner = _tokenOwner[tokenId]; 
       // return truthiness tha address is not zero
       return owner != address(0);
    }



    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), 'ERC721: minting to the zero address');
        require(!_exists(tokenId), 'ERC721: token already minted');
        _tokenOwner[tokenId] = to;
        _OwnedTokensCount[to] += 1;

        emit Transfer(address(0), to, tokenId);
    }

    function _transferFrom(address _from, address _to, uint256 _tokenId) external payable
    {
        require(_to != address(0), 'Error - ERC721 transfer to the zero address');
        require(ownerOf(_tokenId) == _from, 'Trying to transfer a token the address does not own!');

        _OwnedTokensCount[_from] -= 1;
        _OwnedTokensCount[_from] += 1;
        
        _tokenOwner[_tokenId] = _to;

        emit Transfer(_from, _to, _tokenId);
    }


    function transferFrom(address _from, address _to, uint256 _tokenId) override public {
        require(msg.sender, _tokenId);
        transferFrom(_from, _to, _tokenId);
    }

    function approve(address _to, uint256 tokenId) public {
        address owner = ownerOf(tokenId);
        require(_to != owner, 'Error - approval to current owner');
        require(msg.sender == owner, 'Current caller is not the owner of the token');
        _tokenApprovals[tokenId] = _to;
        emit Approval(owner, _to, tokenId);
    }
}

the error was on the function called transferfrom it gave me an error saying [1]: https://i.sstatic.net/m3Eio.png

please help me, I've been stuck here for an hour, I don't know what to do.

2
  • What do you mean by this: require(msg.sender, _tokenId); ? Commented Jul 15, 2022 at 6:21
  • what do you mean by that?
    – Korumaq1xa
    Commented Jul 15, 2022 at 6:34

1 Answer 1

1

This code is wrong:

function transferFrom(address _from, address _to, uint256 _tokenId) override public {
        require(msg.sender, _tokenId);
        transferFrom(_from, _to, _tokenId);
}

should be:

function transferFrom(address _from, address _to, uint256 _tokenId) override public {
    require(msg.sender == _tokenOwner[_tokenId]," Error, not the owner"); 
    transferFrom(_from, _to, _tokenId);
}

There should be judgment in require, you can change it to other

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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