3

This question already has an answer here:

I am trying to create a user database with solidity and ethereum blockchain.

i have a super user who needs to add other users using their address as a unique identifier. The address is not passed through msg.sender so how can i know if it really exists or not? ?

marked as duplicate by Richard Horrocks, Achala Dissanayake, Roman Frolov, Ismael, flygoing Feb 15 '18 at 15:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What is meant by Super user? In Eth? – Jitendra Kumar. Balla Feb 14 '18 at 15:02
  • Super user is just a type that i invented to say that the account calling the adduser method is different from the one that i am trying to add. – Kaki Master Of Time Feb 14 '18 at 15:04
2

As noted in linked question all addresses exist.

If you want to know if for a given address a private key exists (e.g. this address can send transactions) you can have the method register() which is supposed to be called by normal users. This method will store msg.sender to the registeredAddresses mapping.

Another method approve(address addr) is supposed to be called by the super user and it will put the address to approvedAddresses mapping, after checking the addr exists in the registeredAddresses mapping. The fact that this address is in registeredAddresses means that someone must own the private key for this address.

This of course imposes the gas cost that users will need to pay for calling register(). Instead you can also do it off-chain, just ask the address that you need to add to the database to sign some random message with their private key then check it against the address with ecrecover.

  • So, from what i understand from your answer is that, calling register() on an address( e.g. can send transactions ) will prove by the the returned value of the method register() that this address is genuin or not, right ? – Kaki Master Of Time Feb 15 '18 at 8:10
  • So, from what i understand from your answer is that, i can't really know wether some address has a private key behind untill it actually calls a method from my contract. so what you stated is just a workaround. Thank you, i am implementing it. – Kaki Master Of Time Feb 15 '18 at 8:56
  • 1
    "can't really know wether some address has a private key behind untill it actually calls a method from my contract." yes that's correct. The workaround is to require users to send you a signed message off-chain. You can then verify the signature on-chain when registering users. This way all registered users in your smart contract are guaranteed to have private keys and there needs to be only a single transaction instead of 2. – medvedev1088 Feb 15 '18 at 9:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.