UNPKG

@gear-js/api

Version:

A JavaScript library that provides functionality to connect GEAR Component APIs.

38 lines (37 loc) 1.48 kB
import { Codec, Registry } from '@polkadot/types/types'; import { HexString } from '@polkadot/util/types'; export declare class CreateType { registry: Registry; private metadata; constructor(hexRegistry?: HexString); private registerDefaultTypes; /** * * @param type `TypeName` to encode or decode payload * @param payload `Payload` that have to be encoded or decoded * @returns Codec * @example * ```javascript * const createType = new CreateType(); * const encoded = createType.create('String', 'Hello, World'); * console.log(encoded.toHex()); // 0x48656c6c6f2c20576f726c6421 * * const decoded = createType.create('String', '0x48656c6c6f2c20576f726c6421'); * console.log(decoded.toHuman()); // "Hello, World!" */ create<T extends Codec = Codec>(typeOrTypeIndex: string | number, payload: unknown): T; /** * * @param type `TypeName` to encode or decode payload * @param payload `Payload` that have to be encoded or decoded * @param hexRegistry registry in hex format * @param defaultTypes set to true if you want to register default types too * @returns Codec * @example * ```javascript * const encoded = CreateType.create('String', 'Hello, World'); * console.log(encoded.toHex()); // 0x48656c6c6f2c20576f726c6421 * ``` */ static create<T extends Codec = Codec>(type: string, payload: unknown, hexRegistry?: HexString): T; }