0

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?

0

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.

| improve this answer | |
  • 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? – user3316323 Jul 5 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. – Rob Hitchens Jul 5 at 18:10
  • Thank you @Rob Hitchens, that does make sense if the caller has their own account linked to the calls – user3316323 Jul 6 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. – Rob Hitchens Jul 6 at 19:46

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.