Assignment - Safetransfer Implementation

Create safeTransferFrom with and without data parameter.

1 Like
Safetransfer Implementation Assignment
 //safeTransferFrom ERC721 Specification, without data
       function safeTransferFrom(address _from, address _to, uint256 _tokenId) public {
           safeTransferFrom(_from, _to, _tokenId, "");
       }
    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes calldata _data) public {
        require(_transferChecks(_from, _to, _tokenId));
        
        //Now handled by _transferChecks
        // require(msg.sender == _from || msg.sender == tokenIdToApproved[_tokenId] || isApprovedForAll(_from, msg.sender), "Only Owner, Operator or Approved Addresses can transfer!");
        // require(_owns(_from, _tokenId), "Owner address is not connected to this token!");
        // require(_to != address(0), "Transfer to zero-address is not possible!");
        // require(_tokenId < bears.length, "This token does not exist!");

        _safeTransfer(_from, _to, _tokenId, _data);
    }
  
    function _safeTransfer(address _from, address _to, uint256 _tokenId, bytes memory _data) internal {
        _transfer(_from, _to, _tokenId);
        require( _checkERC721Support(_from, _to, _tokenId, _data) );
    }

    //Transfers Ownership of a Token
    function transferFrom(address _from, address _to, uint256 _tokenId) external{
        require(_transferChecks(_from, _to, _tokenId));

        //Now handled by _transferChecks
        // require(msg.sender == _from || msg.sender == tokenIdToApproved[_tokenId] || isApprovedForAll(_from, msg.sender), "Only Owner, Operator or Approved Addresses can transfer!");
        // require(_owns(_from, _tokenId), "Owner address is not connected to this token!");
        // require(_to != address(0), "Transfer to zero-address is not possible!");
        // require(_tokenId < bears.length, "This token does not exist!");

        _transfer(_from, _to, _tokenId);
    }
2 Likes