1

MyContract is ERC721

I want to adapt the _update function to a specific usecase.

In order to keep its core functionality, the adapted function needs to write into _owners, _balances and _tokenApprovals.

Could someone please show me the way?

2
  • 1
    It would be helpful to see the code you have implemented to this point. Commented Aug 14, 2023 at 8:53
  • please see the post below. i apologize the time delay
    – PupSt4r
    Commented Jun 7 at 5:53

1 Answer 1

-1

I copy pasted the code of ERC721.sol into the file of my custom contract and manually set the above mentioned mappings from private to internal (within the ERC721 code).

 // Mapping from token ID to owner address
    mapping(uint256 => address) internal _owners;

 // Mapping owner address to token count
  mapping(address => uint256) internal _balances;

Now I can access the variables directly. For example like this:

function _update_(address to, uint256 tokenId) internal returns (bool){  

address from = _ownerOf(tokenId);
        
unchecked {
_balances[from] -= 1;  // 
        
_balances[to] += 1; //

_owners[tokenId] = to;

}
emit Transfer(from, to, tokenId);
return true;

}

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.