essential-eth 0.6.2 → 0.8.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/cjs/classes/Contract.js +307 -66
- package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
- package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
- package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
- package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
- package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
- package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
- package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
- package/dist/cjs/classes/utils/clean-block.js +52 -30
- package/dist/cjs/classes/utils/clean-log.js +42 -20
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
- package/dist/cjs/classes/utils/clean-transaction.js +52 -29
- package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
- package/dist/cjs/classes/utils/fetchers.js +165 -41
- package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
- package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
- package/dist/cjs/index.js +25 -54
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -23
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -4
- package/dist/cjs/providers/BaseProvider.d.ts +2 -0
- package/dist/cjs/providers/BaseProvider.js +883 -475
- package/dist/cjs/providers/FallthroughProvider.js +118 -37
- package/dist/cjs/providers/JsonRpcProvider.js +93 -28
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
- package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +212 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
- package/dist/cjs/providers/test/rpc-urls.js +9 -12
- package/dist/cjs/providers/utils/chains-info.js +1 -3
- package/dist/cjs/shared/tiny-big/helpers.js +93 -42
- package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +1 -2
- package/dist/cjs/types/Contract.types.js +1 -2
- package/dist/cjs/types/FeeData.types.d.ts +7 -0
- package/dist/cjs/types/FeeData.types.js +1 -0
- package/dist/cjs/types/Filter.types.js +1 -2
- package/dist/cjs/types/Network.types.js +3 -2
- package/dist/cjs/types/Transaction.types.js +1 -2
- package/dist/cjs/utils/bytes.js +286 -318
- package/dist/cjs/utils/compute-address.js +8 -14
- package/dist/cjs/utils/compute-public-key.js +5 -10
- package/dist/cjs/utils/ether-to-gwei.js +10 -11
- package/dist/cjs/utils/ether-to-wei.js +10 -11
- package/dist/cjs/utils/gwei-to-ether.js +10 -11
- package/dist/cjs/utils/hash-message.d.ts +1 -1
- package/dist/cjs/utils/hash-message.js +11 -14
- package/dist/cjs/utils/is-address.js +8 -12
- package/dist/cjs/utils/keccak256.js +8 -14
- package/dist/cjs/utils/solidity-keccak256.js +49 -60
- package/dist/cjs/utils/split-signature.js +55 -73
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
- package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
- package/dist/cjs/utils/tests/compute-address.test.js +27 -0
- package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
- package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
- package/dist/cjs/utils/tests/hash-message.test.js +21 -0
- package/dist/cjs/utils/tests/is-address.test.js +55 -0
- package/dist/cjs/utils/tests/keccak256.test.js +97 -0
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
- package/dist/cjs/utils/tests/split-signature.test.js +25 -0
- package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
- package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
- package/dist/cjs/utils/to-checksum-address.js +15 -20
- package/dist/cjs/utils/to-utf8-bytes.js +1 -6
- package/dist/cjs/utils/wei-to-ether.js +13 -15
- package/dist/esm/classes/utils/clean-block.d.ts +1 -2
- package/dist/esm/classes/utils/clean-block.js +1 -1
- package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
- package/dist/esm/classes/utils/clean-transaction.js +2 -1
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
- package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/BaseProvider.d.ts +2 -0
- package/dist/esm/providers/BaseProvider.js +15 -0
- package/dist/esm/types/FeeData.types.d.ts +7 -0
- package/dist/esm/types/FeeData.types.js +1 -0
- package/dist/esm/utils/compute-address.js +2 -1
- package/dist/esm/utils/hash-message.d.ts +1 -1
- package/dist/esm/utils/hash-message.js +3 -1
- package/dist/esm/utils/is-address.js +1 -1
- package/package.json +10 -8
- package/readme.md +63 -3
|
@@ -1,28 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _asyncToGenerator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _classCallCheck(instance, Constructor) {
|
|
39
|
+
if (!(instance instanceof Constructor)) {
|
|
40
|
+
throw new TypeError("Cannot call a class as a function");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function _iterableToArrayLimit(arr, i) {
|
|
44
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
45
|
+
if (_i == null) return;
|
|
46
|
+
var _arr = [];
|
|
47
|
+
var _n = true;
|
|
48
|
+
var _d = false;
|
|
49
|
+
var _s, _e;
|
|
50
|
+
try {
|
|
51
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
52
|
+
_arr.push(_s.value);
|
|
53
|
+
if (i && _arr.length === i) break;
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
_d = true;
|
|
57
|
+
_e = err;
|
|
58
|
+
} finally{
|
|
59
|
+
try {
|
|
60
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
61
|
+
} finally{
|
|
62
|
+
if (_d) throw _e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return _arr;
|
|
66
|
+
}
|
|
67
|
+
function _nonIterableRest() {
|
|
68
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
69
|
+
}
|
|
70
|
+
function _slicedToArray(arr, i) {
|
|
71
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
72
|
+
}
|
|
73
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
74
|
+
if (!o) return;
|
|
75
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
76
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
77
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
78
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
79
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
80
|
+
}
|
|
81
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
82
|
+
var f, y, t, g, _ = {
|
|
83
|
+
label: 0,
|
|
84
|
+
sent: function() {
|
|
85
|
+
if (t[0] & 1) throw t[1];
|
|
86
|
+
return t[1];
|
|
87
|
+
},
|
|
88
|
+
trys: [],
|
|
89
|
+
ops: []
|
|
90
|
+
};
|
|
91
|
+
return g = {
|
|
92
|
+
next: verb(0),
|
|
93
|
+
"throw": verb(1),
|
|
94
|
+
"return": verb(2)
|
|
95
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
96
|
+
return this;
|
|
97
|
+
}), g;
|
|
98
|
+
function verb(n) {
|
|
99
|
+
return function(v) {
|
|
100
|
+
return step([
|
|
101
|
+
n,
|
|
102
|
+
v
|
|
103
|
+
]);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function step(op) {
|
|
107
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
108
|
+
while(_)try {
|
|
109
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
110
|
+
if (y = 0, t) op = [
|
|
111
|
+
op[0] & 2,
|
|
112
|
+
t.value
|
|
113
|
+
];
|
|
114
|
+
switch(op[0]){
|
|
115
|
+
case 0:
|
|
116
|
+
case 1:
|
|
117
|
+
t = op;
|
|
118
|
+
break;
|
|
119
|
+
case 4:
|
|
120
|
+
_.label++;
|
|
121
|
+
return {
|
|
122
|
+
value: op[1],
|
|
123
|
+
done: false
|
|
124
|
+
};
|
|
125
|
+
case 5:
|
|
126
|
+
_.label++;
|
|
127
|
+
y = op[1];
|
|
128
|
+
op = [
|
|
129
|
+
0
|
|
130
|
+
];
|
|
131
|
+
continue;
|
|
132
|
+
case 7:
|
|
133
|
+
op = _.ops.pop();
|
|
134
|
+
_.trys.pop();
|
|
135
|
+
continue;
|
|
136
|
+
default:
|
|
137
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
138
|
+
_ = 0;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
142
|
+
_.label = op[1];
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
146
|
+
_.label = t[1];
|
|
147
|
+
t = op;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
if (t && _.label < t[2]) {
|
|
151
|
+
_.label = t[2];
|
|
152
|
+
_.ops.push(op);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
if (t[2]) _.ops.pop();
|
|
156
|
+
_.trys.pop();
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
op = body.call(thisArg, _);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
op = [
|
|
162
|
+
6,
|
|
163
|
+
e
|
|
164
|
+
];
|
|
165
|
+
y = 0;
|
|
166
|
+
} finally{
|
|
167
|
+
f = t = 0;
|
|
168
|
+
}
|
|
169
|
+
if (op[0] & 5) throw op[1];
|
|
170
|
+
return {
|
|
171
|
+
value: op[0] ? op[1] : void 0,
|
|
172
|
+
done: true
|
|
173
|
+
};
|
|
174
|
+
}
|
|
13
175
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
25
|
-
const chains_info_1 = __importDefault(require("./utils/chains-info"));
|
|
176
|
+
import { cleanBlock } from "../classes/utils/clean-block";
|
|
177
|
+
import { cleanLog } from "../classes/utils/clean-log";
|
|
178
|
+
import { cleanTransaction } from "../classes/utils/clean-transaction";
|
|
179
|
+
import { cleanTransactionReceipt } from "../classes/utils/clean-transaction-receipt";
|
|
180
|
+
import { buildRPCPostBody, post } from "../classes/utils/fetchers";
|
|
181
|
+
import { hexToDecimal } from "../classes/utils/hex-to-decimal";
|
|
182
|
+
import { prepareTransaction } from "../classes/utils/prepare-transaction";
|
|
183
|
+
import { logger } from "../logger/logger";
|
|
184
|
+
import { tinyBig } from "../shared/tiny-big/tiny-big";
|
|
185
|
+
import chainsInfo from "./utils/chains-info";
|
|
26
186
|
/**
|
|
27
187
|
* Converts a block tag into the right format when needed.
|
|
28
188
|
*
|
|
@@ -42,471 +202,719 @@ const chains_info_1 = __importDefault(require("./utils/chains-info"));
|
|
|
42
202
|
* prepBlockTag('0xe290b7');
|
|
43
203
|
* // '0xe290b7'
|
|
44
204
|
* ```
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
return typeof blockTag === 'number'
|
|
48
|
-
? (0, tiny_big_1.tinyBig)(blockTag).toHexString()
|
|
49
|
-
: blockTag;
|
|
205
|
+
*/ function prepBlockTag(blockTag) {
|
|
206
|
+
return typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag;
|
|
50
207
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @example
|
|
57
|
-
* `https://mainnet.infura.io/v3/YOUR-PROJECT-ID`
|
|
58
|
-
*/
|
|
59
|
-
constructor(rpcUrls) {
|
|
208
|
+
export var BaseProvider = /*#__PURE__*/ function() {
|
|
209
|
+
"use strict";
|
|
210
|
+
function BaseProvider(rpcUrls) {
|
|
211
|
+
var _this = this;
|
|
212
|
+
_classCallCheck(this, BaseProvider);
|
|
60
213
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this._rpcUrls = [];
|
|
214
|
+
* @ignore
|
|
215
|
+
*/ this._rpcUrls = [];
|
|
64
216
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
217
|
+
* @ignore
|
|
218
|
+
*/ this._post = function(body) {
|
|
219
|
+
return post(_this.selectRpcUrl(), body);
|
|
220
|
+
};
|
|
68
221
|
this._rpcUrls = rpcUrls;
|
|
69
222
|
}
|
|
223
|
+
var _proto = BaseProvider.prototype;
|
|
70
224
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
225
|
+
* Gets information (name, chainId, and ensAddress when applicable) about the network the provider is connected to.
|
|
226
|
+
*
|
|
227
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getNetwork`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getNetwork) in ethers.js
|
|
228
|
+
* * [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`
|
|
229
|
+
*
|
|
230
|
+
* @returns information about the network this provider is currently connected to
|
|
231
|
+
* @example
|
|
232
|
+
* ```javascript
|
|
233
|
+
* jsonRpcProvider('https://free-eth-node.com/api/eth').getNetwork();
|
|
234
|
+
* // { chainId: 1, name: 'eth', ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' }
|
|
235
|
+
* ```
|
|
236
|
+
* @example
|
|
237
|
+
* ```javascript
|
|
238
|
+
* jsonRpcProvider('https://free-eth-node.com/api/MATIC').getNetwork();
|
|
239
|
+
* // { chainId: 137, name: 'MATIC', ensAddress: null }
|
|
240
|
+
* ```
|
|
241
|
+
*/ _proto.getNetwork = function getNetwork() {
|
|
242
|
+
var _this = this;
|
|
243
|
+
return _asyncToGenerator(function() {
|
|
244
|
+
var hexChainId, chainId, info;
|
|
245
|
+
return __generator(this, function(_state) {
|
|
246
|
+
switch(_state.label){
|
|
247
|
+
case 0:
|
|
248
|
+
return [
|
|
249
|
+
4,
|
|
250
|
+
_this.post(buildRPCPostBody("eth_chainId", []))
|
|
251
|
+
];
|
|
252
|
+
case 1:
|
|
253
|
+
hexChainId = _state.sent();
|
|
254
|
+
chainId = hexToDecimal(hexChainId);
|
|
255
|
+
info = chainsInfo[chainId];
|
|
256
|
+
return [
|
|
257
|
+
2,
|
|
258
|
+
{
|
|
259
|
+
chainId: Number(chainId),
|
|
260
|
+
name: info[0] || "unknown",
|
|
261
|
+
ensAddress: info[1] || null
|
|
262
|
+
}
|
|
263
|
+
];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
})();
|
|
267
|
+
};
|
|
100
268
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
|
|
269
|
+
* Gets the number of the most recently mined block on the network the provider is connected to.
|
|
270
|
+
*
|
|
271
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber) in ethers.js
|
|
272
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber) in web3.js
|
|
273
|
+
*
|
|
274
|
+
* @returns the number of the most recently mined block
|
|
275
|
+
* @example
|
|
276
|
+
* ```javascript
|
|
277
|
+
* await provider.getBlockNumber();
|
|
278
|
+
* // 1053312
|
|
279
|
+
* ```
|
|
280
|
+
*/ _proto.getBlockNumber = function getBlockNumber() {
|
|
281
|
+
var _this = this;
|
|
282
|
+
return _asyncToGenerator(function() {
|
|
283
|
+
var currentBlockNumber;
|
|
284
|
+
return __generator(this, function(_state) {
|
|
285
|
+
switch(_state.label){
|
|
286
|
+
case 0:
|
|
287
|
+
return [
|
|
288
|
+
4,
|
|
289
|
+
_this.post(buildRPCPostBody("eth_blockNumber", []))
|
|
290
|
+
];
|
|
291
|
+
case 1:
|
|
292
|
+
currentBlockNumber = _state.sent();
|
|
293
|
+
return [
|
|
294
|
+
2,
|
|
295
|
+
Number(hexToDecimal(currentBlockNumber))
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
})();
|
|
300
|
+
};
|
|
119
301
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
302
|
+
* Gets information about a specified transaction, even if it hasn't been mined yet.
|
|
303
|
+
*
|
|
304
|
+
* * [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
|
|
305
|
+
* * [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
|
|
306
|
+
*
|
|
307
|
+
* @param transactionHash the hash of the transaction to get information about
|
|
308
|
+
* @returns information about the specified transaction
|
|
309
|
+
* @example
|
|
310
|
+
* ```javascript
|
|
311
|
+
* await provider.getTransaction('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
|
|
312
|
+
* // {
|
|
313
|
+
* // accessList: [],
|
|
314
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
315
|
+
* // blockNumber: 14578286,
|
|
316
|
+
* // chainId: 1,
|
|
317
|
+
* // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
|
|
318
|
+
* // gas: { TinyBig: 112163 },
|
|
319
|
+
* // gasPrice: { TinyBig: 48592426858 },
|
|
320
|
+
* // hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
321
|
+
* // input: "0x83259f17000000000000000000000000000000000000000000...",
|
|
322
|
+
* // maxFeePerGas: { TinyBig: 67681261618 },
|
|
323
|
+
* // maxPriorityFeePerGas: { TinyBig: 1500000000 },
|
|
324
|
+
* // nonce: { TinyBig: 129 },
|
|
325
|
+
* // r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
|
|
326
|
+
* // s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
|
|
327
|
+
* // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
328
|
+
* // transactionIndex: 29,
|
|
329
|
+
* // type: 2,
|
|
330
|
+
* // v: 0,
|
|
331
|
+
* // value: { TinyBig: 0 },
|
|
332
|
+
* // confirmations: 298140,
|
|
333
|
+
* // }
|
|
334
|
+
* ```
|
|
335
|
+
*/ _proto.getTransaction = function getTransaction(transactionHash) {
|
|
336
|
+
var _this = this;
|
|
337
|
+
return _asyncToGenerator(function() {
|
|
338
|
+
var _ref, rpcTransaction, blockNumber, cleanedTransaction;
|
|
339
|
+
return __generator(this, function(_state) {
|
|
340
|
+
switch(_state.label){
|
|
341
|
+
case 0:
|
|
342
|
+
return [
|
|
343
|
+
4,
|
|
344
|
+
Promise.all([
|
|
345
|
+
_this.post(buildRPCPostBody("eth_getTransactionByHash", [
|
|
346
|
+
transactionHash
|
|
347
|
+
])),
|
|
348
|
+
_this.getBlock("latest")
|
|
349
|
+
])
|
|
350
|
+
];
|
|
351
|
+
case 1:
|
|
352
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
353
|
+
_state.sent(),
|
|
354
|
+
2
|
|
355
|
+
]), rpcTransaction = _ref[0], blockNumber = _ref[1];
|
|
356
|
+
cleanedTransaction = cleanTransaction(rpcTransaction);
|
|
357
|
+
// https://ethereum.stackexchange.com/questions/2881/how-to-get-the-transaction-confirmations-using-the-json-rpc
|
|
358
|
+
cleanedTransaction.confirmations = blockNumber.number - cleanedTransaction.blockNumber + 1;
|
|
359
|
+
return [
|
|
360
|
+
2,
|
|
361
|
+
cleanedTransaction
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
})();
|
|
366
|
+
};
|
|
167
367
|
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
368
|
+
* Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by [`getTransaction`](/docs/api/modules#gettransaction).
|
|
369
|
+
*
|
|
370
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt) in ethers.js
|
|
371
|
+
* * [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
|
|
372
|
+
*
|
|
373
|
+
* @param transactionHash the hash of the transaction to get information about
|
|
374
|
+
* @returns information about the specified transaction that has already been mined
|
|
375
|
+
* @example
|
|
376
|
+
* ```javascript
|
|
377
|
+
* await provider.getTransactionReceipt('0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789');
|
|
378
|
+
* // {
|
|
379
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
380
|
+
* // blockNumber: 14578286,
|
|
381
|
+
* // contractAddress: null,
|
|
382
|
+
* // cumulativeGasUsed: { TinyBig: 3067973 },
|
|
383
|
+
* // effectiveGasPrice: { TinyBig: 48592426858 },
|
|
384
|
+
* // from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
|
|
385
|
+
* // gasUsed: { TinyBig: 112163 },
|
|
386
|
+
* // logs: [
|
|
387
|
+
* // {
|
|
388
|
+
* // address: "0x0eDF9bc41Bbc1354c70e2107F80C42caE7FBBcA8",
|
|
389
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
390
|
+
* // blockNumber: 14578286,
|
|
391
|
+
* // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
|
|
392
|
+
* // logIndex: 42,
|
|
393
|
+
* // topics: [
|
|
394
|
+
* // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
395
|
+
* // "0x00000000000000000000000039b72d136ba3e4cef35f48cd09587ffab754dd8b",
|
|
396
|
+
* // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
|
|
397
|
+
* // ],
|
|
398
|
+
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
399
|
+
* // transactionIndex: 29,
|
|
400
|
+
* // },
|
|
401
|
+
* // {
|
|
402
|
+
* // address: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
403
|
+
* // blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
|
|
404
|
+
* // blockNumber: 14578286,
|
|
405
|
+
* // data: "0x0000000000000000000000000000000000000000000003a12ec797b5484968c1",
|
|
406
|
+
* // logIndex: 43,
|
|
407
|
+
* // topics: [
|
|
408
|
+
* // "0x34fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf7",
|
|
409
|
+
* // "0x000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed4",
|
|
410
|
+
* // "0x0000000000000000000000000000000000000000000000000000000000000003",
|
|
411
|
+
* // ],
|
|
412
|
+
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
413
|
+
* // transactionIndex: 29,
|
|
414
|
+
* // },
|
|
415
|
+
* // ],
|
|
416
|
+
* // logsBloom: "0x00000000000000000000000000000...",
|
|
417
|
+
* // status: 1,
|
|
418
|
+
* // to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
|
|
419
|
+
* // transactionHash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
|
|
420
|
+
* // transactionIndex: 29,
|
|
421
|
+
* // type: 2,
|
|
422
|
+
* // byzantium: true,
|
|
423
|
+
* // confirmations: 298171,
|
|
424
|
+
* // }
|
|
425
|
+
* ```
|
|
426
|
+
*/ _proto.getTransactionReceipt = function getTransactionReceipt(transactionHash) {
|
|
427
|
+
var _this = this;
|
|
428
|
+
return _asyncToGenerator(function() {
|
|
429
|
+
var _ref, rpcTransaction, blockNumber, cleanedTransactionReceipt;
|
|
430
|
+
return __generator(this, function(_state) {
|
|
431
|
+
switch(_state.label){
|
|
432
|
+
case 0:
|
|
433
|
+
return [
|
|
434
|
+
4,
|
|
435
|
+
Promise.all([
|
|
436
|
+
_this.post(buildRPCPostBody("eth_getTransactionReceipt", [
|
|
437
|
+
transactionHash
|
|
438
|
+
])),
|
|
439
|
+
_this.getBlock("latest")
|
|
440
|
+
])
|
|
441
|
+
];
|
|
442
|
+
case 1:
|
|
443
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
444
|
+
_state.sent(),
|
|
445
|
+
2
|
|
446
|
+
]), rpcTransaction = _ref[0], blockNumber = _ref[1];
|
|
447
|
+
cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
|
|
448
|
+
cleanedTransactionReceipt.confirmations = blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
|
|
449
|
+
return [
|
|
450
|
+
2,
|
|
451
|
+
cleanedTransactionReceipt
|
|
452
|
+
];
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
})();
|
|
456
|
+
};
|
|
239
457
|
/**
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
|
|
458
|
+
* Returns the number of sent transactions by an address, from genesis (or as far back as a provider looks) up to specified block.
|
|
459
|
+
*
|
|
460
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getTransactionCount`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionCount) in ethers.js
|
|
461
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getTransactionCount`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#gettransactioncount) in web3.js
|
|
462
|
+
*
|
|
463
|
+
* @param address the address to count number of sent transactions
|
|
464
|
+
* @param blockTag the block to count transactions up to, inclusive
|
|
465
|
+
* @returns the number of transactions sent by the specified address
|
|
466
|
+
* @example
|
|
467
|
+
* ```javascript
|
|
468
|
+
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3');
|
|
469
|
+
* // 1060000
|
|
470
|
+
* ```
|
|
471
|
+
* @example
|
|
472
|
+
* ```javascript
|
|
473
|
+
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 'latest');
|
|
474
|
+
* // 1060000
|
|
475
|
+
* ```
|
|
476
|
+
* @example
|
|
477
|
+
* ```javascript
|
|
478
|
+
* await provider.getTransactionCount('0x71660c4005ba85c37ccec55d0c4493e66fe775d3', 14649390);
|
|
479
|
+
* // 1053312
|
|
480
|
+
* ```
|
|
481
|
+
*/ _proto.getTransactionCount = function getTransactionCount(address) {
|
|
482
|
+
var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
|
|
483
|
+
var _this = this;
|
|
484
|
+
return _asyncToGenerator(function() {
|
|
485
|
+
var transactionCount;
|
|
486
|
+
return __generator(this, function(_state) {
|
|
487
|
+
switch(_state.label){
|
|
488
|
+
case 0:
|
|
489
|
+
blockTag = prepBlockTag(blockTag);
|
|
490
|
+
return [
|
|
491
|
+
4,
|
|
492
|
+
_this.post(buildRPCPostBody("eth_getTransactionCount", [
|
|
493
|
+
address,
|
|
494
|
+
blockTag
|
|
495
|
+
]))
|
|
496
|
+
];
|
|
497
|
+
case 1:
|
|
498
|
+
transactionCount = _state.sent();
|
|
499
|
+
return [
|
|
500
|
+
2,
|
|
501
|
+
Number(hexToDecimal(transactionCount))
|
|
502
|
+
];
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
})();
|
|
506
|
+
};
|
|
271
507
|
/**
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
508
|
+
* Gets information about a certain block, optionally with full transaction objects.
|
|
509
|
+
*
|
|
510
|
+
* * [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`]
|
|
511
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getBlock`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
|
|
512
|
+
*
|
|
513
|
+
* @param timeFrame The number, hash, or text-based description ('latest', 'earliest', or 'pending') of the block to collect information on.
|
|
514
|
+
* @param returnTransactionObjects Whether to also return data about the transactions on the block.
|
|
515
|
+
* @returns A BlockResponse object with information about the specified block
|
|
516
|
+
* @example
|
|
517
|
+
* ```javascript
|
|
518
|
+
* await provider.getBlock(14879862);
|
|
519
|
+
* // {
|
|
520
|
+
* // baseFeePerGas: { TinyBig: 39095728776 },
|
|
521
|
+
* // difficulty: { TinyBig: 14321294455359973 },
|
|
522
|
+
* // extraData: "0x486976656f6e2073672d6865617679",
|
|
523
|
+
* // gasLimit: { TinyBig: 29970620 },
|
|
524
|
+
* // gasUsed: { TinyBig: 20951384 },
|
|
525
|
+
* // hash: "0x563b458ec3c4f87393b53f70bdddc0058497109b784d8cacd9247ddf267049ab",
|
|
526
|
+
* // logsBloom:
|
|
527
|
+
* // "0x9f38794fe80b521794df6efad8b0d2e9582f9ec3959a3f9384bda0fa371cfa5fac5af9d515c6bdf1ec325f5b5f7ebdd6a3a9fae17b38a86d4dc4b0971afc68d8086640550f4c156e6f923f4a1bb94fb0bed6cdcc474c5c64bfeff7a4a906f72b9a7b94004ee58efc53d63ac66961acd3a431b2d896cc9fd75f6072960bced45f770587caf130f57504decfcb63c6ca8fbc5bdbd749edd5a99a7375d2b81872289adb775fb3c928259f4be39c6d3f4d5b6217822979bb88c1f1fb62429b1b6d41cf4e3f77f9e1db3f5723108f1e5b1255dd734ad8cdb11e7ea22487c788e67c83777b6f395e504ca59c64f52245ee6de3804cf809e5caa4f0ea6a9aa9eb6ed801",
|
|
528
|
+
* // miner: "0x1aD91ee08f21bE3dE0BA2ba6918E714dA6B45836",
|
|
529
|
+
* // mixHash: "0x73cc9419bfb89c9d41c3a8c34ce56b5ebe468bdcf870258d2e77262275d580ec",
|
|
530
|
+
* // nonce: "0x976f3f5d596ffb08",
|
|
531
|
+
* // number: 14879862,
|
|
532
|
+
* // parentHash: "0x95986ae14a71face8d9a6a379edd875b2e8bc73e4de0d9d460e7752bddb0f579",
|
|
533
|
+
* // receiptsRoot: "0x8e6ba2fd9bee602b653dae6e3132f16538c2c5df24f1df8c000392053f73defa",
|
|
534
|
+
* // sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
|
|
535
|
+
* // size: { TinyBig: 134483 },
|
|
536
|
+
* // stateRoot: "0xbf2bb67bd1c741f3d00904b8451d7c2cf4e3a2726f5a5884792ede2074747b85",
|
|
537
|
+
* // timestamp: { TinyBig: 1654016186 },
|
|
538
|
+
* // totalDifficulty: { TinyBig: 50478104614257705213748 },
|
|
539
|
+
* // transactions: [
|
|
540
|
+
* // "0xb3326a9149809603a2c28545e50e4f7d16e194bf5ee9764e0544603854c4a8d2",
|
|
541
|
+
* // "0x8b42095f8d335404a4896b2817b8e5e3d86a5a87cb434a8eec295d5280a7f48e",
|
|
542
|
+
* // "0x882f78fcb73f0f7ad0700bb0424a8b4beb366aaa93b88a3562c49a8d0ce4dcff",
|
|
543
|
+
* // ...
|
|
544
|
+
* // ],
|
|
545
|
+
* // transactionsRoot: "0x5934902f3dcc263ec34f24318179bf6301f53f4834685792066026f3a4849d72",
|
|
546
|
+
* // uncles: [],
|
|
547
|
+
* // }
|
|
548
|
+
* ```
|
|
549
|
+
*/ _proto.getBlock = function getBlock() {
|
|
550
|
+
var timeFrame = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "latest", returnTransactionObjects = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
551
|
+
var _this = this;
|
|
552
|
+
return _asyncToGenerator(function() {
|
|
553
|
+
var type, rpcBlock;
|
|
554
|
+
return __generator(this, function(_state) {
|
|
555
|
+
switch(_state.label){
|
|
556
|
+
case 0:
|
|
557
|
+
type = "Number";
|
|
558
|
+
if (typeof timeFrame === "string" && timeFrame.length === 66) {
|
|
559
|
+
// use endpoint that accepts string
|
|
560
|
+
type = "Hash";
|
|
561
|
+
} else {
|
|
562
|
+
timeFrame = prepBlockTag(timeFrame);
|
|
563
|
+
}
|
|
564
|
+
return [
|
|
565
|
+
4,
|
|
566
|
+
_this.post(buildRPCPostBody("eth_getBlockBy".concat(type), [
|
|
567
|
+
timeFrame,
|
|
568
|
+
returnTransactionObjects
|
|
569
|
+
]))
|
|
570
|
+
];
|
|
571
|
+
case 1:
|
|
572
|
+
rpcBlock = _state.sent();
|
|
573
|
+
return [
|
|
574
|
+
2,
|
|
575
|
+
cleanBlock(rpcBlock, returnTransactionObjects)
|
|
576
|
+
];
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
})();
|
|
580
|
+
};
|
|
331
581
|
/**
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return
|
|
346
|
-
|
|
347
|
-
return (
|
|
348
|
-
|
|
349
|
-
|
|
582
|
+
* Gives an estimate of the current gas price in wei.
|
|
583
|
+
*
|
|
584
|
+
* * [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)
|
|
585
|
+
* * [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
|
|
586
|
+
*
|
|
587
|
+
* @returns an estimate of the current gas price in wei
|
|
588
|
+
* @example
|
|
589
|
+
* ```javascript
|
|
590
|
+
* await provider.getGasPrice();
|
|
591
|
+
* // 52493941856
|
|
592
|
+
* ```
|
|
593
|
+
*/ _proto.getGasPrice = function getGasPrice() {
|
|
594
|
+
var _this = this;
|
|
595
|
+
return _asyncToGenerator(function() {
|
|
596
|
+
var hexGasPrice;
|
|
597
|
+
return __generator(this, function(_state) {
|
|
598
|
+
switch(_state.label){
|
|
599
|
+
case 0:
|
|
600
|
+
return [
|
|
601
|
+
4,
|
|
602
|
+
_this.post(buildRPCPostBody("eth_gasPrice", []))
|
|
603
|
+
];
|
|
604
|
+
case 1:
|
|
605
|
+
hexGasPrice = _state.sent();
|
|
606
|
+
return [
|
|
607
|
+
2,
|
|
608
|
+
tinyBig(hexToDecimal(hexGasPrice))
|
|
609
|
+
];
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
})();
|
|
613
|
+
};
|
|
350
614
|
/**
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
return (
|
|
370
|
-
|
|
371
|
-
|
|
615
|
+
* Returns the balance of the account in wei.
|
|
616
|
+
*
|
|
617
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getBalance`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBalance) in ethers.js
|
|
618
|
+
* * [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
|
|
619
|
+
*
|
|
620
|
+
* @param address the address to check the balance of
|
|
621
|
+
* @param blockTag the block to check the specified address' balance on
|
|
622
|
+
* @returns the balance of the network's native token for the specified address on the specified block
|
|
623
|
+
* @example
|
|
624
|
+
* ```javascript
|
|
625
|
+
* await provider.getBalance('0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8');
|
|
626
|
+
* // 28798127851528138
|
|
627
|
+
* ```
|
|
628
|
+
*/ _proto.getBalance = function getBalance(address) {
|
|
629
|
+
var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
|
|
630
|
+
var _this = this;
|
|
631
|
+
return _asyncToGenerator(function() {
|
|
632
|
+
var hexBalance;
|
|
633
|
+
return __generator(this, function(_state) {
|
|
634
|
+
switch(_state.label){
|
|
635
|
+
case 0:
|
|
636
|
+
blockTag = prepBlockTag(blockTag);
|
|
637
|
+
return [
|
|
638
|
+
4,
|
|
639
|
+
_this.post(buildRPCPostBody("eth_getBalance", [
|
|
640
|
+
address,
|
|
641
|
+
blockTag
|
|
642
|
+
]))
|
|
643
|
+
];
|
|
644
|
+
case 1:
|
|
645
|
+
hexBalance = _state.sent();
|
|
646
|
+
return [
|
|
647
|
+
2,
|
|
648
|
+
tinyBig(hexToDecimal(hexBalance))
|
|
649
|
+
];
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
})();
|
|
653
|
+
};
|
|
372
654
|
/**
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return
|
|
392
|
-
|
|
393
|
-
|
|
655
|
+
* Gets the code of a contract on a specified block.
|
|
656
|
+
*
|
|
657
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getCode`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getCode) in ethers.js
|
|
658
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getCode`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getcode) in web3.js
|
|
659
|
+
*
|
|
660
|
+
* @param address the contract address to get the contract code from
|
|
661
|
+
* @param blockTag the block height to search for the contract code from. Contract code can change, so this allows for checking a specific block
|
|
662
|
+
* @returns the contract creation code for the specified address at the specified block height
|
|
663
|
+
* @example
|
|
664
|
+
* ```javascript
|
|
665
|
+
* await jsonRpcProvider().getCode('0xaC6095720221C79C6E7C638d260A2eFBC5D8d880', 'latest');
|
|
666
|
+
* // '0x608060405234801561001057600080fd5b506004361061...'
|
|
667
|
+
* ```
|
|
668
|
+
*/ _proto.getCode = function getCode(address) {
|
|
669
|
+
var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
|
|
670
|
+
var _this = this;
|
|
671
|
+
return _asyncToGenerator(function() {
|
|
672
|
+
var contractCode;
|
|
673
|
+
return __generator(this, function(_state) {
|
|
674
|
+
switch(_state.label){
|
|
675
|
+
case 0:
|
|
676
|
+
blockTag = prepBlockTag(blockTag);
|
|
677
|
+
return [
|
|
678
|
+
4,
|
|
679
|
+
_this.post(buildRPCPostBody("eth_getCode", [
|
|
680
|
+
address,
|
|
681
|
+
blockTag
|
|
682
|
+
]))
|
|
683
|
+
];
|
|
684
|
+
case 1:
|
|
685
|
+
contractCode = _state.sent();
|
|
686
|
+
return [
|
|
687
|
+
2,
|
|
688
|
+
contractCode
|
|
689
|
+
];
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
})();
|
|
693
|
+
};
|
|
394
694
|
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
695
|
+
* Returns an estimate of the amount of gas that would be required to submit transaction to the network.
|
|
696
|
+
* An estimate may not be accurate since there could be another transaction on the network that was not accounted for.
|
|
697
|
+
*
|
|
698
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.estimateGas`](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas) in ethers.js
|
|
699
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.estimateGas`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#estimateGas) in web3.js
|
|
700
|
+
*
|
|
701
|
+
* @param transaction the transaction to check the estimated gas cost for
|
|
702
|
+
* @returns the estimated amount of gas charged for submitting the specified transaction to the blockchain
|
|
703
|
+
* @example
|
|
704
|
+
* ```javascript
|
|
705
|
+
* await provider.estimateGas({
|
|
706
|
+
* // Wrapped ETH address
|
|
707
|
+
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
708
|
+
* data: "0xd0e30db0",
|
|
709
|
+
* value: etherToWei('1.0').toHexString(),
|
|
710
|
+
* });
|
|
711
|
+
* // { TinyBig: "27938" }
|
|
712
|
+
* ```
|
|
713
|
+
*/ _proto.estimateGas = function estimateGas(transaction) {
|
|
714
|
+
var _this = this;
|
|
715
|
+
return _asyncToGenerator(function() {
|
|
716
|
+
var rpcTransaction, gasUsed;
|
|
717
|
+
return __generator(this, function(_state) {
|
|
718
|
+
switch(_state.label){
|
|
719
|
+
case 0:
|
|
720
|
+
rpcTransaction = prepareTransaction(transaction);
|
|
721
|
+
return [
|
|
722
|
+
4,
|
|
723
|
+
_this.post(buildRPCPostBody("eth_estimateGas", [
|
|
724
|
+
rpcTransaction
|
|
725
|
+
]))
|
|
726
|
+
];
|
|
727
|
+
case 1:
|
|
728
|
+
gasUsed = _state.sent();
|
|
729
|
+
return [
|
|
730
|
+
2,
|
|
731
|
+
tinyBig(hexToDecimal(gasUsed))
|
|
732
|
+
];
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
})();
|
|
736
|
+
};
|
|
421
737
|
/**
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
738
|
+
* Returns the current recommended FeeData to use in a transaction.
|
|
739
|
+
* For an EIP-1559 transaction, the maxFeePerGas and maxPriorityFeePerGas should be used.
|
|
740
|
+
* For legacy transactions and networks which do not support EIP-1559, the gasPrice should be used.Returns an estimate of the amount of gas that would be required to submit transaction to the network.
|
|
741
|
+
*
|
|
742
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getFeeData`](https://docs.ethers.org/v5/api/providers/provider/#Provider-getFeeData) in ethers.js
|
|
743
|
+
*
|
|
744
|
+
* @returns an object with gas estimates for the network currently
|
|
745
|
+
* @example
|
|
746
|
+
* ```javascript
|
|
747
|
+
* await provider.getFeeData();
|
|
748
|
+
* // {
|
|
749
|
+
* // gasPrice: { TinyBig: "14184772639" },
|
|
750
|
+
* // lastBaseFeePerGas: { TinyBig: "14038523098" },
|
|
751
|
+
* // maxFeePerGas: { TinyBig: "29577046196" },
|
|
752
|
+
* // maxPriorityFeePerGas: { TinyBig: "1500000000" }
|
|
753
|
+
* // }
|
|
754
|
+
* ```
|
|
755
|
+
*/ _proto.getFeeData = function getFeeData() {
|
|
756
|
+
var _this = this;
|
|
757
|
+
return _asyncToGenerator(function() {
|
|
758
|
+
var _ref, block, gasPrice, lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas;
|
|
759
|
+
return __generator(this, function(_state) {
|
|
760
|
+
switch(_state.label){
|
|
761
|
+
case 0:
|
|
762
|
+
return [
|
|
763
|
+
4,
|
|
764
|
+
Promise.all([
|
|
765
|
+
_this.getBlock("latest"),
|
|
766
|
+
_this.getGasPrice()
|
|
767
|
+
])
|
|
768
|
+
];
|
|
769
|
+
case 1:
|
|
770
|
+
_ref = _slicedToArray.apply(void 0, [
|
|
771
|
+
_state.sent(),
|
|
772
|
+
2
|
|
773
|
+
]), block = _ref[0], gasPrice = _ref[1];
|
|
774
|
+
lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;
|
|
775
|
+
if (block && block.baseFeePerGas) {
|
|
776
|
+
// We may want to compute this more accurately in the future,
|
|
777
|
+
// using the formula "check if the base fee is correct".
|
|
778
|
+
// See: https://eips.ethereum.org/EIPS/eip-1559
|
|
779
|
+
lastBaseFeePerGas = block.baseFeePerGas;
|
|
780
|
+
maxPriorityFeePerGas = tinyBig("1500000000");
|
|
781
|
+
maxFeePerGas = tinyBig(block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas));
|
|
782
|
+
}
|
|
783
|
+
return [
|
|
784
|
+
2,
|
|
785
|
+
{
|
|
786
|
+
lastBaseFeePerGas: lastBaseFeePerGas,
|
|
787
|
+
maxFeePerGas: maxFeePerGas,
|
|
788
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
789
|
+
gasPrice: gasPrice
|
|
790
|
+
}
|
|
791
|
+
];
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
})();
|
|
795
|
+
};
|
|
473
796
|
/**
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
797
|
+
* Returns transaction receipt event logs that match a specified filter.
|
|
798
|
+
* May return `[]` if parameters are too broad, even if logs exist.
|
|
799
|
+
*
|
|
800
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.getLogs`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getLogs) in ethers.js
|
|
801
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.getPastLogs`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getpastlogs) in web3.js
|
|
802
|
+
*
|
|
803
|
+
* @param filter parameters to filter the logs by
|
|
804
|
+
* @returns an array of logs matching the specified filter
|
|
805
|
+
* @example
|
|
806
|
+
* ```javascript
|
|
807
|
+
* provider.getLogs({
|
|
808
|
+
* address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
809
|
+
* topics: [
|
|
810
|
+
* "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
811
|
+
* "0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e",
|
|
812
|
+
* ],
|
|
813
|
+
* fromBlock: 14825027,
|
|
814
|
+
* toBlock: 14825039,
|
|
815
|
+
* });
|
|
816
|
+
*
|
|
817
|
+
* [
|
|
818
|
+
* {
|
|
819
|
+
* address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
820
|
+
* blockHash: '0x8e0dfac2f704851960f866c8708b3bef2f66c0fee0329cf25ff0261b264ca6bc',
|
|
821
|
+
* blockNumber: 14825029,
|
|
822
|
+
* data: '0x000000000000000000000000000000000000000000000000005f862ee352a38a',
|
|
823
|
+
* logIndex: 384,
|
|
824
|
+
* removed: false,
|
|
825
|
+
* topics: [
|
|
826
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
827
|
+
* '0x00000000000000000000000021b8065d10f73ee2e260e5b47d3344d3ced7596e',
|
|
828
|
+
* '0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45'
|
|
829
|
+
* ],
|
|
830
|
+
* transactionHash: '0xbd49031be16f8fd1775f4e0fe79b408ffd8ae9c65b2827ee47e3238e3f51f4c0',
|
|
831
|
+
* transactionIndex: 226
|
|
832
|
+
* }
|
|
833
|
+
* ]
|
|
834
|
+
* ```
|
|
835
|
+
*/ _proto.getLogs = function getLogs(filter) {
|
|
836
|
+
var _this = this;
|
|
837
|
+
return _asyncToGenerator(function() {
|
|
838
|
+
var filterByRange, rpcLogs, logs;
|
|
839
|
+
return __generator(this, function(_state) {
|
|
840
|
+
switch(_state.label){
|
|
841
|
+
case 0:
|
|
842
|
+
filterByRange = filter;
|
|
843
|
+
if (filterByRange.fromBlock) filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
|
|
844
|
+
if (filterByRange.toBlock) filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
|
|
845
|
+
return [
|
|
846
|
+
4,
|
|
847
|
+
_this.post(buildRPCPostBody("eth_getLogs", [
|
|
848
|
+
filter
|
|
849
|
+
]))
|
|
850
|
+
];
|
|
851
|
+
case 1:
|
|
852
|
+
rpcLogs = _state.sent();
|
|
853
|
+
logs = rpcLogs.map(function(log) {
|
|
854
|
+
return cleanLog(log, false);
|
|
855
|
+
});
|
|
856
|
+
return [
|
|
857
|
+
2,
|
|
858
|
+
logs
|
|
859
|
+
];
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
})();
|
|
863
|
+
};
|
|
864
|
+
/**
|
|
865
|
+
* Returns the result of adding a transaction to the blockchain without actually adding that transaction to the blockchain.
|
|
866
|
+
* Does not require any ether as gas.
|
|
867
|
+
*
|
|
868
|
+
* * [Identical](/docs/api#isd) to [`ethers.provider.call`](https://docs.ethers.io/v5/api/providers/provider/#Provider-call) in ethers.js
|
|
869
|
+
* * [Identical](/docs/api#isd) to [`web3.eth.call`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#call) in web3.js
|
|
870
|
+
*
|
|
871
|
+
* @param transaction the transaction object to, in theory, execute. Doesn't actually get added to the blockchain.
|
|
872
|
+
* @param blockTag the block to execute this transaction on
|
|
873
|
+
* @returns the result of executing the transaction on the specified block
|
|
874
|
+
* @example
|
|
875
|
+
* ```javascript
|
|
876
|
+
* await provider.call({ to: "0x6b175474e89094c44da98b954eedeac495271d0f", data: "0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE" });
|
|
877
|
+
* // '0x0000000000000000000000000000000000000000000000000858898f93629000'
|
|
878
|
+
* ```
|
|
879
|
+
*/ _proto.call = function call(transaction) {
|
|
880
|
+
var blockTag = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "latest";
|
|
881
|
+
var _this = this;
|
|
882
|
+
return _asyncToGenerator(function() {
|
|
883
|
+
var rpcTransaction, transactionRes;
|
|
884
|
+
return __generator(this, function(_state) {
|
|
885
|
+
switch(_state.label){
|
|
886
|
+
case 0:
|
|
887
|
+
if (transaction.gasPrice && (transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
|
|
888
|
+
logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
|
|
889
|
+
gasPrice: transaction.gasPrice,
|
|
890
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
891
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
|
|
895
|
+
logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
|
|
896
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
897
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
blockTag = prepBlockTag(blockTag);
|
|
901
|
+
rpcTransaction = prepareTransaction(transaction);
|
|
902
|
+
return [
|
|
903
|
+
4,
|
|
904
|
+
_this.post(buildRPCPostBody("eth_call", [
|
|
905
|
+
rpcTransaction,
|
|
906
|
+
blockTag
|
|
907
|
+
]))
|
|
908
|
+
];
|
|
909
|
+
case 1:
|
|
910
|
+
transactionRes = _state.sent();
|
|
911
|
+
return [
|
|
912
|
+
2,
|
|
913
|
+
transactionRes
|
|
914
|
+
];
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
})();
|
|
918
|
+
};
|
|
919
|
+
return BaseProvider;
|
|
920
|
+
}();
|