Skip to main content

utils

Index

References

keccak256

Renames and re-exports keccak256Wrapper

Namespaces

jsonRpc

jsonRpc:

isBatchRequest

isBatchResponse

isResponseRpcError

isResponseWithError

isResponseWithNotification

isResponseWithResult

isSubscriptionResult

isValidResponse

  • isValidResponse<Result, Error_1>(response: JsonRpcResponse<Result, Error_1>): boolean
  • Type parameters

    • Result = unknown
    • Error_1 = unknown

    Parameters

    Returns boolean

setRequestIdStart

  • setRequestIdStart(start: undefined | number): void
  • Parameters

    • start: undefined | number

    Returns void

toBatchPayload

toPayload

validateResponse

  • validateResponse<Result, Error_1>(response: JsonRpcResponse<Result, Error_1>): boolean
  • Type parameters

    • Result = unknown
    • Error_1 = unknown

    Parameters

    Returns boolean

Enumerations

FMT_BYTES

FMT_BYTES:

BUFFER

BUFFER: BYTES_BUFFER = "BYTES_BUFFER"

HEX

HEX: BYTES_HEX = "BYTES_HEX"

UINT8ARRAY

UINT8ARRAY: BYTES_UINT8ARRAY = "BYTES_UINT8ARRAY"

FMT_NUMBER

FMT_NUMBER:

BIGINT

BIGINT: NUMBER_BIGINT = "NUMBER_BIGINT"

HEX

HEX: NUMBER_HEX = "NUMBER_HEX"

NUMBER

NUMBER: NUMBER_NUMBER = "NUMBER_NUMBER"

STR

STR: NUMBER_STR = "NUMBER_STR"

Classes

ChunkResponseParser

ChunkResponseParser:

constructor

onError

  • onError(clearQueues?: () => void): void
  • Parameters

    • optionalclearQueues: () => void

    Returns void

parseResponse

abstractEip1193Provider

Eip1193Provider<API>:

Type parameters

constructor

[symbol]

  • get [symbol](): boolean
  • Returns boolean

abstractconnect

  • connect(): void
  • Returns void

abstractdisconnect

  • disconnect(code?: number, data?: string): void
  • Parameters

    • optionalcode: number
    • optionaldata: string

    Returns void

abstractgetStatus

abstracton

optionalabstractonce

optionalabstractremoveAllListeners

  • removeAllListeners(type: string): void
  • Parameters

    • type: string

    Returns void

abstractremoveListener

abstractrequest

abstractreset

  • reset(): void
  • Returns void

send

sendAsync

abstractsupportsSubscriptions

  • supportsSubscriptions(): boolean
  • Returns boolean

staticisWeb3Provider

  • isWeb3Provider(provider: unknown): boolean
  • Parameters

    • provider: unknown

    Returns boolean

abstractSocketProvider

SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>:

Type parameters

constructor

  • new SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>(socketPath: string, options?: object, reconnectOptions?: object): SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>
  • Type parameters

    Parameters

    • socketPath: string
    • optionaloptions: object
    • optionalreconnectOptions: object

    Returns SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>

[symbol]

  • get [symbol](): boolean
  • Returns boolean

connect

  • connect(): void
  • Returns void

disconnect

  • disconnect(code?: number, data?: string): void
  • Parameters

    • optionalcode: number
    • optionaldata: string

    Returns void

abstractgetStatus

on

once

removeAllListeners

  • removeAllListeners(type: string): void
  • Parameters

    • type: string

    Returns void

removeListener

request

reset

  • reset(): void
  • Returns void

send

sendAsync

supportsSubscriptions

  • supportsSubscriptions(): boolean
  • Returns boolean

staticisWeb3Provider

  • isWeb3Provider(provider: unknown): boolean
  • Parameters

    • provider: unknown

    Returns boolean

Web3DeferredPromise

Web3DeferredPromise<T>:

Type parameters

  • T

