Documentation
    Preparing search index...

    Variable bcsConst

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

    Type declaration

    • fixedArray: {
          <T extends BcsType<any, any, string>, Name extends string = string>(
              size: number,
              type: T,
              options?: BcsTypeOptions<
                  InferBcsType<T>[],
                  Iterable<InferBcsInput<T>, any, any> & { length: number },
                  Name,
              >,
          ): BcsType<
              InferBcsType<T>[],
              Iterable<InferBcsInput<T>, any, any> & { length: number },
              Name,
          >;
          <T, Input, Name extends string = string>(
              size: number,
              type: BcsType<T, Input>,
              options?: BcsTypeOptions<
                  T[],
                  Iterable<Input, any, any> & { length: number },
                  Name,
              >,
          ): BcsType<T[], Iterable<Input, any, any> & { length: number }, Name>;
      }

      Creates a BcsType that represents a fixed length array of a given type

      The number of elements in the array

      The BcsType of each element in the array

      bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
      
    • map: {
          <
              K extends BcsType<any, any, string>,
              V extends BcsType<any, any, string>,
          >(
              keyType: K,
              valueType: V,
          ): BcsType<
              Map<InferBcsType<K>, InferBcsType<V>>,
              Map<InferBcsInput<K>, InferBcsInput<V>>,
              `Map<${K["name"]}, ${V["name"]}>`,
          >;
          <K, V, InputK = K, InputV = V>(
              keyType: BcsType<K, InputK>,
              valueType: BcsType<V, InputV>,
          ): BcsType<Map<K, V>, Map<InputK, InputV>, `Map<${string}, ${string}>`>;
      }

      Creates a BcsType representing a map of a given key and value type

      The BcsType of the key

      The BcsType of the value

      const map = bcs.map(bcs.u8(), bcs.string())
      map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
    • option: {
          <T extends BcsType<any, any, string>>(
              type: T,
          ): BcsType<
              null
              | InferBcsType<T>,
              undefined | null | InferBcsInput<T>,
              `Option<${T["name"]}>`,
          >;
          <T, Input, Name extends string = string>(
              type: BcsType<T, Input, Name>,
          ): BcsType<null | T, undefined | null | Input>;
      }

      Creates a BcsType representing an optional value

      The BcsType of the optional value

      bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
      bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
    • vector: {
          <
              T extends BcsType<any, any, string>,
              Name extends string = `vector<${T["name"]}>`,
          >(
              type: T,
              options?: BcsTypeOptions<
                  InferBcsType<T>[],
                  Iterable<InferBcsInput<T>, any, any> & { length: number },
                  Name,
              >,
          ): BcsType<
              InferBcsType<T>[],
              Iterable<InferBcsInput<T>, any, any> & { length: number },
              Name,
          >;
          <T, Input, Name extends string = string>(
              type: BcsType<T, Input, Name>,
              options?: BcsTypeOptions<
                  T[],
                  Iterable<Input, any, any> & { length: number },
                  `vector<${Name}>`,
              >,
          ): BcsType<
              T[],
              Iterable<Input, any, any> & { length: number },
              `vector<${Name}>`,
          >;
      }

      Creates a BcsType representing a variable length vector of a given type

      The BcsType of each element in the vector

      bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
      
    • bool: function
      • Creates a BcsType that can be used to read and write boolean values.

        Parameters

        Returns BcsType<boolean, boolean, "bool">

        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<ArrayBufferLike>, Iterable<number, any, any>, string>

        Returns BcsType<Uint8Array<ArrayBufferLike>, Iterable<number, any, any>, `bytes[${T}]`>

        bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
        
    • byteVector: function
      • Creates a BcsType representing a variable length byte array

        Parameters

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

        Returns BcsType<Uint8Array<ArrayBufferLike>, Iterable<number, any, any>, "vector<u8>">

        bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 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, string>>
        • const Name extends string = string

        Parameters

        • name: Name

          The name of the enum

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

        Returns BcsEnum<T, Name>

        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 ]
    • lazy: function
      • Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.

        Type Parameters

        • T extends BcsType<any, any, string>

        Parameters

        • cb: () => T

          A callback that returns the BcsType

        Returns T

    • string: function
      • Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded

        Parameters

        Returns BcsType<string, 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, string>>
        • const Name extends string = string

        Parameters

        • name: Name

          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, string> ? U : never
                  },
                  {
                      [K in string
                      | number
                      | symbol]: T[K] extends BcsType<any, U, string> ? U : never
                  },
                  string,
              >,
              "name",
          >

        Returns BcsStruct<T, string>

        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 T extends readonly BcsType<any, any, string>[]
        • const Name extends string = `(${JoinString<
              {
                  [K in string
                  | number
                  | symbol]: T[K<K>] extends BcsType<any, any, T> ? T : never
              },
              ", ",
          >})`

        Parameters

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

        Returns BcsTuple<T, Name>

        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

        • Optionaloptions: BcsTypeOptions<string, string | number | bigint, string>

        Returns BcsType<string, string | number | bigint, "u128">

        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, "u16">

        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

        • Optionaloptions: BcsTypeOptions<string, string | number | bigint, string>

        Returns BcsType<string, string | number | bigint, "u256">

        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, "u32">

        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

        • Optionaloptions: BcsTypeOptions<string, string | number | bigint, string>

        Returns BcsType<string, string | number | bigint, "u64">

        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, "u8">

        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, string>