MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / hexStringToBigInt

Function hexStringToBigInt

packages/hardhat-utils/src/hex.ts:37–53  ·  view source on GitHub ↗
(hexString: string)

Source from the content-addressed store, hash-verified

35 * @throws InvalidParameterError If the input is not a hexadecimal string.
36 */
37export function hexStringToBigInt(hexString: string): bigint {
38 if (!isHexString(hexString)) {
39 throw new InvalidParameterError(
40 `Expected a valid hexadecimal string. Received: ${hexString}`,
41 );
42 }
43 // Prefix the string as it is required to make BigInt interpret it as a
44 // hexadecimal number.
45 let prefixedHexString = getPrefixedHexString(hexString);
46 // BigInt does not support "0x" as a valid hexadecimal number, so we need to
47 // add a zero after the prefix if the string is "0x".
48 prefixedHexString = prefixedHexString === "0x" ? "0x0" : prefixedHexString;
49
50 const bigInt = BigInt(prefixedHexString);
51
52 return bigInt;
53}
54
55/**
56 * Converts a hexadecimal string to a number. The string must be a valid

Callers 9

#ethSendTransactionMethod · 0.90
#getNonceMethod · 0.90
fetchBlockNumberActionFunction · 0.90
#getNonceMethod · 0.90
handleMethod · 0.90
#getGasPriceMethod · 0.90
hex.tsFile · 0.85
bytesToBigIntFunction · 0.85

Calls 2

isHexStringFunction · 0.85
getPrefixedHexStringFunction · 0.85

Tested by

no test coverage detected