AssetName
- class cometa.assets.asset_name.AssetName(ptr)[source]
Bases:
objectRepresents 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'
- 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:
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:
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:
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:
- 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