MoccasinAccount

class moccasin.moccasin_account.MoccasinAccount(private_key: str | bytes | None = None, keystore_path_or_account_name: Path | str | None = None, password: str = None, password_file_path: Path = None, address: Address | None = None, ignore_warning: bool = False)

Bases: LocalAccount

A class representing a Moccasin account, extending LocalAccount functionality.

This class provides enhanced account management features including keystore handling, private key management, and account unlocking capabilities.

Parameters:
  • private_key (str | bytes | None) – The private key for the account

  • keystore_path_or_account_name (Path | str | None) – Path to keystore file or account name

  • password (str) – Password for keystore decryption

  • password_file_path (Path) – Path to file containing password

  • address (Address | None) – Address for the account

  • ignore_warning (bool) – Whether to ignore warning about unlocked account

Variables:
  • _private_key – The account’s private key

  • _address – The account’s address

  • _publicapi – Public API instance for account operations

  • keystore_path – Path to the account’s keystore file

property private_key: bytes

Get the private key of the account.

Returns:

The private key in bytes

Return type:

bytes

property address: ChecksumAddress | None

Get the account’s address.

Returns:

The account’s checksum address or None if not set

Return type:

ChecksumAddress | None

set_keystore_path(keystore_path: Path | str)

Set the path to the keystore file.

Parameters:

keystore_path (Path | str) – Path to the keystore file

unlocked() bool

Check if the account is unlocked.

Returns:

True if the account is unlocked, False otherwise

Return type:

bool

unlock(password: str = None, password_file_path: Path = None, prompt_even_if_unlocked: bool = False) HexBytes

Unlock the account using a password or password file.

Parameters:
  • password (str) – Password for keystore decryption

  • password_file_path (Path) – Path to file containing password

  • prompt_even_if_unlocked (bool) – Whether to prompt for password even if account is already unlocked

Returns:

The decrypted private key

Return type:

HexBytes

Raises:

Exception – If no keystore path is provided

get_balance() int

Get the account balance using boa environment.

Returns:

The account balance in wei

Return type:

int

classmethod from_boa_address(address: Address) MoccasinAccount

Create a MoccasinAccount instance from a boa address.

Parameters:

address (Address) – The boa address

Returns:

A new MoccasinAccount instance

Return type:

MoccasinAccount