25

I'm creating an ethereum wallet and I'm a bit confused with the concept of public key vs address. I understand that the Address is a hashed version of the public key, but when I'm generating a new wallet, I have 3 data fields: private key (used to sign a transaction), Address (used to receive a transaction), Public Key (???)

What is the practical use of the public key?

sigmaxf
  • 1,080
  • 2
  • 13
  • 21

4 Answers4

16

When you are creating a new wallet, what you are doing is creating an account. Every account has a private key and a public key, and are indexed by an address that is where you send the transaction.

The address is the last 20 bytes of the hash of the public key.

According to the documentation:

Every account is defined by a pair of keys, a private key and public key. Accounts are indexed by their address which is derived from the public key by taking the last 20 bytes. Every private key/address pair is encoded in a keyfile.

http://ethdocs.org/en/latest/account-management.html?highlight=address#keyfiles

You can find this post useful:

https://kobl.one/blog/create-full-ethereum-keypair-and-address/

Hope this helps.

Vignesh Karthikeyan
  • 1,950
  • 1
  • 12
  • 40
14

No specific usecase of public key, As usually one can ask for public key(address) that means informally we sometimes say public key despite of address.

An Ethereum address represents an account. For external owned accounts, the address is derived as the last 20 bytes of the public key controlling the account, e.g., cd2a3d9f938e13cd947ec0i8um67fe734df8d8861. This is a hexadecimal format (base 16 notation), which is often indicated explicitly by prepending 0x to the address. Since each byte of the address is represented by 2 hex characters, a prefixed address is 42 characters long.

Read more: Accounts, Addresses, Public And Private Keys, And Tokens

Thakur
  • 347
  • 3
  • 3
  • 4
    Well, transactions are signed by that user's private key, so the miners need to have access to the matching public key to be able to verify the transaction signatures. There's your use case :) – Xenonite Feb 15 '21 at 11:55
11

Ethereum security model relies on elliptic curve cryptography (ECC) to sign and validate transactions.

In ECC public and private key are used to sign and verify. It has no concept of addresses. When signing and verifying transactions you do not need addresses.

The original bitcoin paper do not mention addresses at all. They appear later in an effort to make them easier to remember (compressed public key are 32 bytes vs address 20 bytes).

Now you can completely hide public key from the user interaction and only have private key and addresses. But internaly ethereum keeps using them to validate transactions.

Ismael
  • 30,570
  • 21
  • 53
  • 96
6

I believe there is no practical use of the public key. Because of this, in most account creation tools, the public key is never even displayed to the user.

(You could use the public key to encrypt a message such that only the private key holder can decrypt it, but this isn't typically done in Ethereum.)

user19510
  • 27,999
  • 2
  • 30
  • 48