From an end user standpoint, they will never want to use the address for searching for mapped data when they could just submit a username for function parameters, so is there any specific reason why it would be better to use an address?

1 Answer 1


Your premise includes a whole bunch of odd assumptions but it isn't exactly clear what you are thinking or why you are thinking it.

they will never want to use the address for searching f

It's not necessarily about what a user would want to do. Contracts are about what the system must do. mappings are about internal organization so it "can do" it efficiently.

There are lots of reasons to use an address ("the" user or "a" user) as a unique identifier. It's natural, for example, to use it if the information is about users. For example, a user balance:

mapping(address => user) userBalances;

If the contract has a collection of properties of each user, maybe:

mapping(address => UserProfile) userProfiles; where UserProfile is a struct with several members.

Hope it helps.

  • I see it like this, if I have to have an identifier to link the end user with the address, then why use the address middleman at all? If I do it for the unique Identifier, what way would be best to link the username to the address? Jul 5, 2020 at 13:00
  • You use mappings for random access and arrays to enumerate members. Since you already have authenticated unique ids (msg.sender), you are making harder on yourself by thinking of user id as something other than their address. Jul 5, 2020 at 18:10
  • Thank you @Rob Hitchens, that does make sense if the caller has their own account linked to the calls Jul 6, 2020 at 15:30
  • Yes, msg.sender is always "authenticated." If the query is from someone else, it still makes sense to use this protocol level identifier. Jul 6, 2020 at 19:46

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.