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
: TinyBig
; difficulty
: TinyBig
; gasLimit
: TinyBig
; gasUsed
: TinyBig
; nonce
: TinyBig
; number
: number
; size
: TinyBig
; timestamp
: TinyBig
; totalDifficulty
: TinyBig
; transactions
: (string
| BlockTransactionResponse
)[] }>
Defined in
src/types/Block.types.ts:9
BlockTag
Ƭ BlockTag: "latest"
| "earliest"
| "pending"
| number
| string
Defined in
src/types/Block.types.ts:50
BlockTransactionResponse
Ƭ BlockTransactionResponse: Omit
<TransactionResponse
, "maxFeePerGas"
| "maxPriorityFeePerGas"
>
Defined in
src/types/Transaction.types.ts:95
Bytes
Ƭ Bytes: ArrayLike
<number
>
Defined in
src/utils/bytes.ts:7
BytesLike
Ƭ BytesLike: Bytes
| string
example
[1,2,3]
example
0x123
example
'0x123'
Defined in
src/utils/bytes.ts:18
BytesLikeWithNumber
Ƭ BytesLikeWithNumber: BytesLike
| number
Defined in
src/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]"
| "uint256"
| "uint256[100]"
| "uint8"
| "uint32"
| string
Defined in
src/types/Contract.types.ts:1
JSONABI
Ƭ JSONABI: JSONABIArgument
[]
Defined in
src/types/Contract.types.ts:67
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
src/types/Transaction.types.ts:86
SignatureLike
Ƭ SignatureLike: { _vs?
: string
; r
: string
; recoveryParam?
: number
; s?
: string
; v?
: number
} | BytesLike
Defined in
src/utils/bytes.ts:30
TransactionReceipt
Ƭ TransactionReceipt: Modify
<RPCTransactionReceipt
, { blockNumber
: number
; cumulativeGasUsed
: TinyBig
; effectiveGasPrice
: TinyBig
; gasUsed
: TinyBig
; 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
src/types/Transaction.types.ts:38
TransactionResponse
Ƭ TransactionResponse: Modify
<RPCTransaction
, { blockNumber
: number
; chainId
: number
; gas
: TinyBig
; gasLimit
: TinyBig
; gasPrice
: TinyBig
; nonce
: TinyBig
; transactionIndex
: number
; type
: number
; v
: number
; value
: TinyBig
} & { confirmations
: number
; maxFeePerGas
: TinyBig
; maxPriorityFeePerGas
: TinyBig
}>
Defined in
src/types/Transaction.types.ts:13
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 | 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
src/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
src/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
src/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
src/utils/bytes.ts:258
etherToGwei
▸ etherToGwei(etherQuantity
): TinyBig
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'
example
etherToGwei('1000').toNumber()
// 1000000000000
etherToGwei(1000).toNumber()
// 1000000000000
Parameters
Name | Type | Description |
---|---|---|
etherQuantity | string | number | TinyBig | Big | the amount of ether to convert to gwei |
Returns
a number of gwei equivalent to the specified ether
Defined in
src/utils/ether-to-gwei.ts:30
etherToWei
▸ etherToWei(etherQuantity
): TinyBig
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'
example
etherToWei('1000').toNumber()
// 1000000000000000000000
etherToWei(1000).toNumber()
// 1000000000000000000000
Parameters
Name | Type | Description |
---|---|---|
etherQuantity | string | number | TinyBig | Big | the amount of ether to convert to wei |
Returns
a number of wei equivalent to the specified ether
Defined in
src/utils/ether-to-wei.ts:30
gweiToEther
▸ gweiToEther(gweiQuantity
): TinyBig
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').toString()
// '1000'
gweiToEther(1000000000000).toString()
// '1000'
example
gweiToEther('1000000000000').toNumber()
// 1000
gweiToEther(1000000000000).toNumber()
// 1000
Parameters
Name | Type | Description |
---|---|---|
gweiQuantity | string | number | TinyBig | Big | the amount of gwei to convert to ether |
Returns
a number of ether equivalent to the specified gwei
Defined in
src/utils/gwei-to-ether.ts:30
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
src/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
src/utils/bytes.ts:525
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
src/utils/bytes.ts:471
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
src/utils/bytes.ts:494
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
src/utils/bytes.ts:568
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
src/utils/bytes.ts:549
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
src/utils/bytes.ts:612
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
src/utils/bytes.ts:383
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
src/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
src/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
src/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
src/utils/bytes.ts:354
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
src/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
src/utils/keccak256.ts:18
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
src/utils/solidity-keccak256.ts:115
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
src/utils/solidity-keccak256.ts:153
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
src/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
src/utils/bytes.ts:283
tinyBig
▸ tinyBig(value
): TinyBig
Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
example
tinyBig(10).times(3).toNumber()
// 30
Parameters
Name | Type | Description |
---|---|---|
value | string | number | TinyBig | Big | the value to initiate the TinyBig with |
Returns
an initiated TinyBig
Defined in
src/shared/tiny-big/tiny-big.ts:102
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
src/utils/to-checksum-address.ts:20
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
src/utils/to-utf8-bytes.ts:15
weiToEther
▸ weiToEther(weiQuantity
): TinyBig
Convert from Wei to Ether
Similar to "formatEther" in ethers.js
Similar to "fromWei" in web3.js
example
weiToEther('1000000000000000000000').toString()
// '1000'
weiToEther(1000000000000000000000).toString()
// '1000'
example
weiToEther('1000000000000000000000').toNumber()
// 1000
weiToEther(1000000000000000000000).toNumber()
// 1000
Parameters
Name | Type | Description |
---|---|---|
weiQuantity | string | number | TinyBig | Big | the amount of wei to convert to ether |
Returns
a number of ether equivalent to the specified wei
Defined in
src/utils/wei-to-ether.ts:30
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
src/utils/bytes.ts:322