eth-account: Ethereum Account Management

0.13.7 · active · verified Thu Apr 09

eth-account is a Python library for managing Ethereum private keys and signing transactions and messages locally, without requiring a connection to an Ethereum node. It provides functionality for creating accounts, signing raw transactions, and signing messages (EIP-191 and EIP-712). It is a core component of web3.py. The current stable version is 0.13.7, released on April 21, 2025. The library is actively maintained with frequent releases, often on a monthly or bi-monthly basis for bugfixes and features. [1, 8, 15]

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a new Ethereum account (generating a private key locally) and then sign a plain text message using that account. It also shows how to recover the signer's address from the signed message to verify the signature. [1, 3]

from eth_account import Account
from eth_account.messages import encode_defunct
import os

# 1. Create a new account (generates a private key)
private_key_bytes = Account.create()._private_key
account = Account.from_key(private_key_bytes)

print(f"New Account Address: {account.address}")

# 2. Sign a message
msg_text = "Hello, Ethereum!"
message = encode_defunct(text=msg_text.encode('utf-8'))
signed_message = account.sign_message(message)

print(f"Signed Message Hash: {signed_message.messageHash.hex()}")
print(f"Signature: {signed_message.signature.hex()}")

# 3. Verify the signature
recovered_address = Account.recover_message(message, signature=signed_message.signature)
print(f"Recovered Address: {recovered_address}")
assert recovered_address == account.address
print("Signature verification successful!")

view raw JSON →