1

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 ?

7
  • 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.)
    – user19510
    Feb 13, 2018 at 19:28
  • I need to generate public/private key pair for a smart contract. Is it possible? Feb 13, 2018 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?
    – user19510
    Feb 13, 2018 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 ? Feb 13, 2018 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. :-)
    – user19510
    Feb 13, 2018 at 19:50

1 Answer 1

1

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.