Polkadot JS APIGlobals"codec/Struct"Struct

# Class: Struct <S, T, V, E>

name Struct

description A Struct defines an Object with key-value pairs - where the values are Codec values. It removes a lot of repetition from the actual coding, define a structure type, pass it the key/Codec values in the constructor and it manages the decoding. It is important that the constructor values matches 100% to the order in th Rust code, i.e. don't go crazy and make it alphabetical, it needs to decoded in the specific defined order.

# Type parameters

S: TypesDef

T: object

V: object

E: object

# Hierarchy

# Implements

# Index

# Constructors

# Properties

# Accessors

# Methods

# Constructors

# constructor

+ new Struct(registry: Registry, Types: S, value: V | Map‹unknown, unknown› | unknown[] | string, jsonMap: Map‹keyof S, string›): Struct

Defined in packages/types/src/codec/Struct.ts:116


Name Type Default
registry Registry -
Types S -
value V | Map‹unknown, unknown› | unknown[] | string {} as V
jsonMap Map‹keyof S, string› new Map()

Returns: Struct

# Properties

# Readonly registry

registry: Registry

Implementation of Codec.registry

Defined in packages/types/src/codec/Struct.ts:112

# Static Map

Map: MapConstructor

Defined in node_modules/typescript/lib/lib.es2015.collection.d.ts:36

# Accessors

# Type

get Type(): E

Defined in packages/types/src/codec/Struct.ts:175

description Returns the Type description to sthe structure

Returns: E

# defKeys

get defKeys(): string[]

Defined in packages/types/src/codec/Struct.ts:153

description The available keys for this enum

Returns: string[]

# encodedLength

get encodedLength(): number

Defined in packages/types/src/codec/Struct.ts:189

description The length of the value when encoded as a Uint8Array

Returns: number

# hash

get hash(): H256

Defined in packages/types/src/codec/Struct.ts:200

description returns a hash of the contents

Returns: H256

# isEmpty

get isEmpty(): boolean

Defined in packages/types/src/codec/Struct.ts:160

description Checks if the value is an empty value

Returns: boolean

# Methods

# eq

eq(other?: unknown): boolean

Implementation of Codec

Defined in packages/types/src/codec/Struct.ts:207

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


Name Type
other? unknown

Returns: boolean

# get

get(name: keyof S): Codec | undefined

Overrides CodecMap.get

Defined in packages/types/src/codec/Struct.ts:215

description Returns a specific names entry in the structure


Name Type Description
name keyof S The name of the entry to retrieve

Returns: Codec | undefined

# getAtIndex

getAtIndex(index: number): Codec

Defined in packages/types/src/codec/Struct.ts:222

description Returns the values of a member at a specific index (Rather use get(name) for performance)


Name Type
index number

Returns: Codec

# toArray

toArray(): Codec[]

Defined in packages/types/src/codec/Struct.ts:229

description Converts the Object to an standard JavaScript Array

Returns: Codec[]

# toHex

toHex(): string

Defined in packages/types/src/codec/Struct.ts:236

description Returns a hex string representation of the value

Returns: string

# toHuman

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

Implementation of Codec

Defined in packages/types/src/codec/Struct.ts:243

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 Codec

Defined in packages/types/src/codec/Struct.ts:256

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

Returns: AnyJson

# toRawType

toRawType(): string

Implementation of Codec

Defined in packages/types/src/codec/Struct.ts:280

description Returns the base runtime type name for this instance

Returns: string

# toString

toString(): string

Implementation of Codec

Defined in packages/types/src/codec/Struct.ts:289

description Returns the string representation of the value

Returns: string

# toU8a

toU8a(isBare?: BareOpts): Uint8Array

Implementation of Codec

Defined in packages/types/src/codec/Struct.ts:297

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


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

Returns: Uint8Array

# Static typesToMap

typesToMap(registry: Registry, Types: Record‹string, Constructor›): Record‹string, string›

Defined in packages/types/src/codec/Struct.ts:269


Name Type
registry Registry
Types Record‹string, Constructor

Returns: Record‹string, string›

# Static with

with<S>(Types: S, jsonMap?: Map‹keyof S, string›): ConstructorStruct‹S››

Defined in packages/types/src/codec/Struct.ts:129

Type parameters:

S: TypesDef


Name Type
Types S
jsonMap? Map‹keyof S, string›

Returns: ConstructorStruct‹S››