Option

Variant 51 v393

Option

About This Type

Optional value: Some(value) or None.

Used when a value may or may not be present. Common in storage queries where a key may not exist.

Encoding: Variant: 0x00 = None, 0x01 = Some(value). Exception: Option<bool> uses 0x00=None, 0x01=true, 0x02=false.

Variants (2)

IndexNameFieldsDocs
0Nonenone
1Some

SCALE Encoding

Rule
Variant: 0x00 = None, 0x01 = Some(value).
Size
variable (1+ bytes)

Examples

None
0x00
00 Variant index 0 = None
Some(42u32) = Some(42)
0x012a000000
01 Variant index 1 = Some
2a 00 00 00 42 as u32 little-endian

Code Examples

import { TypeRegistry } from "@polkadot/types";

const registry = new TypeRegistry();

// Encode Option — variant "None"
const value = registry.createType("Option", "None");
console.log("Hex:", value.toHex());

Type Parameters

T = u32

Referenced By (157)

and 137 more...

Type Information

Type ID
51
Kind
Variant
Path
Option
Runtime
v393