essential-eth
Classes
Interfaces
- ConstructorOptions
- DataOptions
- Filter
- FilterByBlockHash
- Hexable
- JSONABIArgument
- Network
- RPCBlock
- RPCLog
- RPCTransaction
- RPCTransactionReceipt
- RPCTransactionRequest
- Signature
- TransactionRequest
Type aliases
BlockResponse
Ƭ BlockResponse: Modify<RPCBlock, { baseFeePerGas: bigint ; difficulty: bigint ; gasLimit: bigint ; gasUsed: bigint ; nonce: bigint ; number: number ; size: bigint ; timestamp: bigint ; totalDifficulty: bigint ; transactions: (string | BlockTransactionResponse)[] }>
Defined in
types/Block.types.ts:8
BlockTag
Ƭ BlockTag: "latest" | "earliest" | "pending" | number | string
Defined in
types/Block.types.ts:49
BlockTransactionResponse
Ƭ BlockTransactionResponse: Omit<TransactionResponse, "maxFeePerGas" | "maxPriorityFeePerGas">
Defined in
types/Transaction.types.ts:93
Bytes
Ƭ Bytes: ArrayLike<number>
Defined in
utils/bytes.ts:7
BytesLike
Ƭ BytesLike: Bytes | string
example
[1,2,3]
example
0x123
example
'0x123'
Defined in
utils/bytes.ts:18
BytesLikeWithNumber
Ƭ BytesLikeWithNumber: BytesLike | number
Defined in
utils/bytes.ts:19
ContractTypes
Ƭ ContractTypes: "bool" | "bytes1" | "bytes2" | "bytes3" | "bytes4" | "bytes5" | "bytes6" | "bytes7" | "bytes8" | "bytes9" | "bytes10" | "bytes11" | "bytes12" | "bytes13" | "bytes14" | "bytes15" | "bytes16" | "bytes17" | "bytes18" | "bytes19" | "bytes20" | "bytes21" | "bytes22" | "bytes23" | "bytes24" | "bytes25" | "bytes26" | "bytes27" | "bytes28" | "bytes29" | "bytes30" | "bytes31" | "bytes32" | "bytes32[]" | "address" | "address payable" | "address[4]" | "address[100]" | "uint8" | "uint16" | "uint24" | "uint32" | "uint40" | "uint48" | "uint56" | "uint64" | "uint72" | "uint80" | "uint88" | "uint96" | "uint104" | "uint112" | "uint120" | "uint128" | "uint136" | "uint144" | "uint152" | "uint160" | "uint168" | "uint176" | "uint184" | "uint192" | "uint200" | "uint208" | "uint216" | "uint224" | "uint232" | "uint240" | "uint248" | "uint256" | "uint256[100]" | "int8" | "int16" | "int24" | "int32" | "int40" | "int48" | "int56" | "int64" | "int72" | "int80" | "int88" | "int96" | "int104" | "int112" | "int120" | "int128" | "int136" | "int144" | "int152" | "int160" | "int168" | "int176" | "int184" | "int192" | "int200" | "int208" | "int216" | "int224" | "int232" | "int240" | "int248" | "int256" | string
Defined in
types/Contract.types.ts:1
JSONABI
Ƭ JSONABI: JSONABIArgument[]
Defined in
types/Contract.types.ts:128
Log
Ƭ Log: Modify<RPCLog, { blockNumber: number ; logIndex: number ; transactionIndex: number }>
Type for the logs that are included in transaction receipts
Similar to Type Log on ethers.providers
Defined in
types/Transaction.types.ts:84
SignatureLike
Ƭ SignatureLike: { _vs?: string ; r: string ; recoveryParam?: number ; s?: string ; v?: number } | BytesLike
Defined in
utils/bytes.ts:30
TransactionReceipt
Ƭ TransactionReceipt: Modify<RPCTransactionReceipt, { blockNumber: number ; cumulativeGasUsed: bigint ; effectiveGasPrice: bigint ; gasUsed: bigint ; logs: Log[] ; status: number ; transactionIndex: number ; type: number } & { byzantium: boolean ; confirmations: number }>
Type that contains information from the receipt of a transaction
- Similar to
Type TransactionReceipt on ethers.providers
Defined in
types/Transaction.types.ts:36
TransactionResponse
Ƭ TransactionResponse: Modify<RPCTransaction, { blockNumber: number ; chainId: number ; gas: bigint ; gasLimit: bigint ; gasPrice: bigint ; nonce: bigint ; transactionIndex: number ; type: number ; v: number ; value: bigint } & { confirmations: number ; maxFeePerGas: bigint ; maxPriorityFeePerGas: bigint }>
Defined in
types/Transaction.types.ts:11
Functions
arrayify
▸ arrayify(value, options?): Uint8Array
Converts DataHexStringOrArrayish to a Uint8Array
Same as ethers.utils.arrayify
example
arrayify(1);
// Uint8Array(1) [ 1 ]
example
arrayify(0x1234);
// Uint8Array(2) [ 18, 52 ]
example
arrayify('0x1', { hexPad: 'right' });
// Uint8Array(1) [ 16 ]
Parameters
| Name | Type | Description |
|---|---|---|
value | number | bigint | BytesLike | Hexable | the value to convert to a Uint8Array |
options? | DataOptions | options to use when converting the value to a Uint8Array |
Returns
Uint8Array
the value represented as a Uint8Array
Defined in
utils/bytes.ts:184
computeAddress
▸ computeAddress(key): string
Computes the address that corresponds to a specified public or private key
example
computeAddress('0x0458eb591f407aef12936bd2989ca699cf5061de9c4964dd6eb6005fd8f580c407434447e813969a1be6e9954b002cad84dfc67a69e032b273e4695e7d0db2d952'); // public key
// '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
example
computeAddress('0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427'); // private key
// '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
Parameters
| Name | Type | Description |
|---|---|---|
key | string | the public or private key to find the address related to |
Returns
string
the address that corresponds to the key specified
Defined in
utils/compute-address.ts:22
computePublicKey
▸ computePublicKey(privKey): string
Computes the public key from a given private key
example
computePublicKey('0xb27cc8dea0177d910110e8d3ec5480d56c723abf433529f4063f261ffdb9297c');
// '0x045cd0032015eecfde49f82f4e149d804e8ac6e3a0bface32e37c72a71ceac864fe84da7e8df84342f7b11dfb753c4d158f636142b46b29cf7f0f171ae0aa4fb87'
example
computePublicKey([50,102,50,99,52,49,57,97,99,102,52,97,49,100,97,56,99,49,101,98,101,97,55,53,98,98,51,102,99,102,98,100]);
// '0x04a9cea77eca949df84f661cee153426fb51f2294b9364b4fac240df57360b9b0ac9c99e4d7966491ab4c81f8c82e0cd24ec5759832ad4ab736d22c7d90b806ee8'
Parameters
| Name | Type | Description |
|---|---|---|
privKey | BytesLike | the private key to find a public key from |
Returns
string
the public key related to the specified private key
Defined in
utils/compute-public-key.ts:21
concat
▸ concat(arrayOfBytesLike): Uint8Array
Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
Same as ethers.utils.concat
example
concat([0, 1]);
// Uint8Array(2) [ 0, 1 ]
Parameters
| Name | Type | Description |
|---|---|---|
arrayOfBytesLike | readonly BytesLikeWithNumber[] | the array of BytesLike to concatenate together |
Returns
Uint8Array
a concatenated Uint8Array
Defined in
utils/bytes.ts:268
decodeBytes32String
▸ decodeBytes32String(bytes32): string
Decode a bytes32 hex value into a string, stripping trailing null bytes.
Similar to "decodeBytes32String" in ethers.js v6
example
decodeBytes32String('0x657373656e7469616c2d657468000000000000000000000000000000000000')
// 'essential-eth'
Parameters
| Name | Type | Description |
|---|---|---|
bytes32 | string | the bytes32 hex string to decode |
Returns
string
the decoded string
Defined in
utils/bytes32-string.ts:43
encodeBytes32String
▸ encodeBytes32String(text): string
Encode a string as a bytes32 hex value. The string must be 31 bytes or shorter, as one byte is used for the null terminator in Solidity.
Similar to "encodeBytes32String" in ethers.js v6
example
encodeBytes32String('essential-eth')
// '0x657373656e7469616c2d657468000000000000000000000000000000000000'
Parameters
| Name | Type | Description |
|---|---|---|
text | string | the string to encode (max 31 bytes UTF-8) |
Returns
string
a 66-character hex string (bytes32)
Defined in
utils/bytes32-string.ts:19
etherToGwei
▸ etherToGwei(etherQuantity): bigint
Convert from Ether to Gwei
No direct equivalent in ether.js; requires multiple functions to achieve.
No direct equivalent in web3; requires multiple functions to achieve.
example
etherToGwei('1000').toString()
// '1000000000000'
etherToGwei(1000).toString()
// '1000000000000'
Parameters
| Name | Type | Description |
|---|---|---|
etherQuantity | string | number | bigint | the amount of ether to convert to gwei |
Returns
bigint
a bigint of gwei equivalent to the specified ether
Defined in
utils/ether-to-gwei.ts:21
etherToWei
▸ etherToWei(etherQuantity): bigint
Convert Ether to Wei
Similar to "parseEther" in ethers.js
Similar to "toWei" in web3.js
example
etherToWei('1000').toString()
// '1000000000000000000000'
etherToWei(1000).toString()
// '1000000000000000000000'
Parameters
| Name | Type | Description |
|---|---|---|
etherQuantity | string | number | bigint | the amount of ether to convert to wei |
Returns
bigint
a bigint of wei equivalent to the specified ether
Defined in
utils/ether-to-wei.ts:21
formatUnits
▸ formatUnits(value, decimals?): string
Format a value in the smallest unit (e.g. wei) as a decimal string with the given number of decimal places.
Similar to "formatUnits" in ethers.js
Similar to "formatUnits" in viem
example
formatUnits(1000000n, 6)
// '1'
example
formatUnits('1000000000000000000', 18)
// '1'
example
formatUnits(1500000n, 6)
// '1.5'
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
value | string | number | bigint | undefined | the value to format (in smallest unit) |
decimals | number | 18 | the number of decimal places (default 18) |
Returns
string
a decimal string representation
Defined in
utils/format-units.ts:30
getAddress
▸ getAddress(address): string
Returns the checksummed address for the given address. Throws if the address is invalid.
This is an alias for toChecksumAddress, provided for compatibility
with ethers.js getAddress.
example
getAddress('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
// '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
Parameters
| Name | Type | Description |
|---|---|---|
address | string | the address to checksum |
Returns
string
the checksummed address
Defined in
utils/get-address.ts:18
gweiToEther
▸ gweiToEther(gweiQuantity): string
Convert from Gwei to Ether
No direct equivalent in ethers.js; requires multiple functions to achieve.
No direct equivalent in web3; requires multiple functions to achieve.
example
gweiToEther('1000000000000')
// '1000'
gweiToEther(1000000000000)
// '1000'
Parameters
| Name | Type | Description |
|---|---|---|
gweiQuantity | string | number | bigint | the amount of gwei to convert to ether |
Returns
string
a string decimal representation of ether equivalent to the specified gwei
Defined in
utils/gwei-to-ether.ts:21
hashMessage
▸ hashMessage(message): string
Computes the EIP-191 personal message digest of message. Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
example
hashMessage("Hello World");
// '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
Parameters
| Name | Type | Description |
|---|---|---|
message | string | Bytes | the message to hash |
Returns
string
a message hashed using Keccak256 that matches the EIP-191 standard
Defined in
utils/hash-message.ts:20
hexConcat
▸ hexConcat(items): string
Concatenates values together into one hex string
example
hexConcat([[2, 4, 0, 1], 9, '0x2934', '0x3947']);
// '0x020400010929343947'
Parameters
| Name | Type | Description |
|---|---|---|
items | readonly BytesLike[] | the items to concatenate together |
Returns
string
a single hex string including all of the items to be concatenated
Defined in
utils/bytes.ts:535
hexDataLength
▸ hexDataLength(data): null | number
Gets the length of data represented as a hex string
example
hexDataLength([2, 4, 0, 1]);
// 4
example
hexDataLength('0x3925');
// 2
Parameters
| Name | Type | Description |
|---|---|---|
data | BytesLike | the data to check the length of |
Returns
null | number
the length of the data
Defined in
utils/bytes.ts:481
hexDataSlice
▸ hexDataSlice(data, offset, endOffset?): string
Slices a BytesLike to extract a certain part of the input
example
hexDataSlice([20, 6, 48], 0, 2);
// '0x1406'
Parameters
| Name | Type | Description |
|---|---|---|
data | BytesLikeWithNumber | the data to slice from |
offset | number | the index to start extraction at |
endOffset? | number | the index to end extraction at |
Returns
string
the extracted data as a hex string
Defined in
utils/bytes.ts:504
hexStripZeros
▸ hexStripZeros(value): string
Strips the leading zeros from a value and returns it as a hex string
example
hexStripZeros([0,0,0,48]);
// '0x30'
Parameters
| Name | Type | Description |
|---|---|---|
value | BytesLike | the value to strip zeros from |
Returns
string
a hex string representation of the value, without leading zeros
Defined in
utils/bytes.ts:578
hexValue
▸ hexValue(value): string
Converts a number of different types into a hex string
example
hexValue(39);
// '0x27'
example
hexValue([9, 4, 19, 4]);
// '0x9041304'
Parameters
| Name | Type | Description |
|---|---|---|
value | number | bigint | BytesLike | Hexable | the value to convert into a hex string |
Returns
string
the value represented as a hex string
Defined in
utils/bytes.ts:559
hexZeroPad
▸ hexZeroPad(value, length): string
Returns a hex string padded to a specified length of bytes.
Similar to "hexZeroPad" in ethers.js
Differs from "padLeft" in web3.js because web3 counts by characters, not bytes.
throws If the value is not a hex string or number
throws If the value is longer than the length
example
hexZeroPad('0x60', 2);
// '0x0060'
example
hexZeroPad(0x60, 3);
// '0x000060'
example
hexZeroPad('12345', 1);
// Throws
Parameters
| Name | Type | Description |
|---|---|---|
value | BytesLikeWithNumber | A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded |
length | number | The final length in bytes |
Returns
string
A hex string padded to the specified length
Defined in
utils/bytes.ts:622
hexlify
▸ hexlify(value, options?): string
Converts a value into a hex string
example
hexlify(4);
// '0x04'
example
hexlify(14);
// '0x0e'
Parameters
| Name | Type | Description |
|---|---|---|
value | number | bigint | BytesLike | Hexable | the value to convert |
options? | DataOptions | options to use when converting the value to a hex string |
Returns
string
the value represented as a hex string
Defined in
utils/bytes.ts:393
id
▸ id(text): string
Compute the keccak256 hash of a UTF-8 string. Commonly used to compute Solidity function selectors and event topic hashes.
Similar to "id" in ethers.js
example
id('Transfer(address,address,uint256)')
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
example
// Get a function selector (first 4 bytes)
id('balanceOf(address)').slice(0, 10)
// '0x70a08231'
Parameters
| Name | Type | Description |
|---|---|---|
text | string | the UTF-8 string to hash |
Returns
string
the keccak256 hash as a hex string
Defined in
utils/id.ts:24
isAddress
▸ isAddress(address): boolean
Returns a boolean as to whether the input is a valid address. Does NOT support ICAP addresses
example
isAddress('0xc0deaf6bd3f0c6574a6a625ef2f22f62a5150eab');
// true
example
isAddress('bad');
// false
example
// Does NOT support ENS.
isAddress('vitalik.eth');
// false
Parameters
| Name | Type | Description |
|---|---|---|
address | string | the address to check the validity of |
Returns
boolean
a boolean for whether the input is a valid address
Defined in
utils/is-address.ts:27
isBytes
▸ isBytes(value): value is Bytes
Returns true if and only if value is a valid Bytes
Same as ethers.utils.isBytes
example
isBytes([1,2,3]);
// true
example
isBytes(false);
// false
example
isBytes(new Uint8Array(1));
// true
Parameters
| Name | Type | Description |
|---|---|---|
value | any | the value to check whether or not it matches Bytes |
Returns
value is Bytes
whether or not the value matches Bytes
Defined in
utils/bytes.ts:137
isBytesLike
▸ isBytesLike(value): value is BytesLike
Returns true if and only if value is a valid Bytes or DataHexString
Same as ethers.utils.isBytesLike
example
isBytesLike([1,2,3]);
// true
example
isBytesLike(false);
// false
example
isBytesLike(new Uint8Array(1));
// true
Parameters
| Name | Type | Description |
|---|---|---|
value | any | the value to check whether or not it matches BytesLike |
Returns
value is BytesLike
whether or not the value matches BytesLike
Defined in
utils/bytes.ts:91
isHexString
▸ isHexString(value, length?): boolean
Returns true if and only if object is a valid hex string.
If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
Same as ethers.utils.isHexString
example
isHexString('0x4924');
// true
example
isHexString('0x4924', 4);
// false
// length of 4 in bytes would mean a hex string with 8 characters
Parameters
| Name | Type | Description |
|---|---|---|
value | any | the value to check whether or not it's a hex string |
length? | number | a length of bytes that the value should be equal to |
Returns
boolean
whether the value is a valid hex string (and optionally, whether it matches the length specified)
Defined in
utils/bytes.ts:364
jsonRpcProvider
▸ jsonRpcProvider(rpcUrl?): JsonRpcProvider
Helper function to avoid "new"
example
jsonRpcProvider().getBlock('latest').then(block => {
console.log(block.number);
})
// 14530496
Parameters
| Name | Type | Description |
|---|---|---|
rpcUrl? | string | the RPC URL to post requests to |
Returns
an initiated JsonRpcProvider
Defined in
providers/JsonRpcProvider.ts:42
keccak256
▸ keccak256(data): string
Hashes data into a Keccak256 hex string
example
keccak256('essential-eth');
// '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
keccak256('0x123');
// '0x5fa2358263196dbbf23d1ca7a509451f7a2f64c15837bfbb81298b1e3e24e4fa'
Parameters
| Name | Type | Description |
|---|---|---|
data | BytesLike | the data to be hashed using Keccak256 |
Returns
string
a hex string with data hashed using Keccak256
Defined in
utils/keccak256.ts:19
namehash
▸ namehash(name): string
Computes the ENS namehash of a domain name as defined in EIP-137.
The namehash algorithm recursively hashes each label of the domain name, producing a unique 32-byte identifier used by ENS contracts.
example
namehash('');
// '0x0000000000000000000000000000000000000000000000000000000000000000'
namehash('eth');
// '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae'
namehash('vitalik.eth');
// '0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835'
Parameters
| Name | Type | Description |
|---|---|---|
name | string | the ENS domain name to hash (e.g. 'vitalik.eth') |
Returns
string
the namehash as a 66-character hex string (0x-prefixed, 32 bytes)
Defined in
utils/namehash.ts:24
pack
▸ pack(types, values): string
Converts arrays with types and values into a hex string that can be hashed
example
const types = ['bool', 'string', 'uint64'];
const values = [true, 'text', 30];
pack(types, values);
// '0x0174657874000000000000001e'
Parameters
| Name | Type | Description |
|---|---|---|
types | readonly string[] | array of Solidity types, where type[0] is the type for value[0] |
values | readonly any[] | array of values, where value[0] is of type type[0] |
Returns
string
a hex string with the data given, packed to include its types
Defined in
utils/solidity-keccak256.ts:118
parseUnits
▸ parseUnits(value, decimals?): bigint
Parse a decimal string into the smallest unit (e.g. wei) as a bigint, given the number of decimal places.
Similar to "parseUnits" in ethers.js
Similar to "parseUnits" in viem
example
parseUnits('1', 6)
// 1000000n
example
parseUnits('1.5', 6)
// 1500000n
example
parseUnits('1', 18)
// 1000000000000000000n
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
value | string | undefined | the decimal string to parse |
decimals | number | 18 | the number of decimal places (default 18) |
Returns
bigint
a bigint in the smallest unit
Defined in
utils/parse-units.ts:30
solidityKeccak256
▸ solidityKeccak256(types, values): string
Hashes data from Solidity using the Keccak256 algorithm.
Similar to "solidityKeccak256" in ethers.js
example
const types = ['string', 'bool', 'uint32'];
const values = ['essential-eth is great', true, 14];
solidityKeccak256(types, values);
// '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
example
const types = ['bytes4', 'uint32[5]'];
const values = [[116, 101, 115, 116], [5, 3, 4, 9, 18]];
solidityKeccak256(types, values);
// '0x038707a887f09355dc545412b058e7ba8f3c74047050c7c5e5e52eec608053d9'
Parameters
| Name | Type | Description |
|---|---|---|
types | readonly string[] | Each Solidity type corresponding to the values passed in. Helps the function parse and pack data properly. |
values | readonly any[] | Data to be concatenated (combined) and then hashed. |
Returns
string
A Keccak256 hash (hex string) based on the values provided
Defined in
utils/solidity-keccak256.ts:156
splitSignature
▸ splitSignature(signature): Signature
Expands a signature into the full signature object and fills in missing properties.
Same as "splitSignature" in ethers.js
example
const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
splitSignature(signature);
{
r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
_vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
recoveryParam: 0,
v: 27,
yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
}
Parameters
| Name | Type | Description |
|---|---|---|
signature | SignatureLike | the signature object to split, parse, and compute missing properties from |
Returns
a full signature object with all properties filled
Defined in
utils/split-signature.ts:34
stripZeros
▸ stripZeros(value): Uint8Array
Strips leading zeros from a BytesLike object
example
stripZeros('0x00002834');
// Uint8Array { [Iterator] 0: 40, 1: 52 }
// Equivalent to '0x2834'
Parameters
| Name | Type | Description |
|---|---|---|
value | BytesLike | the value to strip leading zeros from |
Returns
Uint8Array
value without leading zeroes, expressed as a Uint8Array
Defined in
utils/bytes.ts:293
toChecksumAddress
▸ toChecksumAddress(address): string
Returns an Ethereum address in proper mixed-case checksum. Does NOT support ICAP
example
toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
// '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
Similar to "getAddress" in ethers.js
Similar to "toChecksumAddress" in web3.js
Parameters
| Name | Type | Description |
|---|---|---|
address | string | An Ethereum address. Mixed, lower, and uppercase are all valid |
Returns
string
a valid checksum address
Defined in
utils/to-checksum-address.ts:21
toUtf8Bytes
▸ toUtf8Bytes(data): Uint8Array
Converts a string into a UTF-8 Byte Array
example
toUtf8Bytes('essential-eth');
// Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
toUtf8Bytes('ethereum');
// Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
Parameters
| Name | Type | Description |
|---|---|---|
data | string | the input to be converted to a UTF-8 Byte Array |
Returns
Uint8Array
the specified data as a UTF-8 Byte Array
Defined in
utils/to-utf8-bytes.ts:15
toUtf8String
▸ toUtf8String(bytes): string
Decode a BytesLike value into a UTF-8 string.
Similar to "toUtf8String" in ethers.js
example
toUtf8String(new Uint8Array([101, 116, 104]))
// 'eth'
example
toUtf8String('0x657468')
// 'eth'
Parameters
| Name | Type | Description |
|---|---|---|
bytes | BytesLike | the bytes to decode |
Returns
string
the decoded UTF-8 string
Defined in
utils/to-utf8-string.ts:22
weiToEther
▸ weiToEther(weiQuantity): string
Convert from Wei to Ether
Similar to "formatEther" in ethers.js
Similar to "fromWei" in web3.js
example
weiToEther('1000000000000000000000')
// '1000'
weiToEther(1000000000000000000000)
// '1000'
Parameters
| Name | Type | Description |
|---|---|---|
weiQuantity | string | number | bigint | the amount of wei to convert to ether |
Returns
string
a string decimal representation of ether equivalent to the specified wei
Defined in
utils/wei-to-ether.ts:21
zeroPad
▸ zeroPad(value, length): Uint8Array
Pads the beginning of a BytesLike with zeros so it's the specified length as a Uint8Array
example
zeroPad('0x039284');
// Uint8Array { [Iterator] 0: 0, 1: 0, 2: 0, 3: 3, 4: 146, 5: 132 }
// Equivalent to 0x000000039284
example
zeroPad([39, 25, 103, 45], 5);
// Uint8Array { [Iterator] 0: 0, 1: 39, 2: 25, 3: 103, 4: 45 }
Parameters
| Name | Type | Description |
|---|---|---|
value | BytesLike | the value to pad |
length | number | the desired length of the value |
Returns
Uint8Array
the value padded with zeros to the specified length
Defined in
utils/bytes.ts:332