Serializer/Deserializer

Aptos using Binary Canonical Serialization (BCS) as their data serializer/deserializer. For more information, please check the following docs https://github.com/aptos-labs/bcs

Serializer

import { TxnBuilderTypes, BCS } from "@fewcha/aptos";

// RawTransaction
const rawTransaction = new TxnBuilderTypes.RawTransaction(
    sender,
    sequence_number,
    payload,
    max_gas_amount,
    gas_unit_price,
    expiration_timestamp_secs,
    chain_id
)
const serializer = new BCS.Serializer();
tx.serialize(serializer);
const serializedTxn = serializer.getBytes() // Uint8Array

Deserializer

import { TxnBuilderTypes, BCS } from "aptos";

// RawTransaction
const deserializer = new BCS.Deserializer(serializedTxn);
const rawTransaction = TxnBuilderTypes.RawTransaction.deserialize(d);

Last updated