ape-accounts
- class ape_accounts.accounts.AccountContainer(*, name: str, account_type: type[AccountAPI], loaded_accounts: dict[str, KeyfileAccount] = {})
- property accounts: Iterator[AccountAPI]
All accounts.
- Returns:
Iterator[
AccountAPI
]
- property aliases: Iterator[str]
All available aliases.
- Returns:
Iterator[str]
- exception ape_accounts.accounts.InvalidPasswordError
Raised when password to unlock an account is incorrect.
- class ape_accounts.accounts.KeyfileAccount(*, keyfile_path: Path, locked: bool = True)
- property address: AddressType
The address of this account. Subclasses must override and provide this value.
- property alias: str
A shortened-name for quicker access to the account.
- set_autosign(enabled: bool, passphrase: str | None = None)
Allow this account to automatically sign messages and transactions.
- Parameters:
enabled (bool) –
True
to enable,False
to disable.passphrase (Optional[str]) – Optionally provide the passphrase. If not provided, you will be prompted to enter it.
- sign_message(msg: Any, **signer_options) MessageSignature | None
Sign a message.
- Parameters:
msg (Any) – The message to sign. Account plugins can handle various types of messages. For example,
KeyfileAccount
can handleSignableMessage
, str, int, and bytes. See these docs # noqa: E501 for more type information on theSignableMessage
type.**signer_options – Additional kwargs given to the signer to modify the signing operation.
- Returns:
The signature corresponding to the message.
- Return type:
MessageSignature
(optional)
- sign_raw_msghash(msghash: HexBytes) MessageSignature | None
Sign a raw message hash.
- Parameters:
msghash (
HexBytes
) – The message hash to sign. Plugins may or may not support this operation. Default implementation is to raiseNotImplementedError
.- Returns:
The signature corresponding to the message.
- Return type:
MessageSignature
(optional)
- sign_transaction(txn: TransactionAPI, **signer_options) TransactionAPI | None
Sign a transaction.
- Parameters:
txn (
TransactionAPI
) – The transaction to sign.**signer_options – Additional kwargs given to the signer to modify the signing operation.
- Returns:
- A signed transaction.
The
TransactionAPI
returned by this method may not correspond totxn
given as input, however returning a properly-formatted transaction here is meant to be executed. ReturnsNone
if the account does not have a transaction it wishes to execute.
- Return type:
TransactionAPI
(optional)
- ape_accounts.accounts.generate_account(alias: str, passphrase: str, hd_path: str = "m/44'/60'/0'/0/0", word_count: int = 12) tuple[KeyfileAccount, str]
Generate a new account.
- Parameters:
alias (str) – The alias name of the account.
passphrase (str) – Passphrase used to encrypt the account storage file.
hd_path (str) – The hierarchal deterministic path to use when generating the account. Defaults to m/44’/60’/0’/0/0.
word_count (int) – The amount of words to use in the generated mnemonic.
- Returns:
Tuple of
KeyfileAccount
and mnemonic for the generated account.
- ape_accounts.accounts.import_account_from_mnemonic(alias: str, passphrase: str, mnemonic: str, hd_path: str = "m/44'/60'/0'/0/0") KeyfileAccount
Import a new account from a mnemonic seed phrase.
- Parameters:
alias (str) – The alias name of the account.
passphrase (str) – Passphrase used to encrypt the account storage file.
mnemonic (str) – List of space-separated words representing the mnemonic seed phrase.
hd_path (str) – The hierarchal deterministic path to use when generating the account. Defaults to m/44’/60’/0’/0/0.
- Returns:
Tuple of AccountAPI and mnemonic for the generated account.
- ape_accounts.accounts.import_account_from_private_key(alias: str, passphrase: str, private_key: str) KeyfileAccount
Import a new account from a mnemonic seed phrase.
- Parameters:
alias (str) – The alias name of the account.
passphrase (str) – Passphrase used to encrypt the account storage file.
private_key (str) – Hex string private key to import.
- Returns:
Tuple of AccountAPI and mnemonic for the generated account.