The Detailed Process of Generating an Ethereum Address from a Public Key

·

Note: This article clarifies the exact steps to derive an Ethereum address from a public key, addressing common misconceptions and providing a verified implementation.

Understanding Ethereum Address Generation

Many resources explain how ECDSA (Elliptic Curve Digital Signature Algorithm) generates Ethereum key pairs, but few detail the precise hashing process involved in converting a public key to an address. This guide demystifies the workflow and corrects prevalent inaccuracies.

Why Accuracy Matters

A popular Zhihu article claimed to demonstrate the process but yielded incorrect results—highlighting the need for precision. Here’s the verified method.


Step-by-Step Address Generation

1. Public Key Preparation

2. Keccak-256 Hashing

3. Extract the Address


Verified Implementation (Node.js)

const { ethers, utils } = require("ethers");
const sha3 = require("js-sha3");

// Sample Private Key
const private_key = "18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725";
const wallet = new ethers.Wallet(private_key);

// Step 1: Remove '04' prefix
let publicKey = wallet.publicKey.substring(4);

// Step 2: Convert to byte array
let bytes = utils.arrayify("0x" + publicKey);

// Step 3: Keccak-256 hash
let hash = sha3.keccak_256(bytes);

// Step 4: Last 40 chars = address
let address = "0x" + hash.substring(24);
address = utils.getAddress(address); // Checksum

console.log(address === wallet.address); // true

Key Takeaways

  1. Prefix Removal: Ignoring the 04 prefix before hashing is critical.
  2. Byte Conversion: Hashing requires a byte array, not the raw hex string.
  3. Testing: Always verify against trusted tools like ethers.js.

FAQ

Q1: Why does the address start with ‘0x’?

A: 0x denotes hexadecimal format, standard for Ethereum addresses.

Q2: What’s the purpose of the checksum?

A: EIP-55 checksums prevent typos by mixing letter cases based on hash bits.

Q3: Can I use compressed public keys?

A: Yes, but uncompressed keys (04-prefixed) are more common in Ethereum.

👉 Explore Ethereum key formats.


Conclusion

Generating an Ethereum address correctly hinges on precise hashing steps. This guide eliminates ambiguities—ensuring your implementations match blockchain standards. For further reading, consult Ethereum’s official docs.