essential-eth 0.10.3 → 0.10.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2024 -0
- package/dist/index.d.cts +330 -0
- package/dist/index.d.ts +330 -0
- package/dist/index.js +1952 -0
- package/package.json +13 -14
- package/dist/cjs/classes/Contract.d.ts +0 -81
- package/dist/cjs/classes/Contract.js +0 -139
- package/dist/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
- package/dist/cjs/classes/test/Contract/crv-abi.js +0 -413
- package/dist/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
- package/dist/cjs/classes/test/Contract/ens-abi.js +0 -453
- package/dist/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
- package/dist/cjs/classes/test/Contract/fei-abi.js +0 -526
- package/dist/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
- package/dist/cjs/classes/test/Contract/foo-abi.js +0 -42
- package/dist/cjs/classes/test/Contract/jokerrace-abi.d.ts +0 -2
- package/dist/cjs/classes/test/Contract/jokerrace-abi.js +0 -22
- package/dist/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +0 -121
- package/dist/cjs/classes/utils/clean-block.d.ts +0 -120
- package/dist/cjs/classes/utils/clean-block.js +0 -160
- package/dist/cjs/classes/utils/clean-log.d.ts +0 -9
- package/dist/cjs/classes/utils/clean-log.js +0 -39
- package/dist/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -14
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +0 -53
- package/dist/cjs/classes/utils/clean-transaction.d.ts +0 -14
- package/dist/cjs/classes/utils/clean-transaction.js +0 -54
- package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +0 -16
- package/dist/cjs/classes/utils/encode-decode-transaction.js +0 -185
- package/dist/cjs/classes/utils/fetchers.d.ts +0 -53
- package/dist/cjs/classes/utils/fetchers.js +0 -85
- package/dist/cjs/classes/utils/hex-to-decimal.d.ts +0 -18
- package/dist/cjs/classes/utils/hex-to-decimal.js +0 -24
- package/dist/cjs/classes/utils/prepare-transaction.d.ts +0 -6
- package/dist/cjs/classes/utils/prepare-transaction.js +0 -47
- package/dist/cjs/index.d.ts +0 -24
- package/dist/cjs/index.js +0 -58
- package/dist/cjs/index.umd.js +0 -2
- package/dist/cjs/index.umd.js.map +0 -1
- package/dist/cjs/logger/logger.d.ts +0 -11
- package/dist/cjs/logger/logger.js +0 -37
- package/dist/cjs/logger/package-version.d.ts +0 -1
- package/dist/cjs/logger/package-version.js +0 -5
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/providers/AlchemyProvider.d.ts +0 -4
- package/dist/cjs/providers/AlchemyProvider.js +0 -11
- package/dist/cjs/providers/BaseProvider.d.ts +0 -374
- package/dist/cjs/providers/BaseProvider.js +0 -514
- package/dist/cjs/providers/FallthroughProvider.d.ts +0 -24
- package/dist/cjs/providers/FallthroughProvider.js +0 -74
- package/dist/cjs/providers/JsonRpcProvider.d.ts +0 -33
- package/dist/cjs/providers/JsonRpcProvider.js +0 -46
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +0 -152
- package/dist/cjs/providers/test/mock-of.d.ts +0 -8
- package/dist/cjs/providers/test/mock-of.js +0 -12
- package/dist/cjs/providers/test/rpc-urls.d.ts +0 -12
- package/dist/cjs/providers/test/rpc-urls.js +0 -27
- package/dist/cjs/providers/utils/chains-info.d.ts +0 -24
- package/dist/cjs/providers/utils/chains-info.js +0 -71
- package/dist/cjs/shared/tiny-big/helpers.d.ts +0 -17
- package/dist/cjs/shared/tiny-big/helpers.js +0 -97
- package/dist/cjs/shared/tiny-big/tiny-big.d.ts +0 -58
- package/dist/cjs/shared/tiny-big/tiny-big.js +0 -101
- package/dist/cjs/shared/validate-type.d.ts +0 -3
- package/dist/cjs/shared/validate-type.js +0 -9
- package/dist/cjs/types/Block.types.d.ts +0 -41
- package/dist/cjs/types/Block.types.js +0 -2
- package/dist/cjs/types/Contract.types.d.ts +0 -24
- package/dist/cjs/types/Contract.types.js +0 -2
- package/dist/cjs/types/FeeData.types.d.ts +0 -7
- package/dist/cjs/types/FeeData.types.js +0 -2
- package/dist/cjs/types/Filter.types.d.ts +0 -16
- package/dist/cjs/types/Filter.types.js +0 -2
- package/dist/cjs/types/Network.types.d.ts +0 -8
- package/dist/cjs/types/Network.types.js +0 -2
- package/dist/cjs/types/Transaction.types.d.ts +0 -123
- package/dist/cjs/types/Transaction.types.js +0 -2
- package/dist/cjs/utils/bytes.d.ts +0 -289
- package/dist/cjs/utils/bytes.js +0 -711
- package/dist/cjs/utils/compute-address.d.ts +0 -17
- package/dist/cjs/utils/compute-address.js +0 -34
- package/dist/cjs/utils/compute-public-key.d.ts +0 -18
- package/dist/cjs/utils/compute-public-key.js +0 -26
- package/dist/cjs/utils/ether-to-gwei.d.ts +0 -27
- package/dist/cjs/utils/ether-to-gwei.js +0 -35
- package/dist/cjs/utils/ether-to-wei.d.ts +0 -27
- package/dist/cjs/utils/ether-to-wei.js +0 -35
- package/dist/cjs/utils/gwei-to-ether.d.ts +0 -27
- package/dist/cjs/utils/gwei-to-ether.js +0 -35
- package/dist/cjs/utils/hash-message.d.ts +0 -14
- package/dist/cjs/utils/hash-message.js +0 -30
- package/dist/cjs/utils/is-address.d.ts +0 -24
- package/dist/cjs/utils/is-address.js +0 -39
- package/dist/cjs/utils/keccak256.d.ts +0 -16
- package/dist/cjs/utils/keccak256.js +0 -31
- package/dist/cjs/utils/solidity-keccak256.d.ts +0 -39
- package/dist/cjs/utils/solidity-keccak256.js +0 -138
- package/dist/cjs/utils/split-signature.d.ts +0 -24
- package/dist/cjs/utils/split-signature.js +0 -163
- package/dist/cjs/utils/to-checksum-address.d.ts +0 -17
- package/dist/cjs/utils/to-checksum-address.js +0 -46
- package/dist/cjs/utils/to-utf8-bytes.d.ts +0 -15
- package/dist/cjs/utils/to-utf8-bytes.js +0 -21
- package/dist/cjs/utils/wei-to-ether.d.ts +0 -27
- package/dist/cjs/utils/wei-to-ether.js +0 -45
- package/dist/esm/classes/Contract.d.ts +0 -11
- package/dist/esm/classes/Contract.js +0 -58
- package/dist/esm/classes/test/Contract/crv-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/crv-abi.js +0 -395
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/ens-abi.js +0 -435
- package/dist/esm/classes/test/Contract/fei-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/fei-abi.js +0 -521
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/foo-abi.js +0 -33
- package/dist/esm/classes/test/Contract/jokerrace-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/jokerrace-abi.js +0 -18
- package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/dist/esm/classes/test/Contract/uniswap-abi.js +0 -116
- package/dist/esm/classes/utils/clean-block.d.ts +0 -2
- package/dist/esm/classes/utils/clean-block.js +0 -35
- package/dist/esm/classes/utils/clean-log.d.ts +0 -2
- package/dist/esm/classes/utils/clean-log.js +0 -28
- package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +0 -2
- package/dist/esm/classes/utils/clean-transaction-receipt.js +0 -37
- package/dist/esm/classes/utils/clean-transaction.d.ts +0 -2
- package/dist/esm/classes/utils/clean-transaction.js +0 -36
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
- package/dist/esm/classes/utils/encode-decode-transaction.js +0 -143
- package/dist/esm/classes/utils/fetchers.d.ts +0 -15
- package/dist/esm/classes/utils/fetchers.js +0 -37
- package/dist/esm/classes/utils/hex-to-decimal.d.ts +0 -1
- package/dist/esm/classes/utils/hex-to-decimal.js +0 -3
- package/dist/esm/classes/utils/prepare-transaction.d.ts +0 -2
- package/dist/esm/classes/utils/prepare-transaction.js +0 -36
- package/dist/esm/index.d.ts +0 -24
- package/dist/esm/index.js +0 -19
- package/dist/esm/logger/logger.d.ts +0 -11
- package/dist/esm/logger/logger.js +0 -34
- package/dist/esm/logger/package-version.d.ts +0 -1
- package/dist/esm/logger/package-version.js +0 -1
- package/dist/esm/providers/AlchemyProvider.d.ts +0 -4
- package/dist/esm/providers/AlchemyProvider.js +0 -7
- package/dist/esm/providers/BaseProvider.d.ts +0 -26
- package/dist/esm/providers/BaseProvider.js +0 -137
- package/dist/esm/providers/FallthroughProvider.d.ts +0 -11
- package/dist/esm/providers/FallthroughProvider.js +0 -50
- package/dist/esm/providers/JsonRpcProvider.d.ts +0 -7
- package/dist/esm/providers/JsonRpcProvider.js +0 -15
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +0 -142
- package/dist/esm/providers/test/mock-of.d.ts +0 -1
- package/dist/esm/providers/test/mock-of.js +0 -1
- package/dist/esm/providers/test/rpc-urls.d.ts +0 -12
- package/dist/esm/providers/test/rpc-urls.js +0 -21
- package/dist/esm/providers/utils/chains-info.d.ts +0 -24
- package/dist/esm/providers/utils/chains-info.js +0 -67
- package/dist/esm/shared/tiny-big/helpers.d.ts +0 -1
- package/dist/esm/shared/tiny-big/helpers.js +0 -58
- package/dist/esm/shared/tiny-big/tiny-big.d.ts +0 -10
- package/dist/esm/shared/tiny-big/tiny-big.js +0 -45
- package/dist/esm/shared/validate-type.d.ts +0 -3
- package/dist/esm/shared/validate-type.js +0 -5
- package/dist/esm/types/Block.types.d.ts +0 -40
- package/dist/esm/types/Block.types.js +0 -1
- package/dist/esm/types/Contract.types.d.ts +0 -24
- package/dist/esm/types/Contract.types.js +0 -1
- package/dist/esm/types/FeeData.types.d.ts +0 -7
- package/dist/esm/types/FeeData.types.js +0 -1
- package/dist/esm/types/Filter.types.d.ts +0 -12
- package/dist/esm/types/Filter.types.js +0 -1
- package/dist/esm/types/Network.types.d.ts +0 -5
- package/dist/esm/types/Network.types.js +0 -1
- package/dist/esm/types/Transaction.types.d.ts +0 -113
- package/dist/esm/types/Transaction.types.js +0 -1
- package/dist/esm/utils/bytes.d.ts +0 -40
- package/dist/esm/utils/bytes.js +0 -245
- package/dist/esm/utils/compute-address.d.ts +0 -1
- package/dist/esm/utils/compute-address.js +0 -12
- package/dist/esm/utils/compute-public-key.d.ts +0 -2
- package/dist/esm/utils/compute-public-key.js +0 -6
- package/dist/esm/utils/ether-to-gwei.d.ts +0 -3
- package/dist/esm/utils/ether-to-gwei.js +0 -7
- package/dist/esm/utils/ether-to-wei.d.ts +0 -3
- package/dist/esm/utils/ether-to-wei.js +0 -7
- package/dist/esm/utils/gwei-to-ether.d.ts +0 -3
- package/dist/esm/utils/gwei-to-ether.js +0 -7
- package/dist/esm/utils/hash-message.d.ts +0 -2
- package/dist/esm/utils/hash-message.js +0 -14
- package/dist/esm/utils/is-address.d.ts +0 -1
- package/dist/esm/utils/is-address.js +0 -12
- package/dist/esm/utils/keccak256.d.ts +0 -2
- package/dist/esm/utils/keccak256.js +0 -13
- package/dist/esm/utils/solidity-keccak256.d.ts +0 -2
- package/dist/esm/utils/solidity-keccak256.js +0 -85
- package/dist/esm/utils/split-signature.d.ts +0 -2
- package/dist/esm/utils/split-signature.js +0 -126
- package/dist/esm/utils/to-checksum-address.d.ts +0 -1
- package/dist/esm/utils/to-checksum-address.js +0 -25
- package/dist/esm/utils/to-utf8-bytes.d.ts +0 -1
- package/dist/esm/utils/to-utf8-bytes.js +0 -3
- package/dist/esm/utils/wei-to-ether.d.ts +0 -3
- package/dist/esm/utils/wei-to-ether.js +0 -16
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
|
-
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
3
|
-
import { cleanTransaction } from './clean-transaction';
|
|
4
|
-
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
-
export function cleanBlock(block, returnTransactionObjects) {
|
|
6
|
-
const cleanedBlock = { ...block };
|
|
7
|
-
Object.keys(block).forEach((key) => {
|
|
8
|
-
if (!block[key])
|
|
9
|
-
return;
|
|
10
|
-
switch (key) {
|
|
11
|
-
case 'difficulty':
|
|
12
|
-
case 'totalDifficulty':
|
|
13
|
-
case 'gasLimit':
|
|
14
|
-
case 'gasUsed':
|
|
15
|
-
case 'size':
|
|
16
|
-
case 'timestamp':
|
|
17
|
-
case 'baseFeePerGas':
|
|
18
|
-
cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
|
|
19
|
-
break;
|
|
20
|
-
case 'number':
|
|
21
|
-
cleanedBlock[key] = Number(hexToDecimal(block[key]));
|
|
22
|
-
break;
|
|
23
|
-
case 'miner':
|
|
24
|
-
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
if (returnTransactionObjects) {
|
|
29
|
-
const txns = block.transactions;
|
|
30
|
-
txns.forEach((transaction, index) => {
|
|
31
|
-
cleanedBlock.transactions[index] = cleanTransaction(transaction);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return cleanedBlock;
|
|
35
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
2
|
-
import { hexToDecimal } from './hex-to-decimal';
|
|
3
|
-
export function cleanLog(log, receiptLog) {
|
|
4
|
-
const cleanedLog = {
|
|
5
|
-
...log,
|
|
6
|
-
};
|
|
7
|
-
Object.keys(log).forEach((key) => {
|
|
8
|
-
switch (key) {
|
|
9
|
-
case 'address':
|
|
10
|
-
cleanedLog[key] = toChecksumAddress(log[key]);
|
|
11
|
-
break;
|
|
12
|
-
case 'blockNumber':
|
|
13
|
-
case 'logIndex':
|
|
14
|
-
case 'transactionIndex':
|
|
15
|
-
cleanedLog[key] = Number(hexToDecimal(log[key]));
|
|
16
|
-
break;
|
|
17
|
-
case 'removed':
|
|
18
|
-
if (receiptLog) {
|
|
19
|
-
delete cleanedLog[key];
|
|
20
|
-
}
|
|
21
|
-
else if (log[key] == null) {
|
|
22
|
-
cleanedLog[key] === false;
|
|
23
|
-
}
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return cleanedLog;
|
|
28
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
|
-
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
3
|
-
import { cleanLog } from './clean-log';
|
|
4
|
-
import { cleanTransaction } from './clean-transaction';
|
|
5
|
-
import { hexToDecimal } from './hex-to-decimal';
|
|
6
|
-
export function cleanTransactionReceipt(transactionReceipt) {
|
|
7
|
-
const cleanedTransaction = cleanTransaction(transactionReceipt);
|
|
8
|
-
const cleanedTransactionReceipt = {
|
|
9
|
-
...cleanedTransaction,
|
|
10
|
-
};
|
|
11
|
-
Object.keys(transactionReceipt).forEach((key) => {
|
|
12
|
-
if (!transactionReceipt[key])
|
|
13
|
-
return;
|
|
14
|
-
switch (key) {
|
|
15
|
-
case 'status':
|
|
16
|
-
cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
|
|
17
|
-
break;
|
|
18
|
-
case 'contractAddress':
|
|
19
|
-
if (transactionReceipt[key]) {
|
|
20
|
-
cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
case 'cumulativeGasUsed':
|
|
24
|
-
case 'effectiveGasPrice':
|
|
25
|
-
case 'gasUsed':
|
|
26
|
-
cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
|
|
27
|
-
break;
|
|
28
|
-
case 'logs':
|
|
29
|
-
transactionReceipt[key].forEach((log, index) => {
|
|
30
|
-
cleanedTransactionReceipt[key][index] = cleanLog(log, true);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
cleanedTransactionReceipt.byzantium =
|
|
35
|
-
cleanedTransactionReceipt.blockNumber >= 4370000;
|
|
36
|
-
return cleanedTransactionReceipt;
|
|
37
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
|
-
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
3
|
-
import { hexToDecimal } from './hex-to-decimal';
|
|
4
|
-
export function cleanTransaction(transaction) {
|
|
5
|
-
const cleanedTransaction = {
|
|
6
|
-
...transaction,
|
|
7
|
-
};
|
|
8
|
-
Object.keys(transaction).forEach((key) => {
|
|
9
|
-
if (!transaction[key])
|
|
10
|
-
return;
|
|
11
|
-
switch (key) {
|
|
12
|
-
case 'blockNumber':
|
|
13
|
-
case 'chainId':
|
|
14
|
-
case 'transactionIndex':
|
|
15
|
-
case 'type':
|
|
16
|
-
case 'v':
|
|
17
|
-
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
18
|
-
break;
|
|
19
|
-
case 'from':
|
|
20
|
-
case 'to':
|
|
21
|
-
if (transaction[key]) {
|
|
22
|
-
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
23
|
-
}
|
|
24
|
-
break;
|
|
25
|
-
case 'value':
|
|
26
|
-
case 'gas':
|
|
27
|
-
case 'gasPrice':
|
|
28
|
-
case 'maxFeePerGas':
|
|
29
|
-
case 'maxPriorityFeePerGas':
|
|
30
|
-
case 'nonce':
|
|
31
|
-
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return cleanedTransaction;
|
|
36
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { JSONABIArgument } from '../../types/Contract.types';
|
|
2
|
-
export declare const hexFalse: string;
|
|
3
|
-
export declare function encodeData(jsonABIArgument: JSONABIArgument, args: any[]): string;
|
|
4
|
-
export declare function decodeRPCResponse(jsonABIArgument: JSONABIArgument, nodeResponse: string): string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig | (string | number | boolean | import("../../shared/tiny-big/tiny-big").TinyBig)[];
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Keccak } from 'sha3';
|
|
2
|
-
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
3
|
-
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
4
|
-
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
-
export const hexFalse = '0'.repeat(64);
|
|
6
|
-
const hexTrue = '0'.repeat(63) + '1';
|
|
7
|
-
function hexToUtf8(hex) {
|
|
8
|
-
let str = '';
|
|
9
|
-
let i = 0;
|
|
10
|
-
const l = hex.length;
|
|
11
|
-
if (hex.substring(0, 2) === '0x') {
|
|
12
|
-
i = 2;
|
|
13
|
-
}
|
|
14
|
-
for (; i < l; i += 2) {
|
|
15
|
-
const code = parseInt(hex.substr(i, 2), 16);
|
|
16
|
-
if (code === 0)
|
|
17
|
-
continue;
|
|
18
|
-
str += String.fromCharCode(code);
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
return decodeURIComponent(escape(str));
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function expandType(type) {
|
|
28
|
-
if (type === 'uint[]') {
|
|
29
|
-
return 'uint256[]';
|
|
30
|
-
}
|
|
31
|
-
if (type === 'int[]') {
|
|
32
|
-
return 'int256[]';
|
|
33
|
-
}
|
|
34
|
-
return type;
|
|
35
|
-
}
|
|
36
|
-
export function encodeData(jsonABIArgument, args) {
|
|
37
|
-
const hash = new Keccak(256);
|
|
38
|
-
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
|
|
39
|
-
const functionHash = hash.update(functionString).digest('hex');
|
|
40
|
-
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
41
|
-
let shouldValidateInputLength = true;
|
|
42
|
-
if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
|
|
43
|
-
shouldValidateInputLength = false;
|
|
44
|
-
}
|
|
45
|
-
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
46
|
-
throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
|
|
47
|
-
}
|
|
48
|
-
const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
|
|
49
|
-
if (input.type.includes('[')) {
|
|
50
|
-
const basicType = /([^[]*)\[.*$/g.exec(input.type)?.[1];
|
|
51
|
-
args.forEach((arg) => {
|
|
52
|
-
acc = acc.concat([[arg, basicType]]);
|
|
53
|
-
});
|
|
54
|
-
return acc;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return acc.concat([[args[i], input.type]]);
|
|
58
|
-
}
|
|
59
|
-
}, []);
|
|
60
|
-
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
61
|
-
let rawArg = arg;
|
|
62
|
-
switch (inputType) {
|
|
63
|
-
case 'bool':
|
|
64
|
-
return arg ? hexTrue : hexFalse;
|
|
65
|
-
case 'address':
|
|
66
|
-
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
if (inputType.startsWith('bytes')) {
|
|
70
|
-
if (Array.isArray(arg)) {
|
|
71
|
-
throw new Error(`essential-eth does not yet support "${inputType}[]" inputs. Make a PR today!"`);
|
|
72
|
-
}
|
|
73
|
-
const argEncoded = BigInt(arg).toString(16);
|
|
74
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
75
|
-
return paddedEncodedArg;
|
|
76
|
-
}
|
|
77
|
-
else if (inputType === 'uint256') {
|
|
78
|
-
const argEncoded = BigInt(arg).toString(16);
|
|
79
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
80
|
-
return paddedEncodedArg;
|
|
81
|
-
}
|
|
82
|
-
else if (inputType.startsWith('uint')) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const argEncoded = rawArg.toString(16);
|
|
90
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
91
|
-
return paddedEncodedArg;
|
|
92
|
-
});
|
|
93
|
-
const functionEncoded = functionHash.slice(0, 8);
|
|
94
|
-
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
98
|
-
const rawOutputs = jsonABIArgument.outputs || [];
|
|
99
|
-
const slicedResponse = nodeResponse.slice(2);
|
|
100
|
-
if (rawOutputs.length === 1 && rawOutputs[0].type === 'string') {
|
|
101
|
-
const [hexOffset, responseData] = [
|
|
102
|
-
slicedResponse.slice(0, 64),
|
|
103
|
-
slicedResponse.slice(64),
|
|
104
|
-
];
|
|
105
|
-
const decimalOffset = Number(hexToDecimal(`0x${hexOffset}`));
|
|
106
|
-
const hexLength = responseData.slice(0, decimalOffset * 2);
|
|
107
|
-
const decimalLength = Number(hexToDecimal(`0x${hexLength}`));
|
|
108
|
-
const hexToDecode = responseData.slice(decimalOffset * 2, decimalOffset * 2 + decimalLength * 2);
|
|
109
|
-
return hexToUtf8(hexToDecode);
|
|
110
|
-
}
|
|
111
|
-
const encodedOutputs = slicedResponse.match(/.{1,64}/g) || [];
|
|
112
|
-
if (rawOutputs.length === 1 && rawOutputs[0].type === 'address[]') {
|
|
113
|
-
const unformattedAddresses = encodedOutputs.slice(2);
|
|
114
|
-
return unformattedAddresses.map((unformattedAddress) => {
|
|
115
|
-
return toChecksumAddress(`0x${unformattedAddress.slice(24)}`);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (rawOutputs?.length === 1 && rawOutputs[0].type === 'uint256[]') {
|
|
119
|
-
const outputs = encodedOutputs.slice(2);
|
|
120
|
-
return outputs.map((output) => {
|
|
121
|
-
return tinyBig(hexToDecimal(`0x${output}`));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
const outputs = encodedOutputs.map((output, i) => {
|
|
125
|
-
const outputType = rawOutputs[i].type;
|
|
126
|
-
switch (outputType) {
|
|
127
|
-
case 'bool':
|
|
128
|
-
return output === hexTrue;
|
|
129
|
-
case 'address':
|
|
130
|
-
return toChecksumAddress(`0x${output.slice(24)}`);
|
|
131
|
-
case 'uint256':
|
|
132
|
-
case 'uint120':
|
|
133
|
-
return tinyBig(hexToDecimal(`0x${output}`));
|
|
134
|
-
case 'bytes32':
|
|
135
|
-
return `0x${output}`;
|
|
136
|
-
case 'uint8':
|
|
137
|
-
return Number(hexToDecimal(`0x${output}`));
|
|
138
|
-
default:
|
|
139
|
-
throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
return outputs.length === 1 ? outputs[0] : outputs;
|
|
143
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare function buildFetchInit<T>(body: T): {
|
|
2
|
-
method: string;
|
|
3
|
-
headers: {
|
|
4
|
-
'Content-Type': string;
|
|
5
|
-
};
|
|
6
|
-
body: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
9
|
-
export type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
|
|
10
|
-
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
11
|
-
jsonrpc: string;
|
|
12
|
-
id: number;
|
|
13
|
-
method: RPCMethodName;
|
|
14
|
-
params: unknown[];
|
|
15
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import unfetch from 'isomorphic-unfetch';
|
|
2
|
-
export function buildFetchInit(body) {
|
|
3
|
-
return {
|
|
4
|
-
method: 'POST',
|
|
5
|
-
headers: {
|
|
6
|
-
'Content-Type': 'application/json',
|
|
7
|
-
},
|
|
8
|
-
body: JSON.stringify(body),
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export function post(url, body) {
|
|
12
|
-
return unfetch(url, buildFetchInit(body))
|
|
13
|
-
.then(async (r) => {
|
|
14
|
-
const t = await r.text();
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(t);
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
throw new Error(`Invalid JSON RPC response: "${t}"`);
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
.then((response) => {
|
|
23
|
-
const result = response?.result;
|
|
24
|
-
if (!result) {
|
|
25
|
-
throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
|
|
26
|
-
}
|
|
27
|
-
return response.result;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function buildRPCPostBody(method, params) {
|
|
31
|
-
return {
|
|
32
|
-
jsonrpc: '2.0',
|
|
33
|
-
id: 1,
|
|
34
|
-
method,
|
|
35
|
-
params,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function hexToDecimal(hex: string): string;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import Big from 'big.js';
|
|
2
|
-
import { TinyBig } from '../../shared/tiny-big/tiny-big';
|
|
3
|
-
import { hexlify } from '../../utils/bytes';
|
|
4
|
-
export function prepareTransaction(transaction) {
|
|
5
|
-
const preparedTransaction = {
|
|
6
|
-
...transaction,
|
|
7
|
-
};
|
|
8
|
-
Object.keys(transaction).forEach((key) => {
|
|
9
|
-
switch (key) {
|
|
10
|
-
case 'gas':
|
|
11
|
-
case 'gasPrice':
|
|
12
|
-
case 'nonce':
|
|
13
|
-
case 'maxFeePerGas':
|
|
14
|
-
case 'maxPriorityFeePerGas':
|
|
15
|
-
case 'value': {
|
|
16
|
-
const value = transaction[key];
|
|
17
|
-
if (value instanceof TinyBig) {
|
|
18
|
-
preparedTransaction[key] = value.toHexString();
|
|
19
|
-
}
|
|
20
|
-
else if (value instanceof Big) {
|
|
21
|
-
preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
|
|
22
|
-
}
|
|
23
|
-
else if (typeof transaction[key] === 'number')
|
|
24
|
-
preparedTransaction[key] =
|
|
25
|
-
'0x' + transaction[key].toString(16);
|
|
26
|
-
else
|
|
27
|
-
preparedTransaction[key] = transaction[key].toString();
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
case 'data':
|
|
31
|
-
preparedTransaction[key] = hexlify(transaction[key]);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return preparedTransaction;
|
|
36
|
-
}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export { BaseContract, Contract } from './classes/Contract';
|
|
2
|
-
export { AlchemyProvider } from './providers/AlchemyProvider';
|
|
3
|
-
export { ConstructorOptions, FallthroughProvider, } from './providers/FallthroughProvider';
|
|
4
|
-
export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
|
|
5
|
-
export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
6
|
-
export { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
|
|
7
|
-
export { ContractTypes, JSONABI, JSONABIArgument, } from './types/Contract.types';
|
|
8
|
-
export { Filter, FilterByBlockHash } from './types/Filter.types';
|
|
9
|
-
export { Network } from './types/Network.types';
|
|
10
|
-
export { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, RPCTransactionRequest, TransactionReceipt, TransactionRequest, TransactionResponse, } from './types/Transaction.types';
|
|
11
|
-
export { arrayify, Bytes, BytesLike, BytesLikeWithNumber, concat, DataOptions, Hexable, hexConcat, hexDataLength, hexDataSlice, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, Signature, SignatureLike, stripZeros, zeroPad, } from './utils/bytes';
|
|
12
|
-
export { computeAddress } from './utils/compute-address';
|
|
13
|
-
export { computePublicKey } from './utils/compute-public-key';
|
|
14
|
-
export { etherToGwei } from './utils/ether-to-gwei';
|
|
15
|
-
export { etherToWei } from './utils/ether-to-wei';
|
|
16
|
-
export { gweiToEther } from './utils/gwei-to-ether';
|
|
17
|
-
export { hashMessage } from './utils/hash-message';
|
|
18
|
-
export { isAddress } from './utils/is-address';
|
|
19
|
-
export { keccak256 } from './utils/keccak256';
|
|
20
|
-
export { pack, solidityKeccak256 } from './utils/solidity-keccak256';
|
|
21
|
-
export { splitSignature } from './utils/split-signature';
|
|
22
|
-
export { toChecksumAddress } from './utils/to-checksum-address';
|
|
23
|
-
export { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
24
|
-
export { weiToEther } from './utils/wei-to-ether';
|
package/dist/esm/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { BaseContract, Contract } from './classes/Contract';
|
|
2
|
-
export { AlchemyProvider } from './providers/AlchemyProvider';
|
|
3
|
-
export { FallthroughProvider, } from './providers/FallthroughProvider';
|
|
4
|
-
export { jsonRpcProvider, JsonRpcProvider } from './providers/JsonRpcProvider';
|
|
5
|
-
export { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
6
|
-
export { arrayify, concat, hexConcat, hexDataLength, hexDataSlice, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, stripZeros, zeroPad, } from './utils/bytes';
|
|
7
|
-
export { computeAddress } from './utils/compute-address';
|
|
8
|
-
export { computePublicKey } from './utils/compute-public-key';
|
|
9
|
-
export { etherToGwei } from './utils/ether-to-gwei';
|
|
10
|
-
export { etherToWei } from './utils/ether-to-wei';
|
|
11
|
-
export { gweiToEther } from './utils/gwei-to-ether';
|
|
12
|
-
export { hashMessage } from './utils/hash-message';
|
|
13
|
-
export { isAddress } from './utils/is-address';
|
|
14
|
-
export { keccak256 } from './utils/keccak256';
|
|
15
|
-
export { pack, solidityKeccak256 } from './utils/solidity-keccak256';
|
|
16
|
-
export { splitSignature } from './utils/split-signature';
|
|
17
|
-
export { toChecksumAddress } from './utils/to-checksum-address';
|
|
18
|
-
export { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
19
|
-
export { weiToEther } from './utils/wei-to-ether';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare class Logger {
|
|
2
|
-
private packageVersion;
|
|
3
|
-
constructor();
|
|
4
|
-
throwError(message: string, args: {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}): never;
|
|
7
|
-
throwArgumentError(message: string, arg: string, value: any): never;
|
|
8
|
-
checkSafeUint53(value: number, message?: string): void;
|
|
9
|
-
}
|
|
10
|
-
export declare const logger: Logger;
|
|
11
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { version } from './package-version';
|
|
2
|
-
class Logger {
|
|
3
|
-
packageVersion;
|
|
4
|
-
constructor() {
|
|
5
|
-
this.packageVersion = version;
|
|
6
|
-
}
|
|
7
|
-
throwError(message, args) {
|
|
8
|
-
const argsLength = Object.keys(args).length;
|
|
9
|
-
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
10
|
-
}
|
|
11
|
-
throwArgumentError(message, arg, value) {
|
|
12
|
-
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
13
|
-
}
|
|
14
|
-
checkSafeUint53(value, message = 'value not safe') {
|
|
15
|
-
if (typeof value !== 'number') {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
19
|
-
this.throwError(message, {
|
|
20
|
-
operation: 'checkSafeInteger',
|
|
21
|
-
fault: 'out-of-safe-range',
|
|
22
|
-
value: value,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (value % 1) {
|
|
26
|
-
this.throwError(message, {
|
|
27
|
-
operation: 'checkSafeInteger',
|
|
28
|
-
fault: 'non-integer',
|
|
29
|
-
value: value,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export const logger = new Logger();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const version = "0.10.3";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = '0.10.3';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
-
import type { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
|
-
import type { FeeData } from '../types/FeeData.types';
|
|
4
|
-
import type { Filter, FilterByBlockHash } from '../types/Filter.types';
|
|
5
|
-
import type { Network } from '../types/Network.types';
|
|
6
|
-
import type { Log, TransactionReceipt, TransactionRequest, TransactionResponse } from '../types/Transaction.types';
|
|
7
|
-
export declare abstract class BaseProvider {
|
|
8
|
-
abstract selectRpcUrl(): string;
|
|
9
|
-
abstract post(body: Record<string, unknown>): Promise<any>;
|
|
10
|
-
readonly _rpcUrls: string[];
|
|
11
|
-
protected _post: (body: Record<string, unknown>) => Promise<any>;
|
|
12
|
-
constructor(rpcUrls: string[]);
|
|
13
|
-
getNetwork(): Promise<Network>;
|
|
14
|
-
getBlockNumber(): Promise<number>;
|
|
15
|
-
getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
|
16
|
-
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
|
17
|
-
getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
|
|
18
|
-
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
19
|
-
getGasPrice(): Promise<TinyBig>;
|
|
20
|
-
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
21
|
-
getCode(address: string, blockTag?: BlockTag): Promise<string>;
|
|
22
|
-
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
23
|
-
getFeeData(): Promise<FeeData>;
|
|
24
|
-
getLogs(filter: Filter | FilterByBlockHash): Promise<Array<Log>>;
|
|
25
|
-
call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string>;
|
|
26
|
-
}
|