constructor

  • new Web3DeferredPromise<T>(__namedParameters?: { eagerStart: boolean; timeout: number; timeoutMessage: string }): Web3DeferredPromise<T>
  • Type parameters

    • T

    Parameters

    • optional__namedParameters: { eagerStart: boolean; timeout: number; timeoutMessage: string }

    Returns Web3DeferredPromise<T>

[toStringTag]

[toStringTag]: Promise

state

  • get state(): pending | fulfilled | rejected
  • Returns pending | fulfilled | rejected

catch

  • catch<TResult>(onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>
  • Type parameters

    • TResult

    Parameters

    • optionalonrejected: (reason: any) => TResult | PromiseLike<TResult>

    Returns Promise<T | TResult>

finally

  • finally(onfinally?: () => void): Promise<T>
  • Parameters

    • optionalonfinally: () => void

    Returns Promise<T>

reject

  • reject(reason?: unknown): void
  • Parameters

    • optionalreason: unknown

    Returns void

resolve

  • resolve(value: T | PromiseLike<T>): void
  • Parameters

    • value: T | PromiseLike<T>

    Returns void

startTimer

  • startTimer(): void
  • Returns void

then

  • then<TResult1, TResult2>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: unknown) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>
  • Type parameters

    • TResult1
    • TResult2

    Parameters

    • optionalonfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>
    • optionalonrejected: (reason: unknown) => TResult2 | PromiseLike<TResult2>

    Returns Promise<TResult1 | TResult2>

Type Aliases

AsyncFunction

AsyncFunction<T, K>: (...args: K[]) => Promise<T>

Type parameters

  • T
  • K = unknown

Type declaration

    • (...args: K[]): Promise<T>
    • Parameters

      • rest...args: K[]

      Returns Promise<T>

ByteTypes

ByteTypes: { BYTES_BUFFER: Buffer; BYTES_HEX: HexString; BYTES_UINT8ARRAY: Uint8Array }

Type declaration

  • BYTES_BUFFER: Buffer
  • BYTES_HEX: HexString
  • BYTES_UINT8ARRAY: Uint8Array

DataFormat

DataFormat: { bytes: FMT_BYTES; number: FMT_NUMBER }

Type declaration

EtherUnits

EtherUnits: keyof typeof ethUnitMap

FormatType

FormatType<T, F>: number extends Extract<T, Numbers> ? NumberTypes[F[number]] | Exclude<T, Numbers> : Buffer extends Extract<T, Bytes> ? ByteTypes[F[bytes]] | Exclude<T, Bytes> : T extends object | undefined ? { [ P in keyof T ]: FormatType<T[P], F> } : T

Type parameters

NumberTypes

NumberTypes: { NUMBER_BIGINT: bigint; NUMBER_HEX: HexString; NUMBER_NUMBER: number; NUMBER_STR: string }

Type declaration

  • NUMBER_BIGINT: bigint
  • NUMBER_HEX: HexString
  • NUMBER_NUMBER: number
  • NUMBER_STR: string

Variables

constDEFAULT_RETURN_FORMAT

DEFAULT_RETURN_FORMAT: { bytes: FMT_BYTES.HEX; number: FMT_NUMBER.BIGINT }

Type declaration

  • readonlybytes: FMT_BYTES.HEX
  • readonlynumber: FMT_NUMBER.BIGINT

constETH_DATA_FORMAT

ETH_DATA_FORMAT: { bytes: FMT_BYTES.HEX; number: FMT_NUMBER.HEX }

Type declaration

  • readonlybytes: FMT_BYTES.HEX
  • readonlynumber: FMT_NUMBER.HEX

constethUnitMap

