Address

class cometa.address.address.Address(ptr)[source]

Bases: object

Represents a Cardano address.

This is the base class for all Cardano address types. It can represent any address format including base, enterprise, pointer, reward, and Byron addresses.

Addresses can be created from:
  • A Bech32 or Base58 string representation

  • Raw bytes

  • Specific address type constructors (BaseAddress, EnterpriseAddress, etc.)

__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

Address

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_string(address_string)[source]

Creates an address from a string representation.

Accepts both Bech32 (Shelley-era) and Base58 (Byron-era) encoded addresses.

Parameters:

address_string (str) – The string representation of the address.

Returns:

A new Address instance.

Raises:

CardanoError – If the string is not a valid address format.

Return type:

Address

Example

>>> addr = Address.from_string("addr1...")
classmethod from_bytes(data)[source]

Creates an address from raw bytes.

Parameters:

data (bytes | bytearray) – The serialized address bytes.

Returns:

A new Address instance.

Raises:

CardanoError – If the bytes are not a valid address.

Return type:

Address

Example

>>> addr = Address.from_bytes(address_bytes)
static is_valid(address_string)[source]

Checks if a string is a valid Cardano address.

Validates both Bech32 (Shelley) and Base58 (Byron) address formats.

Parameters:

address_string (str) – The string to validate.

Returns:

True if the string is a valid Cardano address, False otherwise.

Return type:

bool

Example

>>> Address.is_valid("addr1...")
True
static is_valid_bech32(address_string)[source]

Checks if a string is a valid Bech32-encoded Cardano address.

Parameters:

address_string (str) – The string to validate.

Returns:

True if the string is a valid Bech32 Cardano address.

Return type:

bool

Example

>>> Address.is_valid_bech32("addr1...")
True
static is_valid_byron(address_string)[source]

Checks if a string is a valid Byron-encoded Cardano address.

Parameters:

address_string (str) – The string to validate.

Returns:

True if the string is a valid Byron address.

Return type:

bool

Example

>>> Address.is_valid_byron("Ae2td...")
True
property type: AddressType

Returns the address type.

property network_id: NetworkId

Returns the network ID (mainnet or testnet).

property is_mainnet: bool

Returns True if this is a mainnet address.

property is_testnet: bool

Returns True if this is a testnet address.

to_bytes()[source]

Returns the serialized byte representation of the address.

Returns:

The address as bytes.

Return type:

bytes

Example

>>> addr.to_bytes()
b'\x01...'
to_base_address()[source]

Converts this address to a BaseAddress if applicable.

Returns:

A BaseAddress instance, or None if the conversion is not possible.

Return type:

Optional[BaseAddress]

Example

>>> base = addr.to_base_address()
to_byron_address()[source]

Converts this address to a ByronAddress if applicable.

Returns:

A ByronAddress instance, or None if the conversion is not possible.

Return type:

Optional[ByronAddress]

Example

>>> byron = addr.to_byron_address()
to_enterprise_address()[source]

Converts this address to an EnterpriseAddress if applicable.

Returns:

An EnterpriseAddress instance, or None if the conversion is not possible.

Return type:

Optional[EnterpriseAddress]

Example

>>> ent = addr.to_enterprise_address()
to_pointer_address()[source]

Converts this address to a PointerAddress if applicable.

Returns:

A PointerAddress instance, or None if the conversion is not possible.

Return type:

Optional[PointerAddress]

Example

>>> ptr_addr = addr.to_pointer_address()
to_reward_address()[source]

Converts this address to a RewardAddress if applicable.

Returns:

A RewardAddress instance, or None if the conversion is not possible.

Return type:

Optional[RewardAddress]

Example

>>> reward = addr.to_reward_address()
__str__()[source]

Returns the string representation of the address (Bech32 or Base58).

Return type:

str

__bytes__()[source]

Returns the serialized bytes of the address.

Return type:

bytes

__hash__()[source]

Returns a Python hash for use in sets and dicts.

Return type:

int

__eq__(other)[source]

Checks equality with another Address.

Parameters:

other (object)

Return type:

bool

__len__()[source]

Returns the size of the serialized address in bytes.

Return type:

int