πͺ§Ethereum Addresses
Ethereum Addresses
Ethereum addresses are 40 hexadecimal characters long, excluding the "0x" prefix. This makes each address 20 bytes (160 bits) in length.
20 Bytes Long: An Ethereum address is derived from the last 20 bytes of the Keccak-256 hash of the public key.
160 Bits: This length provides a vast address space, which helps avoid address collisions and enhances security.
How to get a Private Key
When you got your first Ethereum address, you mostly likely used a tool like MetaMask or a Ledger which gave you a Seed Phrase
. But that Seed Phrase
is a string of 12-24 words, so how does that relate to your address?
twin galaxy such vague current rhythm about laundry upset fatigue fragile whisper
The specific words chosen matter, and the details of how they work can be found here:
A single Seed Phrase
can be used to generate a nearly infinite number of Ethereum addresses. Those addresses are generated using a specific hierarchical deterministic derivation path explained in great detail here.
Step-by-Step Example
Seed Phrase
twin galaxy such vague current rhythm about laundry upset fatigue fragile whisper
Private Key Base 2 (Binary)
1010011111101000000011001001111010101100011110010111100010000101110010101101100011010110101111011111101010100110011000111110000100101111100100011101110101100100001110101100000000011111111100111000111001010010111110011100110000110101110010010010010100011011
Private Key Hexadecimal
0xa7e80c9eac797885cad8d6bdfaa663e12f91dd643ac01ff38e52f9cc35c9251b
Generate a Private Key. This is a random 256-bit number. For simplicity, let's use a hexadecimal representation:
0xa7e80c9eac797885cad8d6bdfaa663e12f91dd643ac01ff38e52f9cc35c9251b
Generate the Public Key. The public key is derived from the private key using Elliptic Curve Cryptography (ECC), specifically the secp256k1 curve. The resulting public key is a 512-bit number (128 hexadecimal characters):
wallet = new ethers.Wallet(privateKey);
publicKey = wallet.signingKey.publicKey;
0x04f743d6226bab9de56e067f068371bbe1967ab0f8b32c86b0360f5c9a8dfd3fd03994f9babf7b5efcec75c78f9efa4668df930da585b1d57b8c2b4f7de5a6849d
Keccak-256 Hash of the Public Key. Ethereum uses the Keccak-256 hash function (a variant of SHA-3) to hash the public key. Note that only the x and y coordinates of the public key (excluding the initial '0x04' byte) are hashed.
// Slice the `0x04` from the start of the publicKey
const publicKeyFormatted = '0x' + publicKey.slice(4);
// Convert the public key to a byte array using ethers.getBytes.
const publicKeyBytes = ethers.getBytes(publicKeyFormatted);
// Perform Keccak-256 hash of the public key
const publicKeyHash = ethers.keccak256(publicKeyBytes);
0xf743d6226bab9de56e067f068371bbe1967ab0f8b32c86b0360f5c9a8dfd3fd03994f9babf7b5efcec75c78f9efa4668df930da585b1d57b8c2b4f7de5a6849d
0x624d10d9dd0d1f68800320293872e96f79890737fcf74aa85d6d760a5a451fe9
Ethereum Address. The Ethereum address is derived from the last 20 bytes of the Keccak-256 hash.
const ethereumAddress = wallet.address
0x3872E96F79890737fCf74aa85D6d760a5a451Fe9
Last updated