bcs: {
    bool(options?: BcsTypeOptions<boolean, boolean>): BcsType<boolean, boolean>;
    bytes<T>(size: T, options?: BcsTypeOptions<Uint8Array, Iterable<number, any, any>>): BcsType<Uint8Array, Uint8Array>;
    enum<T>(name: string, values: T, options?: Omit<BcsTypeOptions<EnumOutputShape<{
        [K in string | number | symbol]: T[K] extends BcsType<U, any>
            ? U
            : true
    }>, EnumInputShape<{
        [K in string | number | symbol]: T[K] extends BcsType<any, U>
            ? U
            : null | boolean | object
    }>>, "name">): BcsType<EnumOutputShape<{
        [K in string | number | symbol]: T[K] extends BcsType<U, any>
            ? U
            : true
    }>, EnumInputShape<{
        [K in string | number | symbol]: T[K] extends BcsType<any, U>
            ? U
            : null | boolean | object
    }>>;
    fixedArray<T, Input>(size: number, type: BcsType<T, Input>, options?: BcsTypeOptions<T[], Iterable<Input, any, any> & {
        length: number;
    }>): BcsType<T[], Iterable<Input, any, any> & {
        length: number;
    }>;
    lazy<T>(cb: (() => T)): T;
    map<K, V, InputK, InputV>(keyType: BcsType<K, InputK>, valueType: BcsType<V, InputV>): BcsType<Map<K, V>, Map<InputK, InputV>>;
    option<T, Input>(type: BcsType<T, Input>): BcsType<null | T, undefined | null | Input>;
    string(options?: BcsTypeOptions<string, string>): BcsType<string, string>;
    struct<T>(name: string, fields: T, options?: Omit<BcsTypeOptions<{
        [K in string | number | symbol]: T[K] extends BcsType<U, any>
            ? U
            : never
    }, {
        [K in string | number | symbol]: T[K] extends BcsType<any, U>
            ? U
            : never
    }>, "name">): BcsType<{
        [K in string | number | symbol]: T[K] extends BcsType<U, any>
            ? U
            : never
    }, {
        [K in string | number | symbol]: T[K] extends BcsType<any, U>
            ? U
            : never
    }>;
    tuple<const Types>(types: Types, options?: BcsTypeOptions<{
        -readonly [K in string | number | symbol]: Types[K<K>] extends BcsType<T, any>
            ? T
            : never
    }, {
        [K in string | number | symbol]: Types[K<K>] extends BcsType<any, T>
            ? T
            : never
    }>): BcsType<{
        -readonly [K in string | number | symbol]: Types[K<K>] extends BcsType<T, any>
            ? T
            : never
    }, {
        [K in string | number | symbol]: Types[K<K>] extends BcsType<any, T>
            ? T
            : never
    }>;
    u128(options?: BcsTypeOptions<string, string | number | bigint>): BcsType<string, string | number | bigint>;
    u16(options?: BcsTypeOptions<number, number>): BcsType<number, number>;
    u256(options?: BcsTypeOptions<string, string | number | bigint>): BcsType<string, string | number | bigint>;
    u32(options?: BcsTypeOptions<number, number>): BcsType<number, number>;
    u64(options?: BcsTypeOptions<string, string | number | bigint>): BcsType<string, string | number | bigint>;
    u8(options?: BcsTypeOptions<number, number>): BcsType<number, number>;
    uleb128(options?: BcsTypeOptions<number, number>): BcsType<number, number>;
    vector<T, Input>(type: BcsType<T, Input>, options?: BcsTypeOptions<T[], Iterable<Input, any, any> & {
        length: number;
    }>): BcsType<T[], Iterable<Input, any, any> & {
        length: number;
    }>;
} = ...

