Polkadot JS APIGlobals"codec/Option"Option

# Class: Option <T>

name Option

description An Option is an optional field. Basically the first byte indicates that there is is value to follow. If the byte is 1 there is an actual value. So the Option implements that - decodes, checks for optionality and wraps the required structure with a value if/as required/found.

# Type parameters

T: Codec

# Hierarchy

  • Base‹T›

    Option

# Implements

# Index

# Constructors

# Properties

# Accessors

# Methods

# Constructors

# constructor

+ new Option(registry: Registry, typeName: Constructor‹T› | keyof InterfaceTypes, value?: unknown): Option

Overrides void

Defined in packages/types/src/codec/Option.ts:52

Parameters:

Name Type
registry Registry
typeName Constructor‹T› | keyof InterfaceTypes
value? unknown

Returns: Option

# Properties

# Readonly registry

registry: Registry

Implementation of Codec.registry

Inherited from Base.registry

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

# Accessors

# encodedLength

get encodedLength(): number

Overrides Base.encodedLength

Defined in packages/types/src/codec/Option.ts:73

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

Overrides Base.isEmpty

Defined in packages/types/src/codec/Option.ts:81

description Checks if the Option has no value

Returns: boolean


# isNone

get isNone(): boolean

Defined in packages/types/src/codec/Option.ts:88

description Checks if the Option has no value

Returns: boolean


# isSome

get isSome(): boolean

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

description Checks if the Option has a value

Returns: boolean


# value

get value(): Codec

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

description The actual value for the Option

Returns: Codec

# Methods

# eq

eq(other?: unknown): boolean

Implementation of Codec

Overrides Base.eq

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

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

Parameters:

Name Type
other? unknown

Returns: boolean


# toHex

toHex(): string

Overrides Base.toHex

Defined in packages/types/src/codec/Option.ts:120

description Returns a hex string representation of the value

Returns: string


# toHuman

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

Implementation of Codec

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

Parameters:

Name Type
isExtended? undefined | false | true

Returns: AnyJson


# toJSON

toJSON(): AnyJson

Implementation of Codec

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


# toRawType

toRawType(isBare?: undefined | false | true): string

Overrides Base.toRawType

Defined in packages/types/src/codec/Option.ts:131

description Returns the base runtime type name for this instance

Parameters:

Name Type
isBare? undefined | false | true

Returns: string


# toString

toString(): string

Implementation of Codec

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/Option.ts:143

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

Parameters:

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

Returns: Uint8Array


# unwrap

unwrap(): T

Defined in packages/types/src/codec/Option.ts:161

description Returns the value that the Option represents (if available), throws if null

Returns: T


# unwrapOr

unwrapOr<O>(defaultValue: O): T | O

Defined in packages/types/src/codec/Option.ts:173

description Returns the value that the Option represents (if available) or defaultValue if none

Type parameters:

O

Parameters:

Name Type Description
defaultValue O The value to return if the option isNone

Returns: T | O


# unwrapOrDefault

unwrapOrDefault(): T

Defined in packages/types/src/codec/Option.ts:183

description Returns the value that the Option represents (if available) or defaultValue if none

Returns: T


# Static with

with<O>(Type: Constructor‹O› | keyof InterfaceTypes): ConstructorOption‹O››

Defined in packages/types/src/codec/Option.ts:62

Type parameters:

O: Codec

Parameters:

Name Type
Type Constructor‹O› | keyof InterfaceTypes

Returns: ConstructorOption‹O››