For maximum flexibility and readability by other methods, you can use the library's built-in metadata structs. This approach requires manual structural validation.
Core Types
TransactionMetadatum: Represents one of the 5 variant types (Map, List, Int, Bytes, Text).MetadataMap: An unordered map (like a JSON object) indexed by metadatums.MetadataList: An ordered list (like a JSON array) indexed starting at 0.Int: Represents signed or unsigned numbers.
Implementation Example
To construct a complex metadata object manually:
const map = CardanoWasm.MetadataMap.new();
map.insert(
CardanoWasm.TransactionMetadatum.new_text("receiver_id"),
CardanoWasm.TransactionMetadatum.new_text("SJKdj34k3jjKFDKfjFUDfdjkfd"),
);
// ... add other fields ...
const tags = CardanoWasm.MetadataList.new();
tags.add(CardanoWasm.TransactionMetadatum.new_int(CardanoWasm.Int.new(CardanoWasm.BigNum.from_str("0"))));
map.insert(
CardanoWasm.TransactionMetadatum.new_text("tags"),
CardanoWasm.TransactionMetadatum.new_list(tags),
);
const metadatum = CardanoWasm.TransactionMetadatum.new_map(map);
const map = CardanoWasm.MetadataMap.new();
map.insert(
CardanoWasm.TransactionMetadatum.new_text("receiver_id"),
CardanoWasm.TransactionMetadatum.new_text("SJKdj34k3jjKFDKfjFUDfdjkfd"),
);
map.insert(
CardanoWasm.TransactionMetadatum.new_text("sender_id"),
CardanoWasm.TransactionMetadatum.new_text("jkfdsufjdk34h3Sdfjdhfduf873"),
);
map.insert(
CardanoWasm.TransactionMetadatum.new_text("comment"),
CardanoWasm.TransactionMetadatum.new_text("happy birthday"),
);
const tags = CardanoWasm.MetadataList.new();
tags.add(CardanoWasm.TransactionMetadatum.new_int(CardanoWasm.Int.new(CardanoWasm.BigNum.from_str("0"))));
tags.add(CardanoWasm.TransactionMetadatum.new_int(CardanoWasm.Int.new(CardanoWasm.BigNum.from_str("264"))));
tags.add(CardanoWasm.TransactionMetadatum.new_int(CardanoWasm.Int.new_negative(CardanoWasm.BigNum.from_str("1024"))));
tags.add(CardanoWasm.TransactionMetadatum.new_int(CardanoWasm.Int.new(CardanoWasm.BigNum.from_str("32"))));
map.insert(
CardanoWasm.TransactionMetadatum.new_text("tags"),
CardanoWasm.TransactionMetadatum.new_list(tags),
);
const metadatum = CardanoWasm.TransactionMetadatum.new_map(map);