Type declaration

  • bool:function
    • Creates a BcsType that can be used to read and write boolean values.

      Parameters

      Returns BcsType<boolean, boolean>

      bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
      
  • bytes:function
    • Creates a BcsType representing a fixed length byte array

      Type Parameters

      • T extends number

      Parameters

      • size: T

        The number of bytes this types represents

      • Optionaloptions: BcsTypeOptions<Uint8Array, Iterable<number, any, any>>

      Returns BcsType<Uint8Array, Uint8Array>

      bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
      
  • enum:function
    • Creates a BcsType representing an enum of a given set of options

      Type Parameters

      • T extends Record<string, null | BcsType<any, any>>

      Parameters

      • name: string

        The name of the enum

      • values: T

        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.

      • Optionaloptions: Omit<BcsTypeOptions<EnumOutputShape<{
            [K in string | number | symbol]: T[K] extends BcsType<U, any>
                ? U
                : true
        }>, EnumInputShape<{
            [K in string | number | symbol]: T[K] extends BcsType<any, U>
                ? U
                : null | boolean | object
        }>>, "name">

      Returns BcsType<EnumOutputShape<{
          [K in string | number | symbol]: T[K] extends BcsType<U, any>
              ? U
              : true
      }>, EnumInputShape<{
          [K in string | number | symbol]: T[K] extends BcsType<any, U>
              ? U
              : null | boolean | object
      }>>

      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 ]
  • fixedArray:function
    • Creates a BcsType that represents a fixed length array of a given type

      Type Parameters

      • T
      • Input

      Parameters

      • size: number

        The number of elements in the array

      • type: BcsType<T, Input>

        The BcsType of each element in the array

      • Optionaloptions: BcsTypeOptions<T[], Iterable<Input, any, any> & {
            length: number;
        }>

      Returns BcsType<T[], Iterable<Input, any, any> & {
          length: number;
      }>

      bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
      
  • lazy:function
    • Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.

      Type Parameters

      Parameters

      • cb: (() => T)

        A callback that returns the BcsType

          • (): T
          • Returns T

      Returns T

  • map:function
    • Creates a BcsType representing a map of a given key and value type

      Type Parameters

      • K
      • V
      • InputK = K
      • InputV = V

      Parameters

      Returns BcsType<Map<K, V>, Map<InputK, InputV>>

      const map = bcs.map(bcs.u8(), bcs.string())
      map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
  • option:function
    • Creates a BcsType representing an optional value

      Type Parameters

      • T
      • Input

      Parameters

      Returns BcsType<null | T, undefined | null | Input>

      bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
      bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
  • string:function
    • Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded

      Parameters

      Returns BcsType<string, string>

      bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
      
  • struct:function
    • Creates a BcsType representing a struct of a given set of fields

      Type Parameters

      • T extends Record<string, BcsType<any, any>>

      Parameters

      • name: string

        The name of the struct

      • fields: T

        The fields of the struct. The order of the fields affects how data is serialized and deserialized

      • Optionaloptions: Omit<BcsTypeOptions<{
            [K in string | number | symbol]: T[K] extends BcsType<U, any>
                ? U
                : never
        }, {
            [K in string | number | symbol]: T[K] extends BcsType<any, U>
                ? U
                : never
        }>, "name">

      Returns BcsType<{
          [K in string | number | symbol]: T[K] extends BcsType<U, any>
              ? U
              : never
      }, {
          [K in string | number | symbol]: T[K] extends BcsType<any, U>
              ? U
              : never
      }>

      const struct = bcs.struct('MyStruct', {
      a: bcs.u8(),
      b: bcs.string(),
      })
      struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
  • tuple:function
    • Creates a BcsType representing a tuple of a given set of types

      Type Parameters

      • const Types extends readonly BcsType<any, any>[]

      Parameters

      • types: Types

        The BcsTypes for each element in the tuple

      • Optionaloptions: BcsTypeOptions<{
            -readonly [K in string | number | symbol]: Types[K<K>] extends BcsType<T, any>
                ? T
                : never
        }, {
            [K in string | number | symbol]: Types[K<K>] extends BcsType<any, T>
                ? T
                : never
        }>

      Returns BcsType<{
          -readonly [K in string | number | symbol]: Types[K<K>] extends BcsType<T, any>
              ? T
              : never
      }, {
          [K in string | number | symbol]: Types[K<K>] extends BcsType<any, T>
              ? T
              : never
      }>

      const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
      tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
  • u128:function
    • Creates a BcsType that can be used to read and write a 128-bit unsigned integer.

      Parameters

      Returns BcsType<string, string | number | bigint>

      bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
      
  • u16:function
    • Creates a BcsType that can be used to read and write a 16-bit unsigned integer.

      Parameters

      Returns BcsType<number, number>

      bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
      
  • u256:function
    • Creates a BcsType that can be used to read and write a 256-bit unsigned integer.

      Parameters

      Returns BcsType<string, string | number | bigint>

      bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
      
  • u32:function
    • Creates a BcsType that can be used to read and write a 32-bit unsigned integer.

      Parameters

      Returns BcsType<number, number>

      bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
      
  • u64:function
    • Creates a BcsType that can be used to read and write a 64-bit unsigned integer.

      Parameters

      Returns BcsType<string, string | number | bigint>

      bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
      
  • u8:function
    • Creates a BcsType that can be used to read and write an 8-bit unsigned integer.

      Parameters

      Returns BcsType<number, number>

      bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
      
  • uleb128:function
    • Creates a BcsType that can be used to read and write unsigned LEB encoded integers

      Parameters

      Returns BcsType<number, number>

      
      
  • vector:function
    • Creates a BcsType representing a variable length vector of a given type

      Type Parameters

      • T
      • Input

      Parameters

      Returns BcsType<T[], Iterable<Input, any, any> & {
          length: number;
      }>

      bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]