This library serves as serialization library for Cardano's decentralized exchanges (DEXs). It offers types to simplify the transaction construction and cbor encoding for datums and redeemers to place an order for a specfic DEX. Furthermore, its types are also able to read in cbor and decode it to corresponding types, if valid.
As this library supports decoding from and encoding to cbor, there are generally two types per datum and redeemer.
One for constructing and encoding, which this library refers to as builder
type. And another one for decoding hex-encoded cbor to a specific type, which this library names decoder
.
Every builder
type follows the same pattern inspired by cardano-serialization-lib (CSL) as follows:
Example for creating an IAssetClass
:
const minswapAC: IAssetClass = AssetClassBuilder.new()
.currencySymbol('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6')
.tokenName('4d494e')
.build();
const plutusData: PlutusData = minswapAC.encode();
const cborBytes: UInt8Array = plutusData.to_bytes();
const cborHex: string = plutusData.to_hex();
A decoder
usually takes no arguments to be constructed and offers a decode
method.
Example for decoding an IAssetClass
:
try {
const minswap: IAssetClass = new AssetClassDecoder()
.decode('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6434d494e');
} catch (e) {
/* invalid asset class cbor passed */
}
More specific examples related to orders for each DEX can be found under the following links: