0

This question already has an answer here:

I am new at ethereum.

I've been reading the white paper and it says that the smart contracts have public keys, but I found nothing on how to get them.

So my question is how to get a smart contract's public key in code ? and is it possible for it to generate one ?

marked as duplicate by Ismael, Achala Dissanayake, Roman Frolov, flygoing, manuhalo Feb 15 '18 at 15:44

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.

  • Could you explain what you're trying to do? Smart contracts have addresses which are derived from the hash of the account that deployed the contract and that account's nonce. An account isn't exactly the same thing as a public key. (Notably, it's not derived from a corresponding private key.) – smarx Feb 13 '18 at 19:28
  • I need to generate public/private key pair for a smart contract. Is it possible? – M. Dhaouadi Feb 13 '18 at 19:37
  • You can generate all the key pairs you want, and you can store arbitrary data in smart contracts. BUT, I think this may be an instance of the XY problem. Can you explain your actual goal? – smarx Feb 13 '18 at 19:39
  • I'm working on e-voting project, I need the smart contract to have private/public keys for cryptographic reasons. I have searched the solidity docs, but with no luck. how can I generate the pair in solidity ? – M. Dhaouadi Feb 13 '18 at 19:45
  • Could you explain the "cryptographic reasons?" Note that everything in a contract is public, so it can't secure a private key (e.g. for decryption). If the contract needs to verify the identity of a voter, the easiest thing to do is store the address of the voter in the contract and check the address that sent the vote transaction (msg.sender). If it's something else, please explain. :-) – smarx Feb 13 '18 at 19:50
0

Contracts do not have public keys, and the whitepaper doesn't say they do.

Contracts have addresses. Contract addresses are derived from the address of the user (or other contract) that created them. These in turn are derived from the public key of a normal user's keypair.

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