1

I'm trying to fully comprehend what is going on in a standard ERC721 token.
But this statement is really tripping me up:

// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) internal operatorApprovals;

Like what is a good way to think about a mapping of a mapping,

Like could someone please give me a minimalist example of why this is a useful data structure?

1

You can see the mappings as a sort of an array where the key can be any type (instead of just a numerical index) like the associative arrays in PHP or the Hashtable in C#. And two nested mappings just provide you another level with the same feature.

So to use that mapping in this way

operatorApprovals[owner_address][operator_address] 

to get the bool value

operatorApprovals[owner_address]

will only give you the other mapping which can contains multiple operators. Keys are unique. Check the Solidity doc for more info

1
  • 1
    Great explanation. I think it finally clicked for me. – John DeBord May 11 '18 at 6:45

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.