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: Annotated[ChecksumAddress, _AddressValidator]
The address of this account. Subclasses must override and provide this value.
- property alias: str
A shortened-name for quicker access to the account.
- property public_key: HexBytes | None
The public key for the account.
`{notice} Account might not have this property if feature is unsupported or inaccessible. `
- remove_delegate(**txn_kwargs)
Has the account class remove the override for the value of its
delegate
. For plugins that support this feature, the way they choose to handle it can vary. For example, on a network using an EIP7702-like feature available it will reset the delegate to empty. However, if a plugin chooses to handle it, the resulting action (if successful) should make sure that the value thatself.delegate
returnsNone
after it is completed.By default, this method raises
APINotImplementedError
signaling that support is not available for this feature. Calling this may result in other errors if implemented.- Parameters:
**txn_kwargs – Additional transaction kwargs passed to
create_transaction()
, such asgas
max_fee
, ormax_priority_fee
. For a list of available transaction kwargs, seeTransactionAPI
.
- 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.
- set_delegate(contract: BaseAddress | Annotated[ChecksumAddress, _AddressValidator] | str, **txn_kwargs)
Have the account class override the value of its
delegate
. For plugins that support this feature, the way they choose to handle it can vary. For example, it could be a call to upgrade itself using some built-in method for a smart wallet (with default txn args) e.g. the Safe smart wallet (https://github.com/ApeWorX/ape-safe), or it could be to use an EIP- 7702-like feature available on the network to set a delegate for that account. However if a plugin chooses to handle it, the resulting action (if successful) should make sure that the value thatself.delegate
returns is the same ascontract
after it is completed.By default, this method raises
APINotImplementedError
signaling that support is not available for this feature. Calling this may result in other errors if implemented.- Parameters:
(` (contract) – class:~ape.contracts.ContractInstance`): The contract instance to override the delegate with.
**txn_kwargs – Additional transaction kwargs passed to
create_transaction()
, such asgas
max_fee
, ormax_priority_fee
. For a list of available transaction kwargs, seeTransactionAPI
.
- sign_authorization(address: Annotated[ChecksumAddress, _AddressValidator], chain_id: int | None = None, nonce: int | None = None) MessageSignature | None
Sign an EIP-7702 Authorization.
- Parameters:
address (Any) – A delegate address to sign the authorization for.
chain_id (Optional[int]) – The chain ID that the authorization should be valid for. A value of
0
means that the authorization is valid for any chain. Default tells implementation to use the currently connected network’schain_id
.nonce (Optional[int]) – The nonce to use to sign authorization with. Defaults to account’s current nonce.
- Returns:
The signature corresponding to the message.
- Return type:
MessageSignature
(optional)
`{caution} This action has the capability to be extremely destructive to the signer, and might lead to full account compromise. All implementations are recommended to ensure that the signer be made aware of the severity and impact of this action through some callout. `
- 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 raiseAPINotImplementedError
.- 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 hierarchical 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 hierarchical 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.