Serializers

Encode objects into CBOR or bech32 format.

In smart contract manipulations, serialization is a crucial process that encode data structures or objects into a format that can be easily stored or transmitted and later reconstructed. Below are utilities to help serialize various Cardano smart contracts components.

Serialize Native Script

The function serializeNativeScript allows you to provide the nativeScript with an option of networkId and stakeCredentialHash , returns:

  • Bech32 address
  • Script Cbor
This example demonstrates how to derive the native script from the pubKeyHash with the deserializeAddress then serialize the native script to a bech32 address and script Cbor. To read more on deserializeAddress.

Serialize Native Script

Serialize Native script into bech32 address

Serialize Plutus Script

The function serializePlutusScript allows you to provide the plutusScript with an option of networkId and stakeCredentialHash, returns:

  • Bech32 address
This example demonstrates how to derive and serialize a plutus script into a bech32 address.

Serialize Plutus Script

Serialize Plutus script into bech32 address

Serialize Address Object

Serialize address in Cardano data JSON format into bech32 address with serializeAddressObj().

First you need to create an address object with pubKeyAddress() or scriptAddress().

pubKeyAddress() accepts the following parameters:

scriptAddress() accepts the following parameters:

serializeAddressObj() accepts the following parameters:

Serialize Address Object

Serialize address in Cardano data JSON format into bech32 address

Serialize Pool ID

The function serializePoolId allows you to provide the pubKeyHash i.e (pool Hash), returns:

  • Pool Id
You can use this function to convert a pool hash into a pool ID, which is useful for interacting with staking and delegation mechanisms.

Serialize Pool ID

Resolve the pool ID from hash

Serialize Reward Address

Serialize a script hash or key hash into bech32 reward address.

The function serializeRewardAddress allows you to provide either the scriptHash or pubKeyHash, specifying isScriptHash as true if a scriptHash was provided and false if a pubKeyHash was provided. Additionally, you can specify the networkId The function returns:

  • Bech32 reward address
This example demonstrates how to serialize a pubKeyHash or scriptHash into a Bech32 reward address.

Serialize Reward Address

Serialize a script hash or key hash into bech32 reward address