0

I want to make some extension to the ERC721.

Per example, set some tokens as "requestable" (anyone can request it), if the requester know the "key" of each token

So, I added a mapping with string for each token.

  // Mapping is token transferable knowing the tokenkey
  mapping (uint256 => bytes32) public encryptedTokenKey; 

The standard function is

 function transferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) {
    require(_from != address(0));
    require(_to != address(0));

    clearApproval(_from, _tokenId);
    removeTokenFrom(_from, _tokenId);
    addTokenTo(_to, _tokenId);

    emit Transfer(_from, _to, _tokenId);
  }

I thought to change "canTransfer" but in that case I need to add a "secretkey" param, so it changes everything, everywhere ...

  modifier canTransfer(uint256 _tokenId) {
    require(isApprovedOrOwner(msg.sender, _tokenId));
    _;

  }

I though of something like this :

  /**
   * @dev Checks msg.sender can transfer a token, by being owner, approved, operator or having the tokenkey
   * @param _tokenId uint256 ID of the token to validate
   */
  modifier canTransfer(uint256 _tokenId) {
    require(isApprovedOrOwner(msg.sender, _tokenId)||keccak256(msg.tokenKey) == encryptedTokenKey[_tokenId]);
    _;
  }

With msg.tokenKey set in the call, prior to call "transferFrom", but of course it does not work :)

What is the way to implement it without changing everything ?

Is it to write a transferFromWithSecret function ? And so rewrite all corresponding function ?

I search for the best way to implement it without breaking the ERC721 standard

Thanks in advance !

1

If you change the function interface, you will break the standard. You can simply add a new function to accomplish what you want. In other words, the standard is the standard. Tools that depend on the standard interfaces won't work if you change the interfaces to the standard functions. It's truely as simple as that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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