Polkadot JS APIGlobals"codec/Compact"Compact

# Class: Compact <T>

name Compact

description A compact length-encoding codec wrapper. It performs the same function as Length, however differs in that it uses a variable number of bytes to do the actual encoding. This is mostly used by other types to add length-prefixed encoding, or in the case of wrapped types, taking a number and making the compact representation thereof

# Type parameters

T: CompactEncodable

# Hierarchy

  • Base‹T›


# Implements

# Index

# Constructors

# Properties

# Accessors

# Methods

# Constructors

# constructor

+ new Compact(registry: Registry, Type: Constructor‹T› | keyof InterfaceTypes, value: Compact‹T› | AnyNumber): Compact

Overrides void

Defined in packages/types/src/codec/Compact.ts:29


Name Type Default
registry Registry -
Type Constructor‹T› | keyof InterfaceTypes -
value Compact‹T› | AnyNumber 0

Returns: Compact

# Properties

# Readonly registry

registry: Registry

Implementation of ICompact.registry

Inherited from Base.registry

Defined in packages/types/src/codec/Base.ts:17

# Static addLengthPrefix

addLengthPrefix: compactAddLength = compactAddLength

Defined in packages/types/src/codec/Compact.ts:49

Prepend a Uint8Array with its compact length.

param The Uint8Array to be prefixed

# Static decodeU8a

decodeU8a: compactFromU8a = compactFromU8a

Defined in packages/types/src/codec/Compact.ts:51

# Static encodeU8a

encodeU8a: compactToU8a = compactToU8a

Defined in packages/types/src/codec/Compact.ts:53

# Accessors

# encodedLength

get encodedLength(): number

Inherited from Base.encodedLength

Defined in packages/types/src/codec/Base.ts:29

description The length of the value when encoded as a Uint8Array

Returns: number

# hash

get hash(): H256

Inherited from Base.hash

Defined in packages/types/src/codec/Base.ts:36

description returns a hash of the contents

Returns: H256

# isEmpty

get isEmpty(): boolean

Inherited from Base.isEmpty

Defined in packages/types/src/codec/Base.ts:43

description Checks if the value is an empty value

Returns: boolean

# Methods

# bitLength

bitLength(): number

Defined in packages/types/src/codec/Compact.ts:77

description Returns the number of bits in the value

Returns: number

# eq

eq(other?: unknown): boolean

Implementation of ICompact

Overrides Base.eq

Defined in packages/types/src/codec/Compact.ts:84

description Compares the value of the input to see if there is a match


Name Type
other? unknown

Returns: boolean

# toBn

toBn(): BN

Implementation of ICompact

Defined in packages/types/src/codec/Compact.ts:95

description Returns the BN representation of the number

Returns: BN

# toHex

toHex(isLe?: undefined | false | true): string

Implementation of ICompact

Inherited from Base.toHex

Defined in packages/types/src/codec/Base.ts:57

description Returns a hex string representation of the value. isLe returns a LE (number-only) representation


Name Type
isLe? undefined | false | true

Returns: string

# toHuman

toHuman(isExtended?: undefined | false | true): AnyJson

Implementation of ICompact

Inherited from Base.toHuman

Defined in packages/types/src/codec/Base.ts:64

description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information


Name Type
isExtended? undefined | false | true

Returns: AnyJson

# toJSON

toJSON(): AnyJson

Implementation of ICompact

Inherited from Base.toJSON

Defined in packages/types/src/codec/Base.ts:71

description Converts the Object to JSON, typically used for RPC transfers

Returns: AnyJson

# toNumber

toNumber(): number

Implementation of ICompact

Defined in packages/types/src/codec/Compact.ts:102

description Returns the number representation for the value

Returns: number

# toRawType

toRawType(): string

Implementation of ICompact

Overrides Base.toRawType

Defined in packages/types/src/codec/Compact.ts:109

description Returns the base runtime type name for this instance

Returns: string

# toString

toString(): string

Implementation of ICompact

Inherited from Base.toString

Defined in packages/types/src/codec/Base.ts:78

description Returns the string representation of the value

Returns: string

# toU8a

toU8a(isBare?: undefined | false | true): Uint8Array

Overrides Base.toU8a

Defined in packages/types/src/codec/Compact.ts:118

description Encodes the value as a Uint8Array as per the SCALE specifications


Name Type Description
isBare? undefined | false | true true when the value has none of the type-specific prefixes (internal)

Returns: Uint8Array

# unwrap

unwrap(): T

Implementation of ICompact

Defined in packages/types/src/codec/Compact.ts:125

description Returns the embedded UInt or Moment value

Returns: T

# Static stripLengthPrefix

stripLengthPrefix(u8a: Uint8Array, bitLength: UIntBitLength): Uint8Array

Defined in packages/types/src/codec/Compact.ts:55


Name Type Default
u8a Uint8Array -

Returns: Uint8Array

# Static with

with<T>(Type: Constructor‹T› | keyof InterfaceTypes): ConstructorCompact‹T››

Defined in packages/types/src/codec/Compact.ts:36

Type parameters:

T: CompactEncodable


Name Type
Type Constructor‹T› | keyof InterfaceTypes

Returns: ConstructorCompact‹T››