essential-eth 0.5.11-next.0 → 0.5.13-next.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/{classes → cjs/classes}/Contract.d.ts +0 -0
- package/dist/cjs/classes/Contract.js +140 -0
- package/dist/{classes → cjs/classes}/test/Contract/crv-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/crv-abi.js +488 -0
- package/dist/{classes → cjs/classes}/test/Contract/ens-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +453 -0
- package/dist/{classes → cjs/classes}/test/Contract/fei-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +526 -0
- package/dist/{classes → cjs/classes}/test/Contract/foo-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +42 -0
- package/dist/{classes → cjs/classes}/test/Contract/uniswap-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +121 -0
- package/dist/{classes → cjs/classes}/utils/clean-block.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-block.js +160 -0
- package/dist/{classes → cjs/classes}/utils/clean-log.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-log.js +37 -0
- package/dist/{classes → cjs/classes}/utils/clean-transaction-receipt.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +50 -0
- package/dist/{classes → cjs/classes}/utils/clean-transaction.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-transaction.js +51 -0
- package/dist/{classes → cjs/classes}/utils/encode-decode-transaction.d.ts +0 -0
- package/dist/cjs/classes/utils/encode-decode-transaction.js +137 -0
- package/dist/{classes → cjs/classes}/utils/fetchers.d.ts +0 -0
- package/dist/cjs/classes/utils/fetchers.js +81 -0
- package/dist/{classes → cjs/classes}/utils/hex-to-decimal.d.ts +0 -0
- package/dist/cjs/classes/utils/hex-to-decimal.js +24 -0
- package/dist/{classes → cjs/classes}/utils/prepare-transaction.d.ts +0 -0
- package/dist/cjs/classes/utils/prepare-transaction.js +45 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/cjs/index.js +54 -0
- package/dist/cjs/index.umd.js +2 -0
- package/dist/cjs/index.umd.js.map +1 -0
- package/dist/{logger → cjs/logger}/logger.d.ts +0 -0
- package/dist/cjs/logger/logger.js +36 -0
- package/dist/cjs/logger/package-version.d.ts +1 -0
- package/dist/cjs/logger/package-version.js +5 -0
- package/dist/{providers → cjs/providers}/BaseProvider.d.ts +0 -0
- package/dist/cjs/providers/BaseProvider.js +512 -0
- package/dist/{providers → cjs/providers}/FallthroughProvider.d.ts +0 -0
- package/dist/cjs/providers/FallthroughProvider.js +65 -0
- package/dist/{providers → cjs/providers}/JsonRpcProvider.d.ts +0 -0
- package/dist/cjs/providers/JsonRpcProvider.js +46 -0
- package/dist/{providers → cjs/providers}/test/rpc-urls.d.ts +0 -0
- package/dist/cjs/providers/test/rpc-urls.js +14 -0
- package/dist/{providers → cjs/providers}/utils/chains-info.d.ts +0 -0
- package/dist/cjs/providers/utils/chains-info.js +1402 -0
- package/dist/{shared → cjs/shared}/tiny-big/helpers.d.ts +0 -0
- package/dist/cjs/shared/tiny-big/helpers.js +97 -0
- package/dist/{shared → cjs/shared}/tiny-big/tiny-big.d.ts +0 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +101 -0
- package/dist/{shared → cjs/shared}/validate-type.d.ts +0 -0
- package/dist/cjs/shared/validate-type.js +9 -0
- package/dist/{types → cjs/types}/Block.types.d.ts +0 -0
- package/dist/cjs/types/Block.types.js +2 -0
- package/dist/{types → cjs/types}/Contract.types.d.ts +0 -0
- package/dist/cjs/types/Contract.types.js +2 -0
- package/dist/{types → cjs/types}/Filter.types.d.ts +0 -0
- package/dist/cjs/types/Filter.types.js +2 -0
- package/dist/{types → cjs/types}/Network.types.d.ts +0 -0
- package/dist/cjs/types/Network.types.js +2 -0
- package/dist/{types → cjs/types}/Transaction.types.d.ts +0 -0
- package/dist/cjs/types/Transaction.types.js +2 -0
- package/dist/{utils → cjs/utils}/bytes.d.ts +0 -0
- package/dist/cjs/utils/bytes.js +711 -0
- package/dist/{utils → cjs/utils}/compute-address.d.ts +0 -0
- package/dist/cjs/utils/compute-address.js +33 -0
- package/dist/{utils → cjs/utils}/compute-public-key.d.ts +0 -0
- package/dist/cjs/utils/compute-public-key.js +26 -0
- package/dist/{utils → cjs/utils}/ether-to-gwei.d.ts +0 -0
- package/dist/cjs/utils/ether-to-gwei.js +35 -0
- package/dist/{utils → cjs/utils}/ether-to-wei.d.ts +0 -0
- package/dist/cjs/utils/ether-to-wei.js +35 -0
- package/dist/{utils → cjs/utils}/gwei-to-ether.d.ts +0 -0
- package/dist/cjs/utils/gwei-to-ether.js +35 -0
- package/dist/{utils → cjs/utils}/hash-message.d.ts +0 -0
- package/dist/cjs/utils/hash-message.js +28 -0
- package/dist/{utils → cjs/utils}/is-address.d.ts +0 -0
- package/dist/cjs/utils/is-address.js +39 -0
- package/dist/{utils → cjs/utils}/keccak256.d.ts +0 -0
- package/dist/cjs/utils/keccak256.js +31 -0
- package/dist/{utils → cjs/utils}/solidity-keccak256.d.ts +0 -0
- package/dist/cjs/utils/solidity-keccak256.js +138 -0
- package/dist/{utils → cjs/utils}/split-signature.d.ts +0 -0
- package/dist/cjs/utils/split-signature.js +163 -0
- package/dist/{utils → cjs/utils}/to-checksum-address.d.ts +0 -0
- package/dist/cjs/utils/to-checksum-address.js +46 -0
- package/dist/{utils → cjs/utils}/to-utf8-bytes.d.ts +0 -0
- package/dist/cjs/utils/to-utf8-bytes.js +21 -0
- package/dist/{utils → cjs/utils}/wei-to-ether.d.ts +0 -0
- package/dist/cjs/utils/wei-to-ether.js +45 -0
- package/dist/esm/classes/Contract.d.ts +11 -0
- package/dist/esm/classes/Contract.js +65 -0
- package/dist/esm/classes/test/Contract/crv-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/crv-abi.js +470 -0
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/ens-abi.js +435 -0
- package/dist/esm/classes/test/Contract/fei-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/fei-abi.js +521 -0
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/foo-abi.js +33 -0
- package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/uniswap-abi.js +116 -0
- package/dist/esm/classes/utils/clean-block.d.ts +3 -0
- package/dist/esm/classes/utils/clean-block.js +35 -0
- package/dist/esm/classes/utils/clean-log.d.ts +2 -0
- package/dist/esm/classes/utils/clean-log.js +26 -0
- package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
- package/dist/esm/classes/utils/clean-transaction-receipt.js +34 -0
- package/dist/esm/classes/utils/clean-transaction.d.ts +2 -0
- package/dist/esm/classes/utils/clean-transaction.js +33 -0
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +4 -0
- package/dist/esm/classes/utils/encode-decode-transaction.js +98 -0
- package/dist/esm/classes/utils/fetchers.d.ts +9 -0
- package/dist/esm/classes/utils/fetchers.js +43 -0
- package/dist/esm/classes/utils/hex-to-decimal.d.ts +1 -0
- package/dist/esm/classes/utils/hex-to-decimal.js +3 -0
- package/dist/esm/classes/utils/prepare-transaction.d.ts +2 -0
- package/dist/esm/classes/utils/prepare-transaction.js +34 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/logger/logger.d.ts +11 -0
- package/dist/esm/logger/logger.js +33 -0
- package/dist/esm/logger/package-version.d.ts +1 -0
- package/dist/esm/logger/package-version.js +1 -0
- package/dist/esm/providers/BaseProvider.d.ts +24 -0
- package/dist/esm/providers/BaseProvider.js +157 -0
- package/dist/esm/providers/FallthroughProvider.d.ts +11 -0
- package/dist/esm/providers/FallthroughProvider.js +41 -0
- package/dist/esm/providers/JsonRpcProvider.d.ts +7 -0
- package/dist/esm/providers/JsonRpcProvider.js +15 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +11 -0
- package/dist/esm/providers/test/rpc-urls.js +11 -0
- package/dist/esm/providers/utils/chains-info.d.ts +467 -0
- package/dist/esm/providers/utils/chains-info.js +1398 -0
- package/dist/esm/shared/tiny-big/helpers.d.ts +1 -0
- package/dist/esm/shared/tiny-big/helpers.js +58 -0
- package/dist/esm/shared/tiny-big/tiny-big.d.ts +10 -0
- package/dist/esm/shared/tiny-big/tiny-big.js +45 -0
- package/dist/esm/shared/validate-type.d.ts +3 -0
- package/dist/esm/shared/validate-type.js +5 -0
- package/dist/esm/types/Block.types.d.ts +40 -0
- package/dist/esm/types/Block.types.js +1 -0
- package/dist/esm/types/Contract.types.d.ts +24 -0
- package/dist/esm/types/Contract.types.js +1 -0
- package/dist/esm/types/Filter.types.d.ts +12 -0
- package/dist/esm/types/Filter.types.js +1 -0
- package/dist/esm/types/Network.types.d.ts +5 -0
- package/dist/esm/types/Network.types.js +1 -0
- package/dist/esm/types/Transaction.types.d.ts +113 -0
- package/dist/esm/types/Transaction.types.js +1 -0
- package/dist/esm/utils/bytes.d.ts +40 -0
- package/dist/esm/utils/bytes.js +245 -0
- package/dist/esm/utils/compute-address.d.ts +1 -0
- package/dist/esm/utils/compute-address.js +11 -0
- package/dist/esm/utils/compute-public-key.d.ts +2 -0
- package/dist/esm/utils/compute-public-key.js +6 -0
- package/dist/esm/utils/ether-to-gwei.d.ts +3 -0
- package/dist/esm/utils/ether-to-gwei.js +7 -0
- package/dist/esm/utils/ether-to-wei.d.ts +3 -0
- package/dist/esm/utils/ether-to-wei.js +7 -0
- package/dist/esm/utils/gwei-to-ether.d.ts +3 -0
- package/dist/esm/utils/gwei-to-ether.js +7 -0
- package/dist/esm/utils/hash-message.d.ts +2 -0
- package/dist/esm/utils/hash-message.js +12 -0
- package/dist/esm/utils/is-address.d.ts +1 -0
- package/dist/esm/utils/is-address.js +12 -0
- package/dist/esm/utils/keccak256.d.ts +2 -0
- package/dist/esm/utils/keccak256.js +13 -0
- package/dist/esm/utils/solidity-keccak256.d.ts +2 -0
- package/dist/esm/utils/solidity-keccak256.js +85 -0
- package/dist/esm/utils/split-signature.d.ts +2 -0
- package/dist/esm/utils/split-signature.js +126 -0
- package/dist/esm/utils/to-checksum-address.d.ts +1 -0
- package/dist/esm/utils/to-checksum-address.js +25 -0
- package/dist/esm/utils/to-utf8-bytes.d.ts +1 -0
- package/dist/esm/utils/to-utf8-bytes.js +3 -0
- package/dist/esm/utils/wei-to-ether.d.ts +3 -0
- package/dist/esm/utils/wei-to-ether.js +16 -0
- package/package.json +10 -14
- package/readme.md +5 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/index.modern.mjs +0 -2
- package/dist/index.modern.mjs.map +0 -1
- package/dist/index.module.js +0 -2
- 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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +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)[];
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +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 {};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hexToDecimal(hex: string): string;
|
|
@@ -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, };
|
|
@@ -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.13-next.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '0.5.13-next.0';
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { cleanBlock } from '../classes/utils/clean-block';
|
|
11
|
+
import { cleanLog } from '../classes/utils/clean-log';
|
|
12
|
+
import { cleanTransaction } from '../classes/utils/clean-transaction';
|
|
13
|
+
import { cleanTransactionReceipt } from '../classes/utils/clean-transaction-receipt';
|
|
14
|
+
import { buildRPCPostBody, post } from '../classes/utils/fetchers';
|
|
15
|
+
import { hexToDecimal } from '../classes/utils/hex-to-decimal';
|
|
16
|
+
import { prepareTransaction } from '../classes/utils/prepare-transaction';
|
|
17
|
+
import { logger } from '../logger/logger';
|
|
18
|
+
import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
19
|
+
import chainsInfo from './utils/chains-info';
|
|
20
|
+
function prepBlockTag(blockTag) {
|
|
21
|
+
return typeof blockTag === 'number'
|
|
22
|
+
? tinyBig(blockTag).toHexString()
|
|
23
|
+
: blockTag;
|
|
24
|
+
}
|
|
25
|
+
export class BaseProvider {
|
|
26
|
+
constructor(rpcUrls) {
|
|
27
|
+
this._rpcUrls = [];
|
|
28
|
+
this._post = (body) => post(this.selectRpcUrl(), body);
|
|
29
|
+
this._rpcUrls = rpcUrls;
|
|
30
|
+
}
|
|
31
|
+
getNetwork() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const hexChainId = (yield this.post(buildRPCPostBody('eth_chainId', [])));
|
|
34
|
+
const chainId = hexToDecimal(hexChainId);
|
|
35
|
+
const info = chainsInfo[chainId];
|
|
36
|
+
return {
|
|
37
|
+
chainId: Number(chainId),
|
|
38
|
+
name: info[0] || 'unknown',
|
|
39
|
+
ensAddress: info[1] || null,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getBlockNumber() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const currentBlockNumber = (yield this.post(buildRPCPostBody('eth_blockNumber', [])));
|
|
46
|
+
return Number(hexToDecimal(currentBlockNumber));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getTransaction(transactionHash) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
52
|
+
this.post(buildRPCPostBody('eth_getTransactionByHash', [transactionHash])),
|
|
53
|
+
this.getBlock('latest'),
|
|
54
|
+
]);
|
|
55
|
+
const cleanedTransaction = cleanTransaction(rpcTransaction);
|
|
56
|
+
cleanedTransaction.confirmations =
|
|
57
|
+
blockNumber.number - cleanedTransaction.blockNumber + 1;
|
|
58
|
+
return cleanedTransaction;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getTransactionReceipt(transactionHash) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
64
|
+
this.post(buildRPCPostBody('eth_getTransactionReceipt', [transactionHash])),
|
|
65
|
+
this.getBlock('latest'),
|
|
66
|
+
]);
|
|
67
|
+
const cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
|
|
68
|
+
cleanedTransactionReceipt.confirmations =
|
|
69
|
+
blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
|
|
70
|
+
return cleanedTransactionReceipt;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
getTransactionCount(address, blockTag = 'latest') {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
blockTag = prepBlockTag(blockTag);
|
|
76
|
+
const transactionCount = (yield this.post(buildRPCPostBody('eth_getTransactionCount', [address, blockTag])));
|
|
77
|
+
return Number(hexToDecimal(transactionCount));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
let type = 'Number';
|
|
83
|
+
if (typeof timeFrame === 'string' && timeFrame.length === 66) {
|
|
84
|
+
type = 'Hash';
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
timeFrame = prepBlockTag(timeFrame);
|
|
88
|
+
}
|
|
89
|
+
const rpcBlock = (yield this.post(buildRPCPostBody(`eth_getBlockBy${type}`, [
|
|
90
|
+
timeFrame,
|
|
91
|
+
returnTransactionObjects,
|
|
92
|
+
])));
|
|
93
|
+
return cleanBlock(rpcBlock, returnTransactionObjects);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getGasPrice() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const hexGasPrice = (yield this.post(buildRPCPostBody('eth_gasPrice', [])));
|
|
99
|
+
return tinyBig(hexToDecimal(hexGasPrice));
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getBalance(address, blockTag = 'latest') {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
blockTag = prepBlockTag(blockTag);
|
|
105
|
+
const hexBalance = (yield this.post(buildRPCPostBody('eth_getBalance', [address, blockTag])));
|
|
106
|
+
return tinyBig(hexToDecimal(hexBalance));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getCode(address, blockTag = 'latest') {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
blockTag = prepBlockTag(blockTag);
|
|
112
|
+
const contractCode = (yield this.post(buildRPCPostBody('eth_getCode', [address, blockTag])));
|
|
113
|
+
return contractCode;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
estimateGas(transaction) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const rpcTransaction = prepareTransaction(transaction);
|
|
119
|
+
const gasUsed = (yield this.post(buildRPCPostBody('eth_estimateGas', [rpcTransaction])));
|
|
120
|
+
return tinyBig(hexToDecimal(gasUsed));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
getLogs(filter) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const filterByRange = filter;
|
|
126
|
+
if (filterByRange.fromBlock)
|
|
127
|
+
filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
|
|
128
|
+
if (filterByRange.toBlock)
|
|
129
|
+
filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
|
|
130
|
+
const rpcLogs = (yield this.post(buildRPCPostBody('eth_getLogs', [filter])));
|
|
131
|
+
const logs = rpcLogs.map((log) => cleanLog(log, false));
|
|
132
|
+
return logs;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
call(transaction, blockTag = 'latest') {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
if (transaction.gasPrice &&
|
|
138
|
+
(transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
|
|
139
|
+
logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
|
|
140
|
+
gasPrice: transaction.gasPrice,
|
|
141
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
142
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
|
|
146
|
+
logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
|
|
147
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
148
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
blockTag = prepBlockTag(blockTag);
|
|
152
|
+
const rpcTransaction = prepareTransaction(transaction);
|
|
153
|
+
const transactionRes = (yield this.post(buildRPCPostBody('eth_call', [rpcTransaction, blockTag])));
|
|
154
|
+
return transactionRes;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseProvider } from './BaseProvider';
|
|
2
|
+
export interface ConstructorOptions {
|
|
3
|
+
timeoutDuration?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class FallthroughProvider extends BaseProvider {
|
|
6
|
+
private rpcUrlCounter;
|
|
7
|
+
private readonly timeoutDuration;
|
|
8
|
+
selectRpcUrl(): string;
|
|
9
|
+
constructor(rpcUrls: string[], options?: ConstructorOptions);
|
|
10
|
+
post: (body: Record<string, unknown>) => Promise<any>;
|
|
11
|
+
}
|