ethUnitMap: { Gwei: bigint; Kwei: bigint; Mwei: bigint; babbage: bigint; ether: bigint; femtoether: bigint; finney: bigint; gether: bigint; grand: bigint; gwei: bigint; kether: bigint; kwei: bigint; lovelace: bigint; mether: bigint; micro: bigint; microether: bigint; milli: bigint; milliether: bigint; mwei: bigint; nano: bigint; nanoether: bigint; noether: bigint; picoether: bigint; shannon: bigint; szabo: bigint; tether: bigint; wei: bigint }

Type declaration

  • Gwei: bigint
  • Kwei: bigint
  • Mwei: bigint
  • babbage: bigint
  • ether: bigint
  • femtoether: bigint
  • finney: bigint
  • gether: bigint
  • grand: bigint
  • gwei: bigint
  • kether: bigint
  • kwei: bigint
  • lovelace: bigint
  • mether: bigint
  • micro: bigint
  • microether: bigint
  • milli: bigint
  • milliether: bigint
  • mwei: bigint
  • nano: bigint
  • nanoether: bigint
  • noether: bigint
  • picoether: bigint
  • shannon: bigint
  • szabo: bigint
  • tether: bigint
  • wei: bigint

Functions

asciiToHex

  • asciiToHex(str: string): string
  • Parameters

    • str: string

    Returns string

bytesToBuffer

  • bytesToBuffer(data: Bytes): Buffer
  • Parameters

    Returns Buffer

bytesToHex

  • bytesToHex(bytes: Bytes): string
  • Parameters

    Returns string

checkAddressCheckSum

  • checkAddressCheckSum(data: string): boolean
  • Parameters

    • data: string

    Returns boolean

compareBlockNumbers

convert

  • convert(data: unknown, schema: JsonSchema, dataPath: string[], format: DataFormat, oneOfPath?: [string, number][]): unknown
  • Parameters

    • data: unknown
    • schema: JsonSchema
    • dataPath: string[]
    • format: DataFormat
    • optionaloneOfPath: [string, number][]

    Returns unknown

convertScalarValue

  • convertScalarValue(value: unknown, ethType: string, format: DataFormat): unknown
  • Parameters

    Returns unknown

encodePacked

  • Parameters

    Returns string

format

fromAscii

  • fromAscii(str: string): string
  • Parameters

    • str: string

    Returns string

fromDecimal

  • fromDecimal(value: Numbers): string
  • Parameters

    Returns string

fromTwosComplement

  • fromTwosComplement(value: Numbers, nibbleWidth?: number): number | bigint
  • Parameters

    • value: Numbers
    • optionalnibbleWidth: number

    Returns number | bigint

fromUtf8

  • fromUtf8(str: string): string
  • Parameters

    • str: string

    Returns string

fromWei

  • fromWei(number: Numbers, unit: noether | wei | kwei | Kwei | babbage | femtoether | mwei | Mwei | lovelace | picoether | gwei | Gwei | shannon | nanoether | nano | szabo | microether | micro | finney | milliether | milli | ether | kether | grand | mether | gether | tether): string
  • Parameters

    • number: Numbers
    • unit: noether | wei | kwei | Kwei | babbage | femtoether | mwei | Mwei | lovelace | picoether | gwei | Gwei | shannon | nanoether | nano | szabo | microether | micro | finney | milliether | milli | ether | kether | grand | mether | gether | tether

    Returns string

getStorageSlotNumForLongString

  • getStorageSlotNumForLongString(mainSlotNumber: string | number): undefined | string
  • Parameters

    • mainSlotNumber: string | number

    Returns undefined | string

hexToAscii

  • hexToAscii(str: string): string
  • Parameters

    • str: string

    Returns string

hexToBytes

  • hexToBytes(bytes: string): Buffer
  • Parameters

    • bytes: string

    Returns Buffer

hexToNumber

  • hexToNumber(value: string): number | bigint
  • Parameters

    • value: string

    Returns number | bigint

hexToNumberString

  • hexToNumberString(data: string): string
  • Parameters

    • data: string

    Returns string

hexToString

  • hexToString(str: string): string
  • Parameters

    • str: string

    Returns string

