essential-eth 0.5.11-next.1 → 0.5.12
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/lib/cjs/classes/Contract.d.ts +78 -0
- package/lib/cjs/classes/Contract.js +140 -0
- package/{dist → lib/cjs}/classes/test/Contract/crv-abi.d.ts +2 -2
- package/lib/cjs/classes/test/Contract/crv-abi.js +488 -0
- package/{dist → lib/cjs}/classes/test/Contract/ens-abi.d.ts +2 -2
- package/lib/cjs/classes/test/Contract/ens-abi.js +453 -0
- package/{dist → lib/cjs}/classes/test/Contract/fei-abi.d.ts +2 -2
- package/lib/cjs/classes/test/Contract/fei-abi.js +526 -0
- package/{dist → lib/cjs}/classes/test/Contract/foo-abi.d.ts +2 -2
- package/lib/cjs/classes/test/Contract/foo-abi.js +42 -0
- package/{dist → lib/cjs}/classes/test/Contract/uniswap-abi.d.ts +2 -2
- package/lib/cjs/classes/test/Contract/uniswap-abi.js +121 -0
- package/lib/cjs/classes/utils/clean-block.d.ts +121 -0
- package/lib/cjs/classes/utils/clean-block.js +160 -0
- package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-log.js +37 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +14 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +50 -0
- package/lib/cjs/classes/utils/clean-transaction.d.ts +14 -0
- package/lib/cjs/classes/utils/clean-transaction.js +51 -0
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +16 -0
- package/lib/cjs/classes/utils/encode-decode-transaction.js +137 -0
- package/lib/cjs/classes/utils/fetchers.d.ts +39 -0
- package/lib/cjs/classes/utils/fetchers.js +81 -0
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +18 -0
- package/lib/cjs/classes/utils/hex-to-decimal.js +24 -0
- package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
- package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
- package/{dist → lib/cjs}/index.d.ts +25 -25
- package/lib/cjs/index.js +54 -0
- package/{dist → lib/cjs}/logger/logger.d.ts +11 -11
- package/lib/cjs/logger/logger.js +36 -0
- package/lib/cjs/logger/package-version.d.ts +1 -0
- package/lib/cjs/logger/package-version.js +5 -0
- package/lib/cjs/providers/BaseProvider.d.ts +353 -0
- package/lib/cjs/providers/BaseProvider.js +512 -0
- package/lib/cjs/providers/FallthroughProvider.d.ts +24 -0
- package/lib/cjs/providers/FallthroughProvider.js +65 -0
- package/lib/cjs/providers/JsonRpcProvider.d.ts +33 -0
- package/lib/cjs/providers/JsonRpcProvider.js +46 -0
- package/{dist → lib/cjs}/providers/test/rpc-urls.d.ts +11 -11
- package/lib/cjs/providers/test/rpc-urls.js +14 -0
- package/{dist → lib/cjs}/providers/utils/chains-info.d.ts +467 -467
- package/lib/cjs/providers/utils/chains-info.js +1402 -0
- package/lib/cjs/shared/tiny-big/helpers.d.ts +17 -0
- package/lib/cjs/shared/tiny-big/helpers.js +97 -0
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +58 -0
- package/lib/cjs/shared/tiny-big/tiny-big.js +101 -0
- package/{dist → lib/cjs}/shared/validate-type.d.ts +3 -3
- package/lib/cjs/shared/validate-type.js +9 -0
- package/{dist → lib/cjs}/types/Block.types.d.ts +41 -40
- package/lib/cjs/types/Block.types.js +2 -0
- package/{dist → lib/cjs}/types/Contract.types.d.ts +24 -24
- package/lib/cjs/types/Contract.types.js +2 -0
- package/lib/cjs/types/Filter.types.d.ts +16 -0
- package/lib/cjs/types/Filter.types.js +2 -0
- package/lib/cjs/types/Network.types.d.ts +8 -0
- package/lib/cjs/types/Network.types.js +2 -0
- package/lib/cjs/types/Transaction.types.d.ts +123 -0
- package/lib/cjs/types/Transaction.types.js +2 -0
- package/lib/cjs/utils/bytes.d.ts +289 -0
- package/lib/cjs/utils/bytes.js +711 -0
- package/lib/cjs/utils/compute-address.d.ts +17 -0
- package/lib/cjs/utils/compute-address.js +33 -0
- package/lib/cjs/utils/compute-public-key.d.ts +18 -0
- package/lib/cjs/utils/compute-public-key.js +26 -0
- package/lib/cjs/utils/ether-to-gwei.d.ts +27 -0
- package/lib/cjs/utils/ether-to-gwei.js +35 -0
- package/lib/cjs/utils/ether-to-wei.d.ts +27 -0
- package/lib/cjs/utils/ether-to-wei.js +35 -0
- package/lib/cjs/utils/gwei-to-ether.d.ts +27 -0
- package/lib/cjs/utils/gwei-to-ether.js +35 -0
- package/lib/cjs/utils/hash-message.d.ts +14 -0
- package/lib/cjs/utils/hash-message.js +28 -0
- package/lib/cjs/utils/is-address.d.ts +24 -0
- package/lib/cjs/utils/is-address.js +39 -0
- package/lib/cjs/utils/keccak256.d.ts +16 -0
- package/lib/cjs/utils/keccak256.js +31 -0
- package/lib/cjs/utils/solidity-keccak256.d.ts +39 -0
- package/lib/cjs/utils/solidity-keccak256.js +138 -0
- package/lib/cjs/utils/split-signature.d.ts +24 -0
- package/lib/cjs/utils/split-signature.js +163 -0
- package/lib/cjs/utils/to-checksum-address.d.ts +17 -0
- package/lib/cjs/utils/to-checksum-address.js +46 -0
- package/lib/cjs/utils/to-utf8-bytes.d.ts +15 -0
- package/lib/cjs/utils/to-utf8-bytes.js +21 -0
- package/lib/cjs/utils/wei-to-ether.d.ts +27 -0
- package/lib/cjs/utils/wei-to-ether.js +45 -0
- package/{dist → lib/esm}/classes/Contract.d.ts +11 -11
- package/lib/esm/classes/Contract.js +65 -0
- package/lib/esm/classes/test/Contract/crv-abi.d.ts +2 -0
- package/lib/esm/classes/test/Contract/crv-abi.js +470 -0
- package/lib/esm/classes/test/Contract/ens-abi.d.ts +2 -0
- package/lib/esm/classes/test/Contract/ens-abi.js +435 -0
- package/lib/esm/classes/test/Contract/fei-abi.d.ts +2 -0
- package/lib/esm/classes/test/Contract/fei-abi.js +521 -0
- package/lib/esm/classes/test/Contract/foo-abi.d.ts +2 -0
- package/lib/esm/classes/test/Contract/foo-abi.js +33 -0
- package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/lib/esm/classes/test/Contract/uniswap-abi.js +116 -0
- package/{dist → lib/esm}/classes/utils/clean-block.d.ts +3 -3
- package/lib/esm/classes/utils/clean-block.js +35 -0
- package/{dist → lib/esm}/classes/utils/clean-log.d.ts +2 -2
- package/lib/esm/classes/utils/clean-log.js +26 -0
- package/{dist → lib/esm}/classes/utils/clean-transaction-receipt.d.ts +2 -2
- package/lib/esm/classes/utils/clean-transaction-receipt.js +34 -0
- package/{dist → lib/esm}/classes/utils/clean-transaction.d.ts +2 -2
- package/lib/esm/classes/utils/clean-transaction.js +33 -0
- package/{dist → lib/esm}/classes/utils/encode-decode-transaction.d.ts +4 -4
- package/lib/esm/classes/utils/encode-decode-transaction.js +98 -0
- package/{dist → lib/esm}/classes/utils/fetchers.d.ts +9 -9
- package/lib/esm/classes/utils/fetchers.js +43 -0
- package/{dist → lib/esm}/classes/utils/hex-to-decimal.d.ts +1 -1
- package/lib/esm/classes/utils/hex-to-decimal.js +3 -0
- package/{dist → lib/esm}/classes/utils/prepare-transaction.d.ts +2 -2
- package/lib/esm/classes/utils/prepare-transaction.js +34 -0
- package/lib/esm/index.d.ts +25 -0
- package/lib/esm/index.js +20 -0
- package/lib/esm/logger/logger.d.ts +11 -0
- package/lib/esm/logger/logger.js +33 -0
- package/lib/esm/logger/package-version.d.ts +1 -0
- package/lib/esm/logger/package-version.js +1 -0
- package/{dist → lib/esm}/providers/BaseProvider.d.ts +24 -24
- package/lib/esm/providers/BaseProvider.js +157 -0
- package/{dist → lib/esm}/providers/FallthroughProvider.d.ts +11 -11
- package/lib/esm/providers/FallthroughProvider.js +41 -0
- package/{dist → lib/esm}/providers/JsonRpcProvider.d.ts +7 -7
- package/lib/esm/providers/JsonRpcProvider.js +15 -0
- package/lib/esm/providers/test/rpc-urls.d.ts +11 -0
- package/lib/esm/providers/test/rpc-urls.js +11 -0
- package/lib/esm/providers/utils/chains-info.d.ts +467 -0
- package/lib/esm/providers/utils/chains-info.js +1398 -0
- package/{dist → lib/esm}/shared/tiny-big/helpers.d.ts +1 -1
- package/lib/esm/shared/tiny-big/helpers.js +58 -0
- package/{dist → lib/esm}/shared/tiny-big/tiny-big.d.ts +10 -10
- package/lib/esm/shared/tiny-big/tiny-big.js +45 -0
- package/lib/esm/shared/validate-type.d.ts +3 -0
- package/lib/esm/shared/validate-type.js +5 -0
- package/lib/esm/types/Block.types.d.ts +40 -0
- package/lib/esm/types/Block.types.js +1 -0
- package/lib/esm/types/Contract.types.d.ts +24 -0
- package/lib/esm/types/Contract.types.js +1 -0
- package/{dist → lib/esm}/types/Filter.types.d.ts +12 -12
- package/lib/esm/types/Filter.types.js +1 -0
- package/{dist → lib/esm}/types/Network.types.d.ts +5 -5
- package/lib/esm/types/Network.types.js +1 -0
- package/{dist → lib/esm}/types/Transaction.types.d.ts +113 -113
- package/lib/esm/types/Transaction.types.js +1 -0
- package/{dist → lib/esm}/utils/bytes.d.ts +40 -40
- package/lib/esm/utils/bytes.js +245 -0
- package/{dist → lib/esm}/utils/compute-address.d.ts +1 -1
- package/lib/esm/utils/compute-address.js +11 -0
- package/{dist → lib/esm}/utils/compute-public-key.d.ts +2 -2
- package/lib/esm/utils/compute-public-key.js +6 -0
- package/{dist → lib/esm}/utils/ether-to-gwei.d.ts +3 -3
- package/lib/esm/utils/ether-to-gwei.js +7 -0
- package/{dist → lib/esm}/utils/ether-to-wei.d.ts +3 -3
- package/lib/esm/utils/ether-to-wei.js +7 -0
- package/{dist → lib/esm}/utils/gwei-to-ether.d.ts +3 -3
- package/lib/esm/utils/gwei-to-ether.js +7 -0
- package/{dist → lib/esm}/utils/hash-message.d.ts +2 -2
- package/lib/esm/utils/hash-message.js +12 -0
- package/{dist → lib/esm}/utils/is-address.d.ts +1 -1
- package/lib/esm/utils/is-address.js +12 -0
- package/{dist → lib/esm}/utils/keccak256.d.ts +2 -2
- package/lib/esm/utils/keccak256.js +13 -0
- package/{dist → lib/esm}/utils/solidity-keccak256.d.ts +2 -2
- package/lib/esm/utils/solidity-keccak256.js +85 -0
- package/{dist → lib/esm}/utils/split-signature.d.ts +2 -2
- package/lib/esm/utils/split-signature.js +126 -0
- package/{dist → lib/esm}/utils/to-checksum-address.d.ts +1 -1
- package/lib/esm/utils/to-checksum-address.js +25 -0
- package/{dist → lib/esm}/utils/to-utf8-bytes.d.ts +1 -1
- package/lib/esm/utils/to-utf8-bytes.js +3 -0
- package/{dist → lib/esm}/utils/wei-to-ether.d.ts +3 -3
- package/lib/esm/utils/wei-to-ether.js +16 -0
- package/package.json +14 -26
- package/readme.md +51 -66
- package/dist/index.js +0 -1904
- package/dist/index.js.map +0 -1
- package/dist/index.module.js +0 -1865
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/logger/package-version.d.ts +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { toChecksumAddress } from '../..';
|
|
2
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
3
|
+
import { cleanTransaction } from './clean-transaction';
|
|
4
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
+
export function cleanBlock(block, returnTransactionObjects) {
|
|
6
|
+
const cleanedBlock = Object.assign({}, 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,2 +1,2 @@
|
|
|
1
|
-
import type { Log, RPCLog } from './../../types/Transaction.types';
|
|
2
|
-
export declare function cleanLog(log: RPCLog, receiptLog: boolean): Log;
|
|
1
|
+
import type { Log, RPCLog } from './../../types/Transaction.types';
|
|
2
|
+
export declare function cleanLog(log: RPCLog, receiptLog: boolean): Log;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
2
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
3
|
+
export function cleanLog(log, receiptLog) {
|
|
4
|
+
const cleanedLog = Object.assign({}, log);
|
|
5
|
+
Object.keys(log).forEach((key) => {
|
|
6
|
+
switch (key) {
|
|
7
|
+
case 'address':
|
|
8
|
+
cleanedLog[key] = toChecksumAddress(log[key]);
|
|
9
|
+
break;
|
|
10
|
+
case 'blockNumber':
|
|
11
|
+
case 'logIndex':
|
|
12
|
+
case 'transactionIndex':
|
|
13
|
+
cleanedLog[key] = Number(hexToDecimal(log[key]));
|
|
14
|
+
break;
|
|
15
|
+
case 'removed':
|
|
16
|
+
if (receiptLog) {
|
|
17
|
+
delete cleanedLog[key];
|
|
18
|
+
}
|
|
19
|
+
else if (log[key] == null) {
|
|
20
|
+
cleanedLog[key] === false;
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return cleanedLog;
|
|
26
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RPCTransactionReceipt, TransactionReceipt } from '../../types/Transaction.types';
|
|
2
|
-
export declare function cleanTransactionReceipt(transactionReceipt: RPCTransactionReceipt): TransactionReceipt;
|
|
1
|
+
import type { RPCTransactionReceipt, TransactionReceipt } from '../../types/Transaction.types';
|
|
2
|
+
export declare function cleanTransactionReceipt(transactionReceipt: RPCTransactionReceipt): TransactionReceipt;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { tinyBig, toChecksumAddress } from '../..';
|
|
2
|
+
import { cleanLog } from './clean-log';
|
|
3
|
+
import { cleanTransaction } from './clean-transaction';
|
|
4
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
5
|
+
export function cleanTransactionReceipt(transactionReceipt) {
|
|
6
|
+
const cleanedTransaction = cleanTransaction(transactionReceipt);
|
|
7
|
+
const cleanedTransactionReceipt = Object.assign({}, cleanedTransaction);
|
|
8
|
+
Object.keys(transactionReceipt).forEach((key) => {
|
|
9
|
+
if (!transactionReceipt[key])
|
|
10
|
+
return;
|
|
11
|
+
switch (key) {
|
|
12
|
+
case 'status':
|
|
13
|
+
cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
|
|
14
|
+
break;
|
|
15
|
+
case 'contractAddress':
|
|
16
|
+
if (transactionReceipt[key]) {
|
|
17
|
+
cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
|
|
18
|
+
}
|
|
19
|
+
break;
|
|
20
|
+
case 'cumulativeGasUsed':
|
|
21
|
+
case 'effectiveGasPrice':
|
|
22
|
+
case 'gasUsed':
|
|
23
|
+
cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
|
|
24
|
+
break;
|
|
25
|
+
case 'logs':
|
|
26
|
+
transactionReceipt[key].forEach((log, index) => {
|
|
27
|
+
cleanedTransactionReceipt[key][index] = cleanLog(log, true);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
cleanedTransactionReceipt.byzantium =
|
|
32
|
+
cleanedTransactionReceipt.blockNumber >= 4370000;
|
|
33
|
+
return cleanedTransactionReceipt;
|
|
34
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RPCTransaction, TransactionResponse } from '../../types/Transaction.types';
|
|
2
|
-
export declare function cleanTransaction(transaction: RPCTransaction): TransactionResponse;
|
|
1
|
+
import type { RPCTransaction, TransactionResponse } from '../../types/Transaction.types';
|
|
2
|
+
export declare function cleanTransaction(transaction: RPCTransaction): TransactionResponse;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { tinyBig, toChecksumAddress } from '../..';
|
|
2
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
3
|
+
export function cleanTransaction(transaction) {
|
|
4
|
+
const cleanedTransaction = Object.assign({}, transaction);
|
|
5
|
+
Object.keys(transaction).forEach((key) => {
|
|
6
|
+
if (!transaction[key])
|
|
7
|
+
return;
|
|
8
|
+
switch (key) {
|
|
9
|
+
case 'blockNumber':
|
|
10
|
+
case 'chainId':
|
|
11
|
+
case 'transactionIndex':
|
|
12
|
+
case 'type':
|
|
13
|
+
case 'v':
|
|
14
|
+
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
15
|
+
break;
|
|
16
|
+
case 'from':
|
|
17
|
+
case 'to':
|
|
18
|
+
if (transaction[key]) {
|
|
19
|
+
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
20
|
+
}
|
|
21
|
+
break;
|
|
22
|
+
case 'value':
|
|
23
|
+
case 'gas':
|
|
24
|
+
case 'gasPrice':
|
|
25
|
+
case 'maxFeePerGas':
|
|
26
|
+
case 'maxPriorityFeePerGas':
|
|
27
|
+
case 'nonce':
|
|
28
|
+
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return cleanedTransaction;
|
|
33
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
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("../..").TinyBig | (string | number | boolean | import("../..").TinyBig)[];
|
|
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("../..").TinyBig | (string | number | boolean | import("../..").TinyBig)[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Keccak } from 'sha3';
|
|
2
|
+
import { tinyBig, toChecksumAddress } from '../..';
|
|
3
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
4
|
+
export const hexFalse = '0'.repeat(64);
|
|
5
|
+
const hexTrue = '0'.repeat(63) + '1';
|
|
6
|
+
function expandType(type) {
|
|
7
|
+
if (type === 'uint[]') {
|
|
8
|
+
return 'uint256[]';
|
|
9
|
+
}
|
|
10
|
+
else if (type === 'int[]') {
|
|
11
|
+
return 'int256[]';
|
|
12
|
+
}
|
|
13
|
+
return type;
|
|
14
|
+
}
|
|
15
|
+
export function encodeData(jsonABIArgument, args) {
|
|
16
|
+
const hash = new Keccak(256);
|
|
17
|
+
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
|
|
18
|
+
const functionHash = hash.update(functionString).digest('hex');
|
|
19
|
+
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
20
|
+
let shouldValidateInputLength = true;
|
|
21
|
+
if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
|
|
22
|
+
shouldValidateInputLength = false;
|
|
23
|
+
}
|
|
24
|
+
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
25
|
+
throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
|
|
26
|
+
}
|
|
27
|
+
const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
|
|
28
|
+
var _a;
|
|
29
|
+
if (input.type.includes('[')) {
|
|
30
|
+
const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
|
|
31
|
+
args.forEach((arg) => {
|
|
32
|
+
acc = acc.concat([[arg, basicType]]);
|
|
33
|
+
});
|
|
34
|
+
return acc;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return acc.concat([[args[i], input.type]]);
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
41
|
+
let rawArg = arg;
|
|
42
|
+
switch (inputType) {
|
|
43
|
+
case 'bool':
|
|
44
|
+
return arg ? hexTrue : hexFalse;
|
|
45
|
+
case 'address':
|
|
46
|
+
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
if (inputType.startsWith('bytes')) {
|
|
50
|
+
const argEncoded = rawArg
|
|
51
|
+
.split('')
|
|
52
|
+
.map((character) => character.charCodeAt(0).toString(16))
|
|
53
|
+
.join('');
|
|
54
|
+
const paddedEncodedArg = argEncoded.padEnd(64, '0');
|
|
55
|
+
return paddedEncodedArg;
|
|
56
|
+
}
|
|
57
|
+
else if (inputType === 'uint256') {
|
|
58
|
+
const argEncoded = BigInt(arg).toString(16);
|
|
59
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
60
|
+
return paddedEncodedArg;
|
|
61
|
+
}
|
|
62
|
+
else if (inputType.startsWith('uint')) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const argEncoded = rawArg.toString(16);
|
|
70
|
+
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
71
|
+
return paddedEncodedArg;
|
|
72
|
+
});
|
|
73
|
+
const functionEncoded = functionHash.slice(0, 8);
|
|
74
|
+
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
export function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
78
|
+
const rawOutputs = jsonABIArgument.outputs;
|
|
79
|
+
const encodedOutputs = nodeResponse.slice(2).match(/.{1,64}/g);
|
|
80
|
+
const outputs = (encodedOutputs || []).map((output, i) => {
|
|
81
|
+
const outputType = (rawOutputs || [])[i].type;
|
|
82
|
+
switch (outputType) {
|
|
83
|
+
case 'bool':
|
|
84
|
+
return output === hexTrue;
|
|
85
|
+
case 'address':
|
|
86
|
+
return toChecksumAddress(`0x${output.slice(24)}`);
|
|
87
|
+
case 'uint256':
|
|
88
|
+
return tinyBig(hexToDecimal(`0x${output}`));
|
|
89
|
+
case 'bytes32':
|
|
90
|
+
return `0x${output}`;
|
|
91
|
+
case 'uint8':
|
|
92
|
+
return Number(hexToDecimal(`0x${output}`));
|
|
93
|
+
default:
|
|
94
|
+
throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return outputs.length === 1 ? outputs[0] : outputs;
|
|
98
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
2
|
-
declare 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';
|
|
3
|
-
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
|
-
jsonrpc: string;
|
|
5
|
-
id: number;
|
|
6
|
-
method: RPCMethodName;
|
|
7
|
-
params: unknown[];
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
1
|
+
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
2
|
+
declare 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';
|
|
3
|
+
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
|
+
jsonrpc: string;
|
|
5
|
+
id: number;
|
|
6
|
+
method: RPCMethodName;
|
|
7
|
+
params: unknown[];
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import unfetch from 'isomorphic-unfetch';
|
|
11
|
+
export function post(url, body) {
|
|
12
|
+
return unfetch(url, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify(body),
|
|
18
|
+
})
|
|
19
|
+
.then((r) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const t = yield r.text();
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(t);
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
throw new Error(`Invalid JSON RPC response: "${t}"`);
|
|
26
|
+
}
|
|
27
|
+
}))
|
|
28
|
+
.then((response) => {
|
|
29
|
+
const result = response === null || response === void 0 ? void 0 : response.result;
|
|
30
|
+
if (!result) {
|
|
31
|
+
throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
|
|
32
|
+
}
|
|
33
|
+
return response.result;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function buildRPCPostBody(method, params) {
|
|
37
|
+
return {
|
|
38
|
+
jsonrpc: '2.0',
|
|
39
|
+
id: 1,
|
|
40
|
+
method,
|
|
41
|
+
params,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function hexToDecimal(hex: string): string;
|
|
1
|
+
export declare function hexToDecimal(hex: string): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RPCTransactionRequest, TransactionRequest } from './../../types/Transaction.types';
|
|
2
|
-
export declare function prepareTransaction(transaction: TransactionRequest): RPCTransactionRequest;
|
|
1
|
+
import type { RPCTransactionRequest, TransactionRequest } from './../../types/Transaction.types';
|
|
2
|
+
export declare function prepareTransaction(transaction: TransactionRequest): RPCTransactionRequest;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 = Object.assign({}, transaction);
|
|
6
|
+
Object.keys(transaction).forEach((key) => {
|
|
7
|
+
switch (key) {
|
|
8
|
+
case 'gas':
|
|
9
|
+
case 'gasPrice':
|
|
10
|
+
case 'nonce':
|
|
11
|
+
case 'maxFeePerGas':
|
|
12
|
+
case 'maxPriorityFeePerGas':
|
|
13
|
+
case 'value': {
|
|
14
|
+
const value = transaction[key];
|
|
15
|
+
if (value instanceof TinyBig) {
|
|
16
|
+
preparedTransaction[key] = value.toHexString();
|
|
17
|
+
}
|
|
18
|
+
else if (value instanceof Big) {
|
|
19
|
+
preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
|
|
20
|
+
}
|
|
21
|
+
else if (typeof transaction[key] === 'number')
|
|
22
|
+
preparedTransaction[key] =
|
|
23
|
+
'0x' + transaction[key].toString(16);
|
|
24
|
+
else
|
|
25
|
+
preparedTransaction[key] = transaction[key].toString();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'data':
|
|
29
|
+
preparedTransaction[key] = hexlify(transaction[key]);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return preparedTransaction;
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
+
import { ConstructorOptions, FallthroughProvider } from './providers/FallthroughProvider';
|
|
3
|
+
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
|
+
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
+
import { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
|
|
6
|
+
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
7
|
+
import { Filter, FilterByBlockHash } from './types/Filter.types';
|
|
8
|
+
import { Network } from './types/Network.types';
|
|
9
|
+
import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, RPCTransactionRequest, TransactionReceipt, TransactionRequest, TransactionResponse } from './types/Transaction.types';
|
|
10
|
+
import { computeAddress } from './utils/compute-address';
|
|
11
|
+
import { computePublicKey } from './utils/compute-public-key';
|
|
12
|
+
import { etherToGwei } from './utils/ether-to-gwei';
|
|
13
|
+
import { etherToWei } from './utils/ether-to-wei';
|
|
14
|
+
import { gweiToEther } from './utils/gwei-to-ether';
|
|
15
|
+
import { hashMessage } from './utils/hash-message';
|
|
16
|
+
import { isAddress } from './utils/is-address';
|
|
17
|
+
import { splitSignature } from './utils/split-signature';
|
|
18
|
+
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
19
|
+
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
20
|
+
import { weiToEther } from './utils/wei-to-ether';
|
|
21
|
+
export * from './utils/bytes';
|
|
22
|
+
export * from './utils/hash-message';
|
|
23
|
+
export * from './utils/keccak256';
|
|
24
|
+
export * from './utils/solidity-keccak256';
|
|
25
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, Filter, FilterByBlockHash, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
+
import { FallthroughProvider, } from './providers/FallthroughProvider';
|
|
3
|
+
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
|
+
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
+
import { computeAddress } from './utils/compute-address';
|
|
6
|
+
import { computePublicKey } from './utils/compute-public-key';
|
|
7
|
+
import { etherToGwei } from './utils/ether-to-gwei';
|
|
8
|
+
import { etherToWei } from './utils/ether-to-wei';
|
|
9
|
+
import { gweiToEther } from './utils/gwei-to-ether';
|
|
10
|
+
import { hashMessage } from './utils/hash-message';
|
|
11
|
+
import { isAddress } from './utils/is-address';
|
|
12
|
+
import { splitSignature } from './utils/split-signature';
|
|
13
|
+
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
14
|
+
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
15
|
+
import { weiToEther } from './utils/wei-to-ether';
|
|
16
|
+
export * from './utils/bytes';
|
|
17
|
+
export * from './utils/hash-message';
|
|
18
|
+
export * from './utils/keccak256';
|
|
19
|
+
export * from './utils/solidity-keccak256';
|
|
20
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, };
|
|
@@ -0,0 +1,11 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { version } from './package-version';
|
|
2
|
+
class Logger {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.packageVersion = version;
|
|
5
|
+
}
|
|
6
|
+
throwError(message, args) {
|
|
7
|
+
const argsLength = Object.keys(args).length;
|
|
8
|
+
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
9
|
+
}
|
|
10
|
+
throwArgumentError(message, arg, value) {
|
|
11
|
+
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
12
|
+
}
|
|
13
|
+
checkSafeUint53(value, message = 'value not safe') {
|
|
14
|
+
if (typeof value !== 'number') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
18
|
+
this.throwError(message, {
|
|
19
|
+
operation: 'checkSafeInteger',
|
|
20
|
+
fault: 'out-of-safe-range',
|
|
21
|
+
value: value,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (value % 1) {
|
|
25
|
+
this.throwError(message, {
|
|
26
|
+
operation: 'checkSafeInteger',
|
|
27
|
+
fault: 'non-integer',
|
|
28
|
+
value: value,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const logger = new Logger();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.5.12";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '0.5.12';
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
-
import type { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
|
-
import type { Filter, FilterByBlockHash } from '../types/Filter.types';
|
|
4
|
-
import type { Network } from '../types/Network.types';
|
|
5
|
-
import type { Log, TransactionReceipt, TransactionRequest, TransactionResponse } from '../types/Transaction.types';
|
|
6
|
-
export declare abstract class BaseProvider {
|
|
7
|
-
abstract selectRpcUrl(): string;
|
|
8
|
-
abstract post(body: Record<string, unknown>): Promise<any>;
|
|
9
|
-
readonly _rpcUrls: string[];
|
|
10
|
-
protected _post: (body: Record<string, unknown>) => Promise<any>;
|
|
11
|
-
constructor(rpcUrls: string[]);
|
|
12
|
-
getNetwork(): Promise<Network>;
|
|
13
|
-
getBlockNumber(): Promise<number>;
|
|
14
|
-
getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
|
15
|
-
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
|
16
|
-
getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
|
|
17
|
-
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
18
|
-
getGasPrice(): Promise<TinyBig>;
|
|
19
|
-
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
20
|
-
getCode(address: string, blockTag?: BlockTag): Promise<string>;
|
|
21
|
-
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
22
|
-
getLogs(filter: Filter | FilterByBlockHash): Promise<Array<Log>>;
|
|
23
|
-
call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string>;
|
|
24
|
-
}
|
|
1
|
+
import type { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
+
import type { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
|
+
import type { Filter, FilterByBlockHash } from '../types/Filter.types';
|
|
4
|
+
import type { Network } from '../types/Network.types';
|
|
5
|
+
import type { Log, TransactionReceipt, TransactionRequest, TransactionResponse } from '../types/Transaction.types';
|
|
6
|
+
export declare abstract class BaseProvider {
|
|
7
|
+
abstract selectRpcUrl(): string;
|
|
8
|
+
abstract post(body: Record<string, unknown>): Promise<any>;
|
|
9
|
+
readonly _rpcUrls: string[];
|
|
10
|
+
protected _post: (body: Record<string, unknown>) => Promise<any>;
|
|
11
|
+
constructor(rpcUrls: string[]);
|
|
12
|
+
getNetwork(): Promise<Network>;
|
|
13
|
+
getBlockNumber(): Promise<number>;
|
|
14
|
+
getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
|
15
|
+
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
|
16
|
+
getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
|
|
17
|
+
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
18
|
+
getGasPrice(): Promise<TinyBig>;
|
|
19
|
+
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
20
|
+
getCode(address: string, blockTag?: BlockTag): Promise<string>;
|
|
21
|
+
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
22
|
+
getLogs(filter: Filter | FilterByBlockHash): Promise<Array<Log>>;
|
|
23
|
+
call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string>;
|
|
24
|
+
}
|