2

Want to implement mappings like this in smartpy :

// Mapping from token ID to owner
mapping (uint256 => address) private _tokenOwner;

// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;

// Mapping from owner to number of owned token
mapping (address => Counters.Counter) private _ownedTokensCount;

// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) private _operatorApprovals;
4

No, you do not need to specify the type of the keys of values. Instead, without needing the declare the map, you simply use it and the types are inferred. To construct a mapping called m, use m = sp.map(...). To access element k, write m[k].

For an example, refer to the FA1.2 template in the SmartPy online IDE.

| improve this answer | |

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.