TypeScript SDK
BCS

BCS

The @mysten/sui.js/bcs package extends @mysten/bcs with Sui specific scheme definitions.

To learn more about using BCS see the BCS documentation.

the bcs export of @mysten/sui.js/bcs contains all the same exports as bcs from @mysten/bcs plus the following pre-defined schemes:

  • U8
  • U16
  • U32
  • U64
  • U128
  • U256
  • ULEB128
  • Bool
  • String
  • Address
  • Argument
  • CallArg
  • CompressedSignature
  • GasData
  • MultiSig
  • MultiSigPkMap
  • MultiSigPublicKey
  • ObjectArg
  • ObjectDigest
  • ProgrammableMoveCall
  • ProgrammableTransaction
  • PublicKey
  • SenderSignedData
  • SharedObjectRef
  • StructTag
  • SuiObjectRef
  • Transaction
  • TransactionData
  • TransactionDataV1
  • TransactionExpiration
  • TransactionKind
  • TypeTag

All the upper-cased values are BcsType instances, and can be used directly to parse and serialize data.

import { bcs } from '@mysten/sui.js/bcs';
 
bcs.U8.serialize(1);
bcs.Address.serialize('0x1');
bcs.TypeTag.serialize({
	vector: {
		u8: true,
	},
});