Try it Live
Run Address examples in the interactive playground
Factory API
For tree-shakeable, crypto-agnostic implementation, use the factory function:keccak256- For hashing the public keyderivePublicKey- For deriving public key from private key
Standard API
The standard API automatically injects crypto dependencies:C FFI
The C API does not currently exposefromPrivateKey directly. To derive addresses from private keys in C, use the crypto library’s secp256k1 functions to derive the public key first, then use primitives_address_from_public_key.
Example workflow:
- Using the crypto library directly for secp256k1 operations
- Computing keccak256 hash of the derived public key
- Extracting the last 20 bytes for the address
Algorithm
The address derivation follows this process:- Derive public key - Multiply generator point G by private key scalar
- Extract coordinates - Get x and y coordinates from resulting point
- Hash public key - Compute keccak256(x || y)
- Extract address - Take last 20 bytes of hash
Private Key Requirements
Size: Exactly 32 bytes (256 bits) Valid range:1 to n-1 where n is the secp256k1 curve order:
- All zeros (0x0000…0000)
- Greater than or equal to curve order
Security Considerations
Best practices:- Generate from cryptographically secure random source
- Never reuse across different accounts/networks
- Store encrypted at rest
- Use hardware wallets for high-value keys
- Implement key rotation policies
Complete Example
Use Cases
Wallet Generation
Generate new Ethereum accounts:Key Import
Import existing private keys:HD Wallets
Derive addresses from HD wallet private keys:Performance
Cryptographic operations:- secp256k1 scalar multiplication (public key derivation)
- keccak256 hash function
- secp256k1 implementation (~15-20 KB)
- keccak256 implementation (~5-10 KB)
Error Handling
See Also
- fromPublicKey - Derive from public key coordinates
- from - Universal constructor
- Secp256k1 - secp256k1 cryptography
- Keccak256 - Keccak256 hash function
- Yellow Paper - Section 4.2 (Address derivation)

