ape-accounts

class ape_accounts.AccountContainer(*, data_folder: Path, 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]

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

class ape_accounts.KeyfileAccount(*, keyfile_path: Path, locked: bool = True)
property address: ChecksumAddress

The address of this account. Subclasses must override and provide this value.

property alias: str

A shortened-name for quicker access to the account.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

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 handle SignableMessage, str, int, and bytes. See these docs # noqa: E501 for more type information on the SignableMessage 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 raise NotImplementedError.

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 to txn given as input, however returning a properly-formatted transaction here is meant to be executed. Returns None if the account does not have a transaction it wishes to execute.

Return type:

TransactionAPI (optional)

ape_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.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.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.