U16

Primitive 42 v490

About This Type

Unsigned 16-bit integer (0 to 2^16 - 1).

Fixed-width 2-byte unsigned integer.

Encoding: Fixed-width: 2 bytes, little-endian.

Primitive Type

Name
U16
Byte Size
2 bytes
SCALE Encoding
Fixed-width, little-endian

SCALE Encoding

Rule
Variant: 0x00 = Ok (no payload), 0x01 = Err (followed by DispatchError).
Size
variable (1+ bytes)

Examples

Success (Ok) = Ok(())
0x00
00 Variant index 0 = Ok, no payload
Failure (Err) = Err(DispatchError::BadOrigin)
0x0102
01 Variant index 1 = Err
02 DispatchError variant 2 = BadOrigin

Code Examples

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

const registry = new TypeRegistry();

// Encode a U16 value
const value = registry.createType("U16", 1);
console.log("Hex:", value.toHex());
console.log("Bytes:", value.toU8a());

Type Information

Type ID
42
Kind
Primitive
Runtime
v490