Namespace: num
Functions
isHex
▸ isHex(hex): boolean
Test if string is hex-string
Parameters
| Name | Type | Description |
|---|---|---|
hex | string | hex-string |
Returns
boolean
true if the input string is a hexadecimal string, false otherwise
Example
const hexString1 = '0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914';
const result1 = isHex(hexString1);
// result1 = true
const hexString2 = '2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914';
const result2 = isHex(hexString2);
// result2 = false
Defined in
toBigInt
▸ toBigInt(value): bigint
Convert BigNumberish to bigint
Parameters
| Name | Type | Description |
|---|---|---|
value | BigNumberish | value to convert |
Returns
bigint
converted value
Example
const str = '123';
const result = toBigInt(str);
// result = 123n
Defined in
tryToBigInt
▸ tryToBigInt(value): undefined | bigint
try to convert BigNumberish to bigint in case of undefined return undefined
Parameters
| Name | Type |
|---|---|
value | undefined | BigNumberish |
Returns
undefined | bigint
Defined in
toHex
▸ toHex(value): string
Convert BigNumberish to hex-string
Parameters
| Name | Type | Description |
|---|---|---|
value | BigNumberish | value to convert |
Returns
string
converted number in hex-string format
Example
toHex(100); // '0x64'
toHex('200'); // '0xc8'
toHex('0x00023AB'); // '0x23ab'
Defined in
cleanHex
▸ cleanHex(hex): string
Remove hex-string leading zeroes and lowercase it
Parameters
| Name | Type |
|---|---|
hex | string |
Returns
string
Example
cleanHex('0x00023AB'); // '0x23ab'
Defined in
toStorageKey
▸ toStorageKey(number): string
Convert BigNumberish to storage-key-string
Same as toHex but conforming to the STORAGE_KEY pattern ^0x0[0-7]{1}[a-fA-F0-9]{0,62}$.
A storage key is represented as up to 62 hex digits, 3 bits, and 5 leading zeroes:
0x0 + [0-7] + 62 hex = 0x + 64 hex
Parameters
| Name | Type |
|---|---|
number | BigNumberish |
Returns
string
format: storage-key-string
Example
toStorageKey(0x123); // '0x0000000000000000000000000000000000000000000000000000000000000123'
toStorageKey(123); // '0x000000000000000000000000000000000000000000000000000000000000007b'
toStorageKey('test'); // 'Error'