hexToUtf8

  • hexToUtf8(str: string): string
  • Parameters

    • str: string

    Returns string

isAddress

  • Parameters

    Returns boolean

isBatchRequest

isBatchResponse

isBloom

isContractAddressInBloom

  • isContractAddressInBloom(bloom: string, contractAddress: string): boolean
  • Parameters

    • bloom: string
    • contractAddress: string

    Returns boolean

isDataFormat

  • isDataFormat(dataFormat: unknown): dataFormat is DataFormat
  • Parameters

    • dataFormat: unknown

    Returns dataFormat is DataFormat

isHex

isHexStrict

isInBloom

  • isInBloom(bloom: string, value: string | Uint8Array): boolean
  • Parameters

    • bloom: string
    • value: string | Uint8Array

    Returns boolean

isNullish

  • isNullish(item: unknown): item is undefined | null
  • Parameters

    • item: unknown

    Returns item is undefined | null

isPromise

  • isPromise(object: unknown): boolean
  • Parameters

    • object: unknown

    Returns boolean

isResponseRpcError

isResponseWithError

isResponseWithNotification

isResponseWithResult

isSubscriptionResult

isTopic

  • isTopic(topic: string): boolean
  • Parameters

    • topic: string

    Returns boolean

isTopicInBloom

  • isTopicInBloom(bloom: string, topic: string): boolean
  • Parameters

    • bloom: string
    • topic: string

    Returns boolean

isUserEthereumAddressInBloom

  • isUserEthereumAddressInBloom(bloom: string, ethereumAddress: string): boolean
  • Parameters

    • bloom: string
    • ethereumAddress: string

    Returns boolean

isValidResponse

  • isValidResponse<Result, Error_1>(response: JsonRpcResponse<Result, Error_1>): boolean
  • Type parameters

    • Result = unknown
    • Error_1 = unknown

    Parameters

    Returns boolean

keccak256Wrapper

  • keccak256Wrapper(data: string | number | bigint | Buffer | ArrayBuffer | Uint8Array | readonly number[]): string
  • Parameters

    • data: string | number | bigint | Buffer | ArrayBuffer | Uint8Array | readonly number[]

    Returns string

leftPad

  • leftPad(value: Numbers, characterAmount: number, sign?: string): string
  • Parameters

    • value: Numbers
    • characterAmount: number
    • optionalsign: string

    Returns string

mergeDeep

  • mergeDeep(destination: Record<string, unknown>, ...sources: Record<string, unknown>[]): Record<string, unknown>
  • Parameters

    • destination: Record<string, unknown>
    • rest...sources: Record<string, unknown>[]

    Returns Record<string, unknown>

numberToHex

  • numberToHex(value: Numbers): string
  • Parameters

    Returns string

padLeft

  • padLeft(value: Numbers, characterAmount: number, sign?: string): string
  • Parameters

    • value: Numbers
    • characterAmount: number
    • optionalsign: string

    Returns string

padRight

  • padRight(value: Numbers, characterAmount: number, sign?: string): string
  • Parameters

    • value: Numbers
    • characterAmount: number
    • optionalsign: string

    Returns string

pollTillDefined

  • pollTillDefined<T>(func: AsyncFunction<T, unknown>, interval: number): Promise<Exclude<T, undefined>>
  • Type parameters

    • T

    Parameters

    Returns Promise<Exclude<T, undefined>>

processSolidityEncodePackedArgs

  • processSolidityEncodePackedArgs(arg: Sha3Input): string

randomBytes

  • randomBytes(byteSize: number): Buffer
  • Parameters

    • byteSize: number

    Returns Buffer

randomHex

  • randomHex(byteSize: number): string
  • Parameters

    • byteSize: number

    Returns string

