Achieve tokens ERC721 function

First ERC721 criteria:

contract ERC721 {

  event Transfer(address indexed _from, address indexed _to, uint256 _tokenId);

  event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);

  function balanceOf(address _owner) public view returns (uint256 _balance);

  function ownerOf(uint256 _tokenId) public view returns (address _owner);

  function transfer(address _to, uint256 _tokenId) public;

  function approve(address _to, uint256 _tokenId) public;

  function takeOwnership(uint256 _tokenId) public;

}

1. Survey tokens

  balanceOf:

    function balanceOf(address _owner) public view returns(uint256 _balance)

    // This function is passed the address of the function parameter and returns the number of tokens

  ownerOf:

    function ownerOf(uint256 _tokenId) public view returns(address _owner);

    // incoming tokens (token) of the ID and return address of the owner

2. Transfer tokens:

  ERC721 There are three functions on the transfer of tokens:

Method One: Direct Transfer

  function transfer(address _to,uint256 _tokenId) public;

    I would like to transfer the tokens _tokenId transferred to _to address

Method Two:

function approve(address _to,uint256 _tokenId) public;

function takeOwnership(uint256 _tokenId) public;

  Token owner to call approve, after passing the same parameters, the contract will be allowed to mention the store who replaced coins,

Then stored in a mapping (uint256 => address), and then when you call takeOwnershi contract will check msg.sender

See if there is approval to raise money to replace.

Here the use of private functions to achieve their own convenient method to use //

function _transfer(address _from, address _to, uint256 _tokenId) private {
ownerZombieCount[_to]++;
ownerZombieCount[_from]--;
zombieToOwner[_tokenId] = _to;
Transfer(_from, _to, _tokenId);
Then modify the transfer function of the content, just use _transfer in transfei on the line
}
 
  Achieve approval approve functions:
  step:
    1, as the owner, and deal with _tokenId address new owner to approve call
    2. recipients to get tokens by takeOwnership
     // between the two requires a data structure to store what people get what tokens are approved

  First create a map to make finding tokens and the corresponding address of the person, then transfer the same event which also requires the listener ERC721

  Then implemented takeOwnership function for detecting whether or not approved to ensure msg.sender substituted put coins, after confirmation function is to use _transfer

To extract 

Guess you like

Origin www.cnblogs.com/beautiful7/p/12422965.html