getU256Codec
Returns a codec for encoding and decoding 256-bit unsigned integers (u256).
This codec serializes u256 values using 32 bytes.
Values can be provided as either number or bigint, but the decoded value is always a bigint.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | NumberCodecConfig | Optional configuration to specify endianness (little by default). |
Returns
FixedSizeCodec<number | bigint, bigint, 32>
A FixedSizeCodec<number | bigint, bigint, 32> for encoding and decoding u256 values.
Examples
Encoding and decoding a u256 value.
Using big-endian encoding.
Remarks
This codec supports values between 0 and 2^256 - 1.
Since JavaScript number cannot safely represent values beyond 2^53 - 1, the decoded value is always a bigint.
- If you need a smaller unsigned integer, consider using getU128Codec or getU64Codec.
- If you need signed integers, consider using getI256Codec.
Separate getU256Encoder and getU256Decoder functions are available.