Isa Hassan ⚡ pfp
Isa Hassan ⚡
@totheapex
Day 4: Token Transfer and Safe Transfer_ ``` contract MyERC721 is SafeERC721 { // ... function transferFrom(address from, address to, uint256 tokenId) public { // Check if the token exists require(_exists(tokenId), "Token does not exist");
3 replies
0 recast
0 reaction

Isa Hassan ⚡ pfp
Isa Hassan ⚡
@totheapex
The code explain in diagram below.
0 reply
0 recast
0 reaction

Isa Hassan ⚡ pfp
Isa Hassan ⚡
@totheapex
function safeTransferFrom(address from, address to, uint256 tokenId) public { transferFrom(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, ""), "Safe transfer failed"); } }
0 reply
0 recast
0 reaction

Isa Hassan ⚡ pfp
Isa Hassan ⚡
@totheapex
// Check if the from address is the owner of the token require(ownerOf(tokenId) == from, "From address is not the owner"); // Check if the to address is a valid address require(to != address(0), "Invalid to address"); // Transfer the token _transferFrom(from, to, tokenId); }
0 reply
0 recast
0 reaction