Const
Optional
options: BcsTypeOptions<boolean, boolean>bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
Creates a BcsType representing a fixed length byte array
The number of bytes this types represents
Optional
options: BcsTypeOptions<Uint8Array, Iterable<number>>bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
Creates a BcsType representing an enum of a given set of options
The name of the enum
The values of the enum. The order of the values affects how data is serialized and deserialized. null can be used to represent a variant with no data.
Optional
options: Omit<BcsTypeOptions<EnumOutputShape<{const enum = bcs.enum('MyEnum', {
A: bcs.u8(),
B: bcs.string(),
C: null,
})
enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
Creates a BcsType that represents a fixed length array of a given type
bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
Creates a BcsType representing a map of a given key and value type
const map = bcs.map(bcs.u8(), bcs.string())
map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
Creates a BcsType representing an optional value
bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
Optional
options: BcsTypeOptions<string, string>bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
Creates a BcsType representing a struct of a given set of fields
The name of the struct
The fields of the struct. The order of the fields affects how data is serialized and deserialized
Optional
options: Omit<BcsTypeOptions<{const struct = bcs.struct('MyStruct', {
a: bcs.u8(),
b: bcs.string(),
})
struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
Creates a BcsType representing a tuple of a given set of types
const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
Optional
options: BcsTypeOptions<string, string | number | bigint>bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
Optional
options: BcsTypeOptions<number, number>bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
Optional
options: BcsTypeOptions<string, string | number | bigint>bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
Optional
options: BcsTypeOptions<number, number>bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
Optional
options: BcsTypeOptions<string, string | number | bigint>bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
Optional
options: BcsTypeOptions<number, number>bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
Creates a BcsType that can be used to read and write unsigned LEB encoded integers
Optional
options: BcsTypeOptions<number, number>
Creates a BcsType representing a variable length vector of a given type
bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
Creates a BcsType that can be used to read and write boolean values.