rejectIfConditionAtInterval

  • rejectIfConditionAtInterval<T>(cond: AsyncFunction<undefined | T, unknown>, interval: number): [NodeJS.Timer, Promise<never>]
  • Type parameters

    • T

    Parameters

    Returns [NodeJS.Timer, Promise<never>]

rejectIfTimeout

  • rejectIfTimeout(timeout: number, error: Error): [NodeJS.Timer, Promise<never>]
  • Parameters

    • timeout: number
    • error: Error

    Returns [NodeJS.Timer, Promise<never>]

rightPad

  • rightPad(value: Numbers, characterAmount: number, sign?: string): string
  • Parameters

    • value: Numbers
    • characterAmount: number
    • optionalsign: string

    Returns string

setRequestIdStart

  • setRequestIdStart(start: undefined | number): void
  • Parameters

    • start: undefined | number

    Returns void

sha3

  • sha3(data: Bytes): undefined | string
  • Parameters

    Returns undefined | string

sha3Raw

  • sha3Raw(data: Bytes): string
  • Parameters

    Returns string

soliditySha3

  • soliditySha3(...values: Sha3Input[]): undefined | string
  • Parameters

    Returns undefined | string

soliditySha3Raw

stringToHex

  • stringToHex(str: string): string
  • Parameters

    • str: string

    Returns string

toAscii

  • toAscii(str: string): string
  • Parameters

    • str: string

    Returns string

toBatchPayload

toBigInt

  • toBigInt(value: unknown): bigint
  • Parameters

    • value: unknown

    Returns bigint

toChecksumAddress

  • toChecksumAddress(address: string): string
  • Parameters

    • address: string

    Returns string

toDecimal

  • toDecimal(value: string): number | bigint
  • Parameters

    • value: string

    Returns number | bigint

toHex

  • toHex(value: string | number | bigint | boolean | object | Buffer | ArrayBuffer | Uint8Array, returnType?: boolean): string
  • Parameters

    • value: string | number | bigint | boolean | object | Buffer | ArrayBuffer | Uint8Array
    • optionalreturnType: boolean

    Returns string

toNumber

  • toNumber(value: Numbers): number | bigint
  • Parameters

    Returns number | bigint

toPayload

toTwosComplement

  • toTwosComplement(value: Numbers, nibbleWidth?: number): string
  • Parameters

    • value: Numbers
    • optionalnibbleWidth: number

    Returns string

toUtf8

  • toUtf8(str: string): string
  • Parameters

    • str: string

    Returns string

toWei

  • toWei(number: Numbers, unit: noether | wei | kwei | Kwei | babbage | femtoether | mwei | Mwei | lovelace | picoether | gwei | Gwei | shannon | nanoether | nano | szabo | microether | micro | finney | milliether | milli | ether | kether | grand | mether | gether | tether): string
  • Parameters

    • number: Numbers
    • unit: noether | wei | kwei | Kwei | babbage | femtoether | mwei | Mwei | lovelace | picoether | gwei | Gwei | shannon | nanoether | nano | szabo | microether | micro | finney | milliether | milli | ether | kether | grand | mether | gether | tether

    Returns string

utf8ToHex

  • utf8ToHex(str: string): string
  • Parameters

    • str: string

    Returns string

uuidV4

  • uuidV4(): string
  • Returns string

validateResponse

  • validateResponse<Result, Error_1>(response: JsonRpcResponse<Result, Error_1>): boolean
  • Type parameters

    • Result = unknown
    • Error_1 = unknown

    Parameters

    Returns boolean

waitWithTimeout

  • waitWithTimeout<T>(awaitable: Promise<T> | AsyncFunction<T, unknown>, timeout: number, error: Error): Promise<T>
  • waitWithTimeout<T>(awaitable: Promise<T> | AsyncFunction<T, unknown>, timeout: number): Promise<T | undefined>
  • Type parameters

    • T

    Parameters

    • awaitable: Promise<T> | AsyncFunction<T, unknown>
    • timeout: number
    • error: Error

    Returns Promise<T>