Kit
Functions

assertNumberIsBetweenForCodec

assertNumberIsBetweenForCodec(codecDescription, min, max, value): void

Ensures that a given number falls within a specified range.

If the number is outside the allowed range, an error is thrown. This function is primarily used to validate values before encoding them in a codec.

Parameters

ParameterTypeDescription
codecDescriptionstringA string describing the codec that is performing the validation.
minnumber | bigintThe minimum allowed value (inclusive).
maxnumber | bigintThe maximum allowed value (inclusive).
valuenumber | bigintThe number to validate.

Returns

void

Throws

SolanaError if the value is out of range.

Examples

Validating a number within range.

assertNumberIsBetweenForCodec('u8', 0, 255, 42); // Passes

Throwing an error for an out-of-range value.

assertNumberIsBetweenForCodec('u8', 0, 255, 300); // Throws

On this page