essential-eth 0.5.9 → 0.5.10-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/{lib/esm → dist}/classes/Contract.d.ts +11 -11
- package/dist/classes/test/Contract/crv-abi.d.ts +2 -0
- package/dist/classes/test/Contract/ens-abi.d.ts +2 -0
- package/dist/classes/test/Contract/fei-abi.d.ts +2 -0
- package/dist/classes/test/Contract/foo-abi.d.ts +2 -0
- package/dist/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/dist/classes/utils/clean-block.d.ts +3 -0
- package/{lib/esm → dist}/classes/utils/clean-log.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/clean-transaction-receipt.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/clean-transaction.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/encode-decode-transaction.d.ts +4 -4
- package/{lib/esm → dist}/classes/utils/fetchers.d.ts +9 -9
- package/{lib/esm → dist}/classes/utils/hex-to-decimal.d.ts +1 -1
- package/{lib/esm → dist}/classes/utils/prepare-transaction.d.ts +2 -2
- package/{lib/esm → dist}/index.d.ts +25 -25
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.mjs +2 -0
- package/dist/index.modern.mjs.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/{lib/esm → dist}/logger/logger.d.ts +11 -11
- package/dist/logger/package-version.d.ts +1 -0
- package/{lib/esm → dist}/providers/BaseProvider.d.ts +24 -24
- package/{lib/esm → dist}/providers/FallthroughProvider.d.ts +11 -11
- package/{lib/esm → dist}/providers/JsonRpcProvider.d.ts +7 -7
- package/{lib/cjs → dist}/providers/test/rpc-urls.d.ts +11 -11
- package/{lib/cjs → dist}/providers/utils/chains-info.d.ts +467 -423
- package/{lib/esm → dist}/shared/tiny-big/helpers.d.ts +1 -1
- package/{lib/esm → dist}/shared/tiny-big/tiny-big.d.ts +10 -10
- package/{lib/cjs → dist}/shared/validate-type.d.ts +3 -3
- package/{lib/cjs → dist}/types/Block.types.d.ts +40 -41
- package/{lib/cjs → dist}/types/Contract.types.d.ts +24 -24
- package/{lib/esm → dist}/types/Filter.types.d.ts +12 -12
- package/{lib/esm → dist}/types/Network.types.d.ts +5 -5
- package/{lib/esm → dist}/types/Transaction.types.d.ts +113 -113
- package/{lib/esm → dist}/utils/bytes.d.ts +40 -40
- package/{lib/esm → dist}/utils/compute-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/compute-public-key.d.ts +2 -2
- package/{lib/esm → dist}/utils/ether-to-gwei.d.ts +3 -3
- package/dist/utils/ether-to-wei.d.ts +3 -0
- package/dist/utils/gwei-to-ether.d.ts +3 -0
- package/{lib/esm → dist}/utils/hash-message.d.ts +2 -2
- package/{lib/esm → dist}/utils/is-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/keccak256.d.ts +2 -2
- package/{lib/esm → dist}/utils/solidity-keccak256.d.ts +2 -2
- package/{lib/esm → dist}/utils/split-signature.d.ts +2 -2
- package/{lib/esm → dist}/utils/to-checksum-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/to-utf8-bytes.d.ts +1 -1
- package/dist/utils/wei-to-ether.d.ts +3 -0
- package/package.json +21 -14
- package/lib/cjs/classes/Contract.d.ts +0 -78
- package/lib/cjs/classes/Contract.js +0 -140
- package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
- package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
- package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
- package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
- package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
- package/lib/cjs/classes/utils/clean-block.d.ts +0 -121
- package/lib/cjs/classes/utils/clean-block.js +0 -160
- package/lib/cjs/classes/utils/clean-log.d.ts +0 -9
- package/lib/cjs/classes/utils/clean-log.js +0 -37
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -14
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +0 -50
- package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -14
- package/lib/cjs/classes/utils/clean-transaction.js +0 -51
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +0 -16
- package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -137
- package/lib/cjs/classes/utils/fetchers.d.ts +0 -39
- package/lib/cjs/classes/utils/fetchers.js +0 -81
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +0 -18
- package/lib/cjs/classes/utils/hex-to-decimal.js +0 -24
- package/lib/cjs/classes/utils/prepare-transaction.d.ts +0 -6
- package/lib/cjs/classes/utils/prepare-transaction.js +0 -45
- package/lib/cjs/index.d.ts +0 -25
- package/lib/cjs/index.js +0 -54
- package/lib/cjs/logger/logger.d.ts +0 -11
- package/lib/cjs/logger/logger.js +0 -36
- package/lib/cjs/logger/package-version.d.ts +0 -1
- package/lib/cjs/logger/package-version.js +0 -5
- package/lib/cjs/providers/BaseProvider.d.ts +0 -353
- package/lib/cjs/providers/BaseProvider.js +0 -512
- package/lib/cjs/providers/FallthroughProvider.d.ts +0 -24
- package/lib/cjs/providers/FallthroughProvider.js +0 -65
- package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -33
- package/lib/cjs/providers/JsonRpcProvider.js +0 -46
- package/lib/cjs/providers/test/rpc-urls.js +0 -14
- package/lib/cjs/providers/utils/chains-info.js +0 -1270
- package/lib/cjs/shared/tiny-big/helpers.d.ts +0 -17
- package/lib/cjs/shared/tiny-big/helpers.js +0 -97
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -58
- package/lib/cjs/shared/tiny-big/tiny-big.js +0 -101
- package/lib/cjs/shared/validate-type.js +0 -9
- package/lib/cjs/types/Block.types.js +0 -2
- package/lib/cjs/types/Contract.types.js +0 -2
- package/lib/cjs/types/Filter.types.d.ts +0 -16
- package/lib/cjs/types/Filter.types.js +0 -2
- package/lib/cjs/types/Network.types.d.ts +0 -8
- package/lib/cjs/types/Network.types.js +0 -2
- package/lib/cjs/types/Transaction.types.d.ts +0 -123
- package/lib/cjs/types/Transaction.types.js +0 -2
- package/lib/cjs/utils/bytes.d.ts +0 -289
- package/lib/cjs/utils/bytes.js +0 -711
- package/lib/cjs/utils/compute-address.d.ts +0 -17
- package/lib/cjs/utils/compute-address.js +0 -33
- package/lib/cjs/utils/compute-public-key.d.ts +0 -18
- package/lib/cjs/utils/compute-public-key.js +0 -26
- package/lib/cjs/utils/ether-to-gwei.d.ts +0 -27
- package/lib/cjs/utils/ether-to-gwei.js +0 -35
- package/lib/cjs/utils/ether-to-wei.d.ts +0 -27
- package/lib/cjs/utils/ether-to-wei.js +0 -35
- package/lib/cjs/utils/gwei-to-ether.d.ts +0 -27
- package/lib/cjs/utils/gwei-to-ether.js +0 -35
- package/lib/cjs/utils/hash-message.d.ts +0 -14
- package/lib/cjs/utils/hash-message.js +0 -28
- package/lib/cjs/utils/is-address.d.ts +0 -24
- package/lib/cjs/utils/is-address.js +0 -39
- package/lib/cjs/utils/keccak256.d.ts +0 -16
- package/lib/cjs/utils/keccak256.js +0 -31
- package/lib/cjs/utils/solidity-keccak256.d.ts +0 -39
- package/lib/cjs/utils/solidity-keccak256.js +0 -138
- package/lib/cjs/utils/split-signature.d.ts +0 -24
- package/lib/cjs/utils/split-signature.js +0 -163
- package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
- package/lib/cjs/utils/to-checksum-address.js +0 -46
- package/lib/cjs/utils/to-utf8-bytes.d.ts +0 -15
- package/lib/cjs/utils/to-utf8-bytes.js +0 -21
- package/lib/cjs/utils/wei-to-ether.d.ts +0 -27
- package/lib/cjs/utils/wei-to-ether.js +0 -45
- package/lib/esm/classes/Contract.js +0 -65
- package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
- package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
- package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
- package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
- package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
- package/lib/esm/classes/utils/clean-block.d.ts +0 -3
- package/lib/esm/classes/utils/clean-block.js +0 -35
- package/lib/esm/classes/utils/clean-log.js +0 -26
- package/lib/esm/classes/utils/clean-transaction-receipt.js +0 -34
- package/lib/esm/classes/utils/clean-transaction.js +0 -33
- package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
- package/lib/esm/classes/utils/fetchers.js +0 -43
- package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
- package/lib/esm/classes/utils/prepare-transaction.js +0 -34
- package/lib/esm/index.js +0 -20
- package/lib/esm/logger/logger.js +0 -33
- package/lib/esm/logger/package-version.d.ts +0 -1
- package/lib/esm/logger/package-version.js +0 -1
- package/lib/esm/providers/BaseProvider.js +0 -157
- package/lib/esm/providers/FallthroughProvider.js +0 -41
- package/lib/esm/providers/JsonRpcProvider.js +0 -15
- package/lib/esm/providers/test/rpc-urls.d.ts +0 -11
- package/lib/esm/providers/test/rpc-urls.js +0 -11
- package/lib/esm/providers/utils/chains-info.d.ts +0 -423
- package/lib/esm/providers/utils/chains-info.js +0 -1266
- package/lib/esm/shared/tiny-big/helpers.js +0 -58
- package/lib/esm/shared/tiny-big/tiny-big.js +0 -45
- package/lib/esm/shared/validate-type.d.ts +0 -3
- package/lib/esm/shared/validate-type.js +0 -5
- package/lib/esm/types/Block.types.d.ts +0 -40
- package/lib/esm/types/Block.types.js +0 -1
- package/lib/esm/types/Contract.types.d.ts +0 -24
- package/lib/esm/types/Contract.types.js +0 -1
- package/lib/esm/types/Filter.types.js +0 -1
- package/lib/esm/types/Network.types.js +0 -1
- package/lib/esm/types/Transaction.types.js +0 -1
- package/lib/esm/utils/bytes.js +0 -245
- package/lib/esm/utils/compute-address.js +0 -11
- package/lib/esm/utils/compute-public-key.js +0 -6
- package/lib/esm/utils/ether-to-gwei.js +0 -7
- package/lib/esm/utils/ether-to-wei.d.ts +0 -3
- package/lib/esm/utils/ether-to-wei.js +0 -7
- package/lib/esm/utils/gwei-to-ether.d.ts +0 -3
- package/lib/esm/utils/gwei-to-ether.js +0 -7
- package/lib/esm/utils/hash-message.js +0 -12
- package/lib/esm/utils/is-address.js +0 -12
- package/lib/esm/utils/keccak256.js +0 -13
- package/lib/esm/utils/solidity-keccak256.js +0 -85
- package/lib/esm/utils/split-signature.js +0 -126
- package/lib/esm/utils/to-checksum-address.js +0 -25
- package/lib/esm/utils/to-utf8-bytes.js +0 -3
- package/lib/esm/utils/wei-to-ether.d.ts +0 -3
- package/lib/esm/utils/wei-to-ether.js +0 -16
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.BaseProvider = void 0;
|
|
16
|
-
const clean_block_1 = require("../classes/utils/clean-block");
|
|
17
|
-
const clean_log_1 = require("../classes/utils/clean-log");
|
|
18
|
-
const clean_transaction_1 = require("../classes/utils/clean-transaction");
|
|
19
|
-
const clean_transaction_receipt_1 = require("../classes/utils/clean-transaction-receipt");
|
|
20
|
-
const fetchers_1 = require("../classes/utils/fetchers");
|
|
21
|
-
const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
|
|
22
|
-
const prepare_transaction_1 = require("../classes/utils/prepare-transaction");
|
|
23
|
-
const logger_1 = require("../logger/logger");
|
|
24
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
25
|
-
const chains_info_1 = __importDefault(require("./utils/chains-info"));
|
|
26
|
-
/**
|
|
27
|
-
* Converts a block tag into the right format when needed.
|
|
28
|
-
*
|
|
29
|
-
* * No equivalent in ethers.js
|
|
30
|
-
* * No equivalent in web3.js
|
|
31
|
-
*
|
|
32
|
-
* @internal
|
|
33
|
-
* @param blockTag the block tag to convert/return as a hex string
|
|
34
|
-
* @returns the specified block tag formatted as a hex string
|
|
35
|
-
* @example
|
|
36
|
-
* ```javascript
|
|
37
|
-
* prepBlockTag(14848183);
|
|
38
|
-
* // '0xe290b7'
|
|
39
|
-
* ```
|
|
40
|
-
* @example
|
|
41
|
-
* ```javascript
|
|
42
|
-
* prepBlockTag('0xe290b7');
|
|
43
|
-
* // '0xe290b7'
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
function prepBlockTag(blockTag) {
|
|
47
|
-
return typeof blockTag === 'number'
|
|
48
|
-
? (0, tiny_big_1.tinyBig)(blockTag).toHexString()
|
|
49
|
-
: blockTag;
|
|
50
|
-
}
|
|
51
|
-
class BaseProvider {
|
|
52
|
-
/**
|
|
53
|
-
* @param rpcUrls The URL(s) to your Eth node(s). Consider POKT or Infura
|
|
54
|
-
* @example
|
|
55
|
-
* `https://free-eth-node.com/api/eth`
|
|
56
|
-
* @example
|
|
57
|
-
* `https://mainnet.infura.io/v3/YOUR-PROJECT-ID`
|
|
58
|
-
*/
|
|
59
|
-
constructor(rpcUrls) {
|
|
60
|
-
/**
|
|
61
|
-
* @ignore
|
|
62
|
-
*/
|
|
63
|
-
this._rpcUrls = [];
|
|
64
|
-
/**
|
|
65
|
-
* @ignore
|
|
66
|
-
*/
|
|
67
|
-
this._post = (body) => (0, fetchers_1.post)(this.selectRpcUrl(), body);
|
|
68
|
-
this._rpcUrls = rpcUrls;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Gets information (name, chainId, and ensAddress when applicable) about the network the provider is connected to.
|
|
72
|
-
*
|
|
73
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
|
|
74
|
-
* * [Similar](/docs/api#isd) to [`web3.eth.getChainId`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getchainid) in web3.js, returns more than just the `chainId`
|
|
75
|
-
*
|
|
76
|
-
* @returns information about the network this provider is currently connected to
|
|
77
|
-
* @example
|
|
78
|
-
* ```javascript
|
|
79
|
-
* jsonRpcProvider('https://free-eth-node.com/api/eth').getNetwork();
|
|
80
|
-
* // { chainId: 1, name: 'eth', ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' }
|
|
81
|
-
* ```
|
|
82
|
-
* @example
|
|
83
|
-
* ```javascript
|
|
84
|
-
* jsonRpcProvider('https://free-eth-node.com/api/MATIC').getNetwork();
|
|
85
|
-
* // { chainId: 137, name: 'MATIC', ensAddress: null }
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
getNetwork() {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const hexChainId = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_chainId', [])));
|
|
91
|
-
const chainId = (0, hex_to_decimal_1.hexToDecimal)(hexChainId);
|
|
92
|
-
const info = chains_info_1.default[chainId];
|
|
93
|
-
return {
|
|
94
|
-
chainId: Number(chainId),
|
|
95
|
-
name: info[0] || 'unknown',
|
|
96
|
-
ensAddress: info[1] || null, // only send ensAddress if it exists
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Gets the number of the most recently mined block on the network the provider is connected to.
|
|
102
|
-
*
|
|
103
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
|
|
104
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
|
|
105
|
-
*
|
|
106
|
-
* @returns the number of the most recently mined block
|
|
107
|
-
* @example
|
|
108
|
-
* ```javascript
|
|
109
|
-
* await provider.getBlockNumber();
|
|
110
|
-
* // 1053312
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
getBlockNumber() {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
const currentBlockNumber = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_blockNumber', [])));
|
|
116
|
-
return Number((0, hex_to_decimal_1.hexToDecimal)(currentBlockNumber));
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Gets information about a specified transaction, even if it hasn't been mined yet.
|
|
121
|
-
*
|
|
122
|
-
* * [Similar](/docs/api#isd) to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction) in ethers.js, does not have `wait` method that waits until the transaction has been mined
|
|
123
|
-
* * [Similar](/docs/api#isd) to [`web3.eth.getTransaction`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransaction) in web3.js, some information returned using different types
|
|
124
|
-
*
|
|
125
|
-
* @param transactionHash the hash of the transaction to get information about
|
|
126
|
-
* @returns information about the specified transaction
|
|
127
|
-
* @example
|
|
128
|
-
* ```javascript
|
|
129
|
-
* await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
|
|
130
|
-
* // {
|
|
131
|
-
* // accessList: [],
|
|
132
|
-
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
133
|
-
* // blockNumber: 14578286,
|
|
134
|
-
* // chainId: 1,
|
|
135
|
-
* // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
|
|
136
|
-
* // gas: { TinyBig: 112163 },
|
|
137
|
-
* // gasPrice: { TinyBig: 48592426858 },
|
|
138
|
-
* // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
139
|
-
* // input: "0x83259f17000000000000000000000000000000000000000000...",
|
|
140
|
-
* // maxFeePerGas: { TinyBig: 67681261618 },
|
|
141
|
-
* // maxPriorityFeePerGas: { TinyBig: 1500000000 },
|
|
142
|
-
* // nonce: { TinyBig: 129 },
|
|
143
|
-
* // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
|
|
144
|
-
* // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
|
|
145
|
-
* // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
146
|
-
* // transactionIndex: 29,
|
|
147
|
-
* // type: 2,
|
|
148
|
-
* // v: 0,
|
|
149
|
-
* // value: { TinyBig: 0 },
|
|
150
|
-
* // confirmations: 298140,
|
|
151
|
-
* // }
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
getTransaction(transactionHash) {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
157
|
-
this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionByHash', [transactionHash])),
|
|
158
|
-
this.getBlock('latest'),
|
|
159
|
-
]);
|
|
160
|
-
const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(rpcTransaction);
|
|
161
|
-
// https://ethereum.stackexchange.com/questions/2881/how-to-get-the-transaction-confirmations-using-the-json-rpc
|
|
162
|
-
cleanedTransaction.confirmations =
|
|
163
|
-
blockNumber.number - cleanedTransaction.blockNumber + 1;
|
|
164
|
-
return cleanedTransaction;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by [`getTransaction`](/docs/api/modules#gettransaction).
|
|
169
|
-
*
|
|
170
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
|
|
171
|
-
* * [Similar](/docs/api#isd) to [`web3.eth.getTransactionReceipt`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactionreceipt) in web3.js, some information returned using different types
|
|
172
|
-
*
|
|
173
|
-
* @param transactionHash the hash of the transaction to get information about
|
|
174
|
-
* @returns information about the specified transaction that has already been mined
|
|
175
|
-
* @example
|
|
176
|
-
* ```javascript
|
|
177
|
-
* await provider.getTransactionReceipt('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
|
|
178
|
-
* // {
|
|
179
|
-
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
180
|
-
* // blockNumber: 14578286,
|
|
181
|
-
* // contractAddress: null,
|
|
182
|
-
* // cumulativeGasUsed: { TinyBig: 3067973 },
|
|
183
|
-
* // effectiveGasPrice: { TinyBig: 48592426858 },
|
|
184
|
-
* // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
|
|
185
|
-
* // gasUsed: { TinyBig: 112163 },
|
|
186
|
-
* // logs: [
|
|
187
|
-
* // {
|
|
188
|
-
* // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
|
|
189
|
-
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
190
|
-
* // blockNumber: 14578286,
|
|
191
|
-
* // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
|
|
192
|
-
* // logIndex: 42,
|
|
193
|
-
* // topics: [
|
|
194
|
-
* // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
195
|
-
* // "0x00000000000000000000000039b72d136ba3e4cef35f48cd09587ffab754dd8b",
|
|
196
|
-
* // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
|
|
197
|
-
* // ],
|
|
198
|
-
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
199
|
-
* // transactionIndex: 29,
|
|
200
|
-
* // },
|
|
201
|
-
* // {
|
|
202
|
-
* // address: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
203
|
-
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
204
|
-
* // blockNumber: 14578286,
|
|
205
|
-
* // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
|
|
206
|
-
* // logIndex: 43,
|
|
207
|
-
* // topics: [
|
|
208
|
-
* // "0x34fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf7",
|
|
209
|
-
* // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
|
|
210
|
-
* // "0x0000000000000000000000000000000000000000000000000000000000000003",
|
|
211
|
-
* // ],
|
|
212
|
-
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
213
|
-
* // transactionIndex: 29,
|
|
214
|
-
* // },
|
|
215
|
-
* // ],
|
|
216
|
-
* // logsBloom: "0x00000000000000000000000000000...",
|
|
217
|
-
* // status: 1,
|
|
218
|
-
* // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
219
|
-
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
220
|
-
* // transactionIndex: 29,
|
|
221
|
-
* // type: 2,
|
|
222
|
-
* // byzantium: true,
|
|
223
|
-
* // confirmations: 298171,
|
|
224
|
-
* // }
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
getTransactionReceipt(transactionHash) {
|
|
228
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
-
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
230
|
-
this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionReceipt', [transactionHash])),
|
|
231
|
-
this.getBlock('latest'),
|
|
232
|
-
]);
|
|
233
|
-
const cleanedTransactionReceipt = (0, clean_transaction_receipt_1.cleanTransactionReceipt)(rpcTransaction);
|
|
234
|
-
cleanedTransactionReceipt.confirmations =
|
|
235
|
-
blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
|
|
236
|
-
return cleanedTransactionReceipt;
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Returns the number of sent transactions by an address, from genesis (or as far back as a provider looks) up to specified block.
|
|
241
|
-
*
|
|
242
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
|
|
243
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
|
|
244
|
-
*
|
|
245
|
-
* @param address the address to count number of sent transactions
|
|
246
|
-
* @param blockTag the block to count transactions up to, inclusive
|
|
247
|
-
* @returns the number of transactions sent by the specified address
|
|
248
|
-
* @example
|
|
249
|
-
* ```javascript
|
|
250
|
-
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3');
|
|
251
|
-
* // 1060000
|
|
252
|
-
* ```
|
|
253
|
-
* @example
|
|
254
|
-
* ```javascript
|
|
255
|
-
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 'latest');
|
|
256
|
-
* // 1060000
|
|
257
|
-
* ```
|
|
258
|
-
* @example
|
|
259
|
-
* ```javascript
|
|
260
|
-
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 14649390);
|
|
261
|
-
* // 1053312
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
getTransactionCount(address, blockTag = 'latest') {
|
|
265
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
-
blockTag = prepBlockTag(blockTag);
|
|
267
|
-
const transactionCount = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionCount', [address, blockTag])));
|
|
268
|
-
return Number((0, hex_to_decimal_1.hexToDecimal)(transactionCount));
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Gets information about a certain block, optionally with full transaction objects.
|
|
273
|
-
*
|
|
274
|
-
* * [Similar](/docs/api#isd) to [`ethers.provider.getBlock`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js, includes some additional information. Can also return block with full transaction objects, similar to [`ethers.providers.getBlockWithTransactions`]
|
|
275
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
|
|
276
|
-
*
|
|
277
|
-
* @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
|
|
278
|
-
* @param returnTransactionObjects Whether to also return data about the transactions on the block.
|
|
279
|
-
* @returns A BlockResponse object with information about the specified block
|
|
280
|
-
* @example
|
|
281
|
-
* ```javascript
|
|
282
|
-
* await provider.getBlock(14879862);
|
|
283
|
-
* // {
|
|
284
|
-
* // baseFeePerGas: { TinyBig: 39095728776 },
|
|
285
|
-
* // difficulty: { TinyBig: 14321294455359973 },
|
|
286
|
-
* // extraData: "0x486976656f6e2073672d6865617679",
|
|
287
|
-
* // gasLimit: { TinyBig: 29970620 },
|
|
288
|
-
* // gasUsed: { TinyBig: 20951384 },
|
|
289
|
-
* // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
|
|
290
|
-
* // logsBloom:
|
|
291
|
-
* // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
|
|
292
|
-
* // miner: "0x1aD91ee08f21bE3dE0BA2ba6918E714dA6B45836",
|
|
293
|
-
* // mixHash: "0x73cc9419bfb89c9d41c3a8c34ce56b5ebe468bdcf870258d2e77262275d580ec",
|
|
294
|
-
* // nonce: "0x976f3f5d596ffb08",
|
|
295
|
-
* // number: 14879862,
|
|
296
|
-
* // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
|
|
297
|
-
* // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
|
|
298
|
-
* // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
|
299
|
-
* // size: { TinyBig: 134483 },
|
|
300
|
-
* // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
|
|
301
|
-
* // timestamp: { TinyBig: 1654016186 },
|
|
302
|
-
* // totalDifficulty: { TinyBig: 50478104614257705213748 },
|
|
303
|
-
* // transactions: [
|
|
304
|
-
* // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
|
|
305
|
-
* // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
|
|
306
|
-
* // "0x882f78fcb73f0f7ad0700bb0424a8b4beb366aaa93b88a3562c49a8d0ce4dcff",
|
|
307
|
-
* // ...
|
|
308
|
-
* // ],
|
|
309
|
-
* // transactionsRoot: "0x5934902f3dcc263ec34f24318179bf6301f53f4834685792066026f3a4849d72",
|
|
310
|
-
* // uncles: [],
|
|
311
|
-
* // }
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
|
|
315
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
316
|
-
let type = 'Number';
|
|
317
|
-
if (typeof timeFrame === 'string' && timeFrame.length === 66) {
|
|
318
|
-
// use endpoint that accepts string
|
|
319
|
-
type = 'Hash';
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
timeFrame = prepBlockTag(timeFrame);
|
|
323
|
-
}
|
|
324
|
-
const rpcBlock = (yield this.post((0, fetchers_1.buildRPCPostBody)(`eth_getBlockBy${type}`, [
|
|
325
|
-
timeFrame,
|
|
326
|
-
returnTransactionObjects,
|
|
327
|
-
])));
|
|
328
|
-
return (0, clean_block_1.cleanBlock)(rpcBlock, returnTransactionObjects);
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Gives an estimate of the current gas price in wei.
|
|
333
|
-
*
|
|
334
|
-
* * [Similar](/docs/api#isd) to [`ethers.provider.getGasPrice`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getGasPrice) in ethers.js, does not have a parameter specifying what unit you'd like to return. See also [`weiToEther`](/docs/api/modules#weitoether) and [`etherToGwei`](/docs/api/modules#ethertogwei)
|
|
335
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getGasPrice`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getgasprice) in web3.js, returns a number (TinyBig) instead of a string
|
|
336
|
-
*
|
|
337
|
-
* @returns an estimate of the current gas price in wei
|
|
338
|
-
* @example
|
|
339
|
-
* ```javascript
|
|
340
|
-
* await provider.getGasPrice();
|
|
341
|
-
* // 52493941856
|
|
342
|
-
* ```
|
|
343
|
-
*/
|
|
344
|
-
getGasPrice() {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
-
const hexGasPrice = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_gasPrice', [])));
|
|
347
|
-
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexGasPrice));
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Returns the balance of the account in wei.
|
|
352
|
-
*
|
|
353
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
|
|
354
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getBalance`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getbalance) in web3.js, returns a number (TinyBig) instead of a string
|
|
355
|
-
*
|
|
356
|
-
* @param address the address to check the balance of
|
|
357
|
-
* @param blockTag the block to check the specified address' balance on
|
|
358
|
-
* @returns the balance of the network's native token for the specified address on the specified block
|
|
359
|
-
* @example
|
|
360
|
-
* ```javascript
|
|
361
|
-
* await provider.getBalance('0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8');
|
|
362
|
-
* // 28798127851528138
|
|
363
|
-
* ```
|
|
364
|
-
*/
|
|
365
|
-
getBalance(address, blockTag = 'latest') {
|
|
366
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
-
blockTag = prepBlockTag(blockTag);
|
|
368
|
-
const hexBalance = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getBalance', [address, blockTag])));
|
|
369
|
-
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexBalance));
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Gets the code of a contract on a specified block.
|
|
374
|
-
*
|
|
375
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
|
|
376
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
|
|
377
|
-
*
|
|
378
|
-
* @param address the contract address to get the contract code from
|
|
379
|
-
* @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
|
|
380
|
-
* @returns the contract creation code for the specified address at the specified block height
|
|
381
|
-
* @example
|
|
382
|
-
* ```javascript
|
|
383
|
-
* await jsonRpcProvider().getCode('0xaC6095720221C79C6E7C638d260A2eFBC5D8d880', 'latest');
|
|
384
|
-
* // '0x608060405234801561001057600080fd5b506004361061...'
|
|
385
|
-
* ```
|
|
386
|
-
*/
|
|
387
|
-
getCode(address, blockTag = 'latest') {
|
|
388
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
389
|
-
blockTag = prepBlockTag(blockTag);
|
|
390
|
-
const contractCode = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getCode', [address, blockTag])));
|
|
391
|
-
return contractCode;
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Returns an estimate of the amount of gas that would be required to submit transaction to the network.
|
|
396
|
-
* An estimate may not be accurate since there could be another transaction on the network that was not accounted for.
|
|
397
|
-
*
|
|
398
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
|
|
399
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
|
|
400
|
-
*
|
|
401
|
-
* @param transaction the transaction to check the estimated gas cost for
|
|
402
|
-
* @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
|
|
403
|
-
* @example
|
|
404
|
-
* ```javascript
|
|
405
|
-
* await provider.estimateGas({
|
|
406
|
-
* // Wrapped ETH address
|
|
407
|
-
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
408
|
-
* data: "0xd0e30db0",
|
|
409
|
-
* value: etherToWei('1.0').toHexString(),
|
|
410
|
-
* });
|
|
411
|
-
* // { TinyBig: "27938" }
|
|
412
|
-
* ```
|
|
413
|
-
*/
|
|
414
|
-
estimateGas(transaction) {
|
|
415
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
416
|
-
const rpcTransaction = (0, prepare_transaction_1.prepareTransaction)(transaction);
|
|
417
|
-
const gasUsed = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_estimateGas', [rpcTransaction])));
|
|
418
|
-
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(gasUsed));
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Returns transaction receipt event logs that match a specified filter.
|
|
423
|
-
* May return `[]` if parameters are too broad, even if logs exist.
|
|
424
|
-
*
|
|
425
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
|
|
426
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
|
|
427
|
-
*
|
|
428
|
-
* @param filter parameters to filter the logs by
|
|
429
|
-
* @returns an array of logs matching the specified filter
|
|
430
|
-
* @example
|
|
431
|
-
* ```javascript
|
|
432
|
-
* provider.getLogs({
|
|
433
|
-
* address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
434
|
-
* topics: [
|
|
435
|
-
* "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
436
|
-
* "0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e",
|
|
437
|
-
* ],
|
|
438
|
-
* fromBlock: 14825027,
|
|
439
|
-
* toBlock: 14825039,
|
|
440
|
-
* });
|
|
441
|
-
*
|
|
442
|
-
* [
|
|
443
|
-
* {
|
|
444
|
-
* address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
445
|
-
* blockHash: '0x8e0dfac2f704851960f866c8708b3bef2f66c0fee0329cf25ff0261b264ca6bc',
|
|
446
|
-
* blockNumber: 14825029,
|
|
447
|
-
* data: '0x000000000000000000000000000000000000000000000000005f862ee352a38a',
|
|
448
|
-
* logIndex: 384,
|
|
449
|
-
* removed: false,
|
|
450
|
-
* topics: [
|
|
451
|
-
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
452
|
-
* '0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e',
|
|
453
|
-
* '0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45'
|
|
454
|
-
* ],
|
|
455
|
-
* transactionHash: '0xbd49031be16f8fd1775f4e0fe79b408ffd8ae9c65b2827ee47e3238e3f51f4c0',
|
|
456
|
-
* transactionIndex: 226
|
|
457
|
-
* }
|
|
458
|
-
* ]
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
461
|
-
getLogs(filter) {
|
|
462
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
463
|
-
const filterByRange = filter;
|
|
464
|
-
if (filterByRange.fromBlock)
|
|
465
|
-
filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
|
|
466
|
-
if (filterByRange.toBlock)
|
|
467
|
-
filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
|
|
468
|
-
const rpcLogs = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_getLogs', [filter])));
|
|
469
|
-
const logs = rpcLogs.map((log) => (0, clean_log_1.cleanLog)(log, false));
|
|
470
|
-
return logs;
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Returns the result of adding a transaction to the blockchain without actually adding that transaction to the blockchain.
|
|
475
|
-
* Does not require any ether as gas.
|
|
476
|
-
*
|
|
477
|
-
* * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
|
|
478
|
-
* * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
|
|
479
|
-
*
|
|
480
|
-
* @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
|
|
481
|
-
* @param blockTag the block to execute this transaction on
|
|
482
|
-
* @returns the result of executing the transaction on the specified block
|
|
483
|
-
* @example
|
|
484
|
-
* ```javascript
|
|
485
|
-
* await provider.call({ to: "0x6b175474e89094c44da98b954eedeac495271d0f", data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE" });
|
|
486
|
-
* // '0x0000000000000000000000000000000000000000000000000858898f93629000'
|
|
487
|
-
* ```
|
|
488
|
-
*/
|
|
489
|
-
call(transaction, blockTag = 'latest') {
|
|
490
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
-
if (transaction.gasPrice &&
|
|
492
|
-
(transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
|
|
493
|
-
logger_1.logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
|
|
494
|
-
gasPrice: transaction.gasPrice,
|
|
495
|
-
maxFeePerGas: transaction.maxFeePerGas,
|
|
496
|
-
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
|
|
500
|
-
logger_1.logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
|
|
501
|
-
maxFeePerGas: transaction.maxFeePerGas,
|
|
502
|
-
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
blockTag = prepBlockTag(blockTag);
|
|
506
|
-
const rpcTransaction = (0, prepare_transaction_1.prepareTransaction)(transaction);
|
|
507
|
-
const transactionRes = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_call', [rpcTransaction, blockTag])));
|
|
508
|
-
return transactionRes;
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
exports.BaseProvider = BaseProvider;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from './BaseProvider';
|
|
2
|
-
export interface ConstructorOptions {
|
|
3
|
-
timeoutDuration?: number;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* @beta
|
|
7
|
-
* A JSON RPC Provider which moves to the next URL when one fails.
|
|
8
|
-
*/
|
|
9
|
-
export declare class FallthroughProvider extends BaseProvider {
|
|
10
|
-
/**
|
|
11
|
-
* @ignore
|
|
12
|
-
*/
|
|
13
|
-
private rpcUrlCounter;
|
|
14
|
-
private readonly timeoutDuration;
|
|
15
|
-
/**
|
|
16
|
-
* @ignore
|
|
17
|
-
*/
|
|
18
|
-
selectRpcUrl(): string;
|
|
19
|
-
constructor(rpcUrls: string[], options?: ConstructorOptions);
|
|
20
|
-
/**
|
|
21
|
-
* @ignore
|
|
22
|
-
*/
|
|
23
|
-
post: (body: Record<string, unknown>) => Promise<any>;
|
|
24
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FallthroughProvider = void 0;
|
|
4
|
-
const logger_1 = require("../logger/logger");
|
|
5
|
-
const BaseProvider_1 = require("./BaseProvider");
|
|
6
|
-
// https://advancedweb.hu/how-to-add-timeout-to-a-promise-in-javascript/
|
|
7
|
-
const promiseTimeout = (prom, time) => Promise.race([
|
|
8
|
-
prom,
|
|
9
|
-
new Promise((_r, reject) => setTimeout(() => reject('Promise timed out'), time)),
|
|
10
|
-
]);
|
|
11
|
-
const DEFAULT_TIMEOUT_DURATION = 8000;
|
|
12
|
-
/**
|
|
13
|
-
* @beta
|
|
14
|
-
* A JSON RPC Provider which moves to the next URL when one fails.
|
|
15
|
-
*/
|
|
16
|
-
class FallthroughProvider extends BaseProvider_1.BaseProvider {
|
|
17
|
-
constructor(rpcUrls, options = {}) {
|
|
18
|
-
if (!Array.isArray(rpcUrls)) {
|
|
19
|
-
logger_1.logger.throwError('Array required', { rpcUrls });
|
|
20
|
-
}
|
|
21
|
-
if (rpcUrls.length <= 1) {
|
|
22
|
-
logger_1.logger.throwError('More than one rpcUrl is required', { rpcUrls });
|
|
23
|
-
}
|
|
24
|
-
super(rpcUrls);
|
|
25
|
-
// index of current trusted rpc url
|
|
26
|
-
/**
|
|
27
|
-
* @ignore
|
|
28
|
-
*/
|
|
29
|
-
this.rpcUrlCounter = 0;
|
|
30
|
-
/**
|
|
31
|
-
* @ignore
|
|
32
|
-
*/
|
|
33
|
-
this.post = (body) => {
|
|
34
|
-
// while failing post, add to rpcUrlCounter and post again
|
|
35
|
-
const genesisCount = this.rpcUrlCounter;
|
|
36
|
-
const recursivePostRetry = () => {
|
|
37
|
-
// Times out request
|
|
38
|
-
const genesisRpcUrl = this.selectRpcUrl();
|
|
39
|
-
const res = promiseTimeout(this._post(body), this.timeoutDuration).catch((e) => {
|
|
40
|
-
// A mutex: Only add if no other instance has discovered this url as failing yet
|
|
41
|
-
if (genesisRpcUrl === this.selectRpcUrl()) {
|
|
42
|
-
// add one and handle array overflow
|
|
43
|
-
this.rpcUrlCounter =
|
|
44
|
-
(this.rpcUrlCounter + 1) % this._rpcUrls.length;
|
|
45
|
-
}
|
|
46
|
-
// we've already tried this rpc, throw for good
|
|
47
|
-
if (this.rpcUrlCounter === genesisCount) {
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
50
|
-
return recursivePostRetry();
|
|
51
|
-
});
|
|
52
|
-
return res;
|
|
53
|
-
};
|
|
54
|
-
return recursivePostRetry();
|
|
55
|
-
};
|
|
56
|
-
this.timeoutDuration = options.timeoutDuration || DEFAULT_TIMEOUT_DURATION;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @ignore
|
|
60
|
-
*/
|
|
61
|
-
selectRpcUrl() {
|
|
62
|
-
return this._rpcUrls[this.rpcUrlCounter];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.FallthroughProvider = FallthroughProvider;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from './BaseProvider';
|
|
2
|
-
export declare class JsonRpcProvider extends BaseProvider {
|
|
3
|
-
/**
|
|
4
|
-
* @ignore
|
|
5
|
-
*/
|
|
6
|
-
selectRpcUrl(): string;
|
|
7
|
-
/**
|
|
8
|
-
* @ignore
|
|
9
|
-
*/
|
|
10
|
-
post(body: Record<string, unknown>): Promise<any>;
|
|
11
|
-
/**
|
|
12
|
-
* @param rpcUrl The URL to your Eth node. Consider POKT or Infura
|
|
13
|
-
* @example
|
|
14
|
-
* `https://free-eth-node.com/api/eth`
|
|
15
|
-
* @example
|
|
16
|
-
* `https://mainnet.infura.io/v3/YOUR-PROJECT-ID`
|
|
17
|
-
*/
|
|
18
|
-
constructor(rpcUrl?: string);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Helper function to avoid "new"
|
|
22
|
-
*
|
|
23
|
-
* @param rpcUrl the RPC URL to post requests to
|
|
24
|
-
* @returns an initiated {@link JsonRpcProvider}
|
|
25
|
-
* @example
|
|
26
|
-
* ```javascript
|
|
27
|
-
* jsonRpcProvider().getBlock('latest').then(block => {
|
|
28
|
-
* console.log(block.number);
|
|
29
|
-
* })
|
|
30
|
-
* // 14530496
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
|