AssetName

class cometa.assets.asset_name.AssetName(ptr)[source]

Bases: object

Represents a native asset name in the Cardano blockchain.

Asset names in Cardano are arbitrary byte strings (up to 32 bytes) used to uniquely identify assets within a minting policy. They can represent human-readable names or arbitrary binary data.

Example

>>> asset_name = AssetName.from_string("MyToken")
>>> asset_name.to_string()
'MyToken'
__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

AssetName

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

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_bytes(data)[source]

Creates an asset name from raw bytes.

Parameters:

data (bytes | bytearray) – The asset name as raw bytes (max 32 bytes).

Returns:

A new AssetName instance.

Raises:

CardanoError – If creation fails.

Return type:

AssetName

Example

>>> asset_name = AssetName.from_bytes(b"MyToken")
classmethod from_hex(hex_string)[source]

Creates an asset name from a hexadecimal string.

Parameters:

hex_string (str) – The asset name as a hexadecimal string.

Returns:

A new AssetName instance.

Raises:

CardanoError – If creation fails or hex is invalid.

Return type:

AssetName

Example

>>> asset_name = AssetName.from_hex("4d79546f6b656e")  # "MyToken"
classmethod from_string(name)[source]

Creates an asset name from a UTF-8 string.

Parameters:

name (str) – The asset name as a human-readable string.

Returns:

A new AssetName instance.

Raises:

CardanoError – If creation fails.

Return type:

AssetName

Example

>>> asset_name = AssetName.from_string("MyToken")
classmethod from_cbor(reader)[source]

Deserializes an AssetName from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the asset name data.

Returns:

A new AssetName deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

AssetName

to_bytes()[source]

Returns the asset name as raw bytes.

Returns:

The asset name bytes.

Return type:

bytes

to_hex()[source]

Returns the asset name as a hexadecimal string.

Returns:

The asset name as a hex string.

Return type:

str

to_string()[source]

Returns the asset name as a UTF-8 string.

Returns:

The asset name as a human-readable string.

Return type:

str

Note

If the asset name contains non-UTF-8 bytes, this may return an incomplete or garbled string.

to_cbor(writer)[source]

Serializes the asset name to CBOR format.

Parameters:

writer (CborWriter) – A CborWriter to write the serialized data to.

Raises:

CardanoError – If serialization fails.

Return type:

None

to_cip116_json(writer)[source]

Serializes this asset name to CIP-116 compliant JSON.

Parameters:

writer (JsonWriter) – The JsonWriter to write the JSON to.

Raises:

CardanoError – If serialization fails.

Return type:

None

__len__()[source]

Returns the length of the asset name in bytes.

Return type:

int

__eq__(other)[source]

Checks equality with another AssetName.

Parameters:

other (object)

Return type:

bool

__hash__()[source]

Returns a Python hash for use in sets and dicts.

Return type:

int

__str__()[source]

Returns the string representation of the asset name.

Return type:

str