Kit
Functions

assertIsStringifiedBigInt

assertIsStringifiedBigInt(putativeBigInt): asserts putativeBigInt is StringifiedBigInt

From time to time you might acquire a string, that you expect to parse as a BigInt, from an untrusted network API or user input. Use this function to assert that such an arbitrary string will in fact parse as a BigInt.

Parameters

ParameterType
putativeBigIntstring

Returns

asserts putativeBigInt is StringifiedBigInt

Example

import { assertIsStringifiedBigInt } from '@solana/rpc-types';
 
// Imagine having received a value that you presume represents the supply of some token.
// At this point we know only that it conforms to the `string` type.
try {
    // If this type assertion function doesn't throw, then
    // Typescript will upcast `supplyString` to `StringifiedBigInt`.
    assertIsStringifiedBigInt(supplyString);
    // At this point, `supplyString` is a `StringifiedBigInt`.
    supplyString satisfies StringifiedBigInt;
} catch (e) {
    // `supplyString` turned out not to parse as a `BigInt`
}

On this page