Signers
These classes abstract away the private key, as opposed to eth_account.account.Account,
which explicitly requires the private key on each usage.
All the signer classes in this package must meet the
interface specified by BaseAccount.
Currently there is only one Local Signer. Some upcoming alternatives to the basic local signer include hierarchical deterministic (HD) wallets and hardware wallets.
Local Signer
- class eth_account.signers.local.LocalAccount(key: PrivateKey, account: AccountLocalActions)
Bases:
BaseAccountA collection of convenience methods to sign and encrypt, with an embedded private key.
- Variables:
key (bytes) – the 32-byte private key data
>>> my_local_account.address "0xF0109fC8DF283027b6285cc889F5aA624EaC1F55" >>> my_local_account.key b"\x01\x23..."
You can also get the private key by casting the account to
bytes:>>> bytes(my_local_account) b"\\x01\\x23..."
- property address: ChecksumAddress
The checksummed public address for this account.
>>> my_account.address "0xF0109fC8DF283027b6285cc889F5aA624EaC1F55"
- encrypt(password: str, kdf: Literal['pbkdf2', 'scrypt'] | None = None, iterations: int | None = None) Dict[str, Any]
Generate a string with the encrypted key.
This uses the same structure as in
encrypt(), but without a private key argument.
- sign_message(signable_message: SignableMessage) SignedMessage
Generate a string with the encrypted key.
This uses the same structure as in
sign_message(), but without a private key argument.
- sign_transaction(transaction_dict: Dict[str, Sequence[Dict[str, HexStr | Sequence[HexStr]]] | bytes | HexStr | int], blobs: Sequence[bytes | HexBytes] | None = None) SignedTransaction
Sign a transaction dict.
This uses the same structure as in
sign_transaction()but without specifying the private key.- Parameters:
transaction_dict (dict) – transaction with all fields specified
- unsafe_sign_hash(message_hash: Hash32) SignedMessage
Sign the hash of a message.
Warning
Never sign a hash that you didn’t generate, it can be an arbitrary transaction. For example, it might send all of your account’s ether to an attacker. Instead, prefer
sign_message(), which cannot accidentally sign a transaction.This uses the same structure as in
unsafe_sign_hash()but without specifying the private key.- Parameters:
message_hash (bytes) – 32 byte hash of the message to sign
Abstract Signer
- class eth_account.signers.base.BaseAccount
Bases:
ABCSpecify convenience methods to sign transactions and message hashes.
- abstract property address: ChecksumAddress
The checksummed public address for this account.
>>> my_account.address "0xF0109fC8DF283027b6285cc889F5aA624EaC1F55"
- abstract sign_message(signable_message: SignableMessage) SignedMessage
Sign the EIP-191 message.
This uses the same structure as in
sign_message()but without specifying the private key.- Parameters:
signable_message – The encoded message, ready for signing
- abstract sign_transaction(transaction_dict: Dict[str, Sequence[Dict[str, HexStr | Sequence[HexStr]]] | bytes | HexStr | int]) SignedTransaction
Sign a transaction dict.
This uses the same structure as in
sign_transaction()but without specifying the private key.- Parameters:
transaction_dict (dict) – transaction with all fields specified
- abstract unsafe_sign_hash(message_hash: Hash32) SignedMessage
Sign the hash of a message.
Warning
Never sign a hash that you didn’t generate, it can be an arbitrary transaction. For example, it might send all of your account’s ether to an attacker. Instead, prefer
sign_message(), which cannot accidentally sign a transaction.This uses the same structure as in
unsafe_sign_hash()but without specifying the private key.- Parameters:
message_hash (bytes) – 32 byte hash of the message to sign