essential-eth 0.4.6 → 0.4.9-alpha.1

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.
@@ -1,7 +1,7 @@
1
1
  export declare type ContractTypes = 'bool' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' | 'bytes32[]' | 'address' | 'address payable' | 'address[4]' | 'address[100]' | 'uint256' | 'uint256[100]' | 'uint8' | 'uint32' | string;
2
2
  export declare type ContractInterface = JSONABI;
3
3
  export declare type ContractFunction<T = any> = (...args: Array<any>) => Promise<T>;
4
- export declare type JSONABIArgument = {
4
+ export interface JSONABIArgument {
5
5
  anonymous?: false;
6
6
  inputs: {
7
7
  internalType?: ContractTypes | string;
@@ -16,9 +16,9 @@ export declare type JSONABIArgument = {
16
16
  type: ContractTypes;
17
17
  }[];
18
18
  stateMutability?: 'view' | 'nonpayable' | string;
19
- type: 'function' | 'event' | 'constructor' | 'error';
19
+ type: 'function' | 'event' | 'constructor' | 'error' | 'fallback';
20
20
  gas?: number;
21
21
  constant?: boolean;
22
22
  payable?: boolean;
23
- };
23
+ }
24
24
  export declare type JSONABI = JSONABIArgument[];
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * A trimmed version of https://chainid.network/chains.json
3
3
  */
4
- export declare type Network = {
4
+ export interface Network {
5
5
  chainId: number;
6
6
  ensAddress: string | null;
7
7
  name: string;
8
- };
8
+ }
@@ -1,9 +1,8 @@
1
1
  import { JsonRpcProvider } from '../providers/JsonRpcProvider';
2
2
  import { ContractInterface } from '../types/Contract.types';
3
3
  export declare class BaseContract {
4
- readonly _address: string;
5
- readonly _contractInterface: ContractInterface;
6
- readonly _provider: JsonRpcProvider;
4
+ private readonly _address;
5
+ private readonly _provider;
7
6
  constructor(addressOrName: string, contractInterface: ContractInterface, signerOrProvider: JsonRpcProvider);
8
7
  }
9
8
  export declare function defineReadOnly<T>(object: T, name: string, value: any): void;
@@ -18,7 +18,6 @@ function estimateGas(txnData) {
18
18
  export class BaseContract {
19
19
  constructor(addressOrName, contractInterface, signerOrProvider) {
20
20
  this._address = addressOrName;
21
- this._contractInterface = contractInterface;
22
21
  this._provider = signerOrProvider;
23
22
  contractInterface
24
23
  .filter((jsonABIArgument) => jsonABIArgument.type === 'function')
@@ -40,12 +39,15 @@ export class BaseContract {
40
39
  'number'
41
40
  ? estimateGas(data)
42
41
  : null;
43
- const nodeResponse = yield post(this._provider._rpcUrl, buildRPCPostBody('eth_call', [
44
- Object.assign({ to: this._address.toLowerCase(), data: data }, (decimalGas
45
- ? { gas: `0x${decimalGas.toString(16)}` }
46
- : {})),
47
- 'latest',
48
- ]));
42
+ const req = () => __awaiter(this, void 0, void 0, function* () {
43
+ return yield post(this._provider._rpcUrl, buildRPCPostBody('eth_call', [
44
+ Object.assign({ to: this._address.toLowerCase(), data }, (decimalGas
45
+ ? { gas: `0x${decimalGas.toString(16)}` }
46
+ : {})),
47
+ 'latest',
48
+ ]));
49
+ });
50
+ const nodeResponse = yield req();
49
51
  return decodeRPCResponse(jsonABIArgument, nodeResponse);
50
52
  }));
51
53
  }
@@ -1,5 +1,5 @@
1
1
  export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId';
2
+ declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice';
3
3
  export declare function buildRPCPostBody(method: RPCMethodName, params: any[]): {
4
4
  jsonrpc: string;
5
5
  id: number;
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import unfetch from 'isomorphic-unfetch';
2
11
  export function post(url, body) {
3
12
  return unfetch(url, {
@@ -7,10 +16,19 @@ export function post(url, body) {
7
16
  },
8
17
  body: JSON.stringify(body),
9
18
  })
10
- .then((r) => r.json())
19
+ .then((r) => __awaiter(this, void 0, void 0, function* () {
20
+ const t = yield r.text();
21
+ try {
22
+ return JSON.parse(t);
23
+ }
24
+ catch (_a) {
25
+ throw new Error(`Invalid JSON RPC response: "${t}"`);
26
+ }
27
+ }))
11
28
  .then((response) => {
12
- if (response.error) {
13
- throw new Error(response.error);
29
+ const result = response === null || response === void 0 ? void 0 : response.result;
30
+ if (!result) {
31
+ throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
14
32
  }
15
33
  return response.result;
16
34
  });
@@ -1,9 +1,11 @@
1
+ import { TinyBig } from '../shared/tiny-big/tiny-big';
1
2
  import { Block } from '../types/Block.types';
2
3
  import { Network } from '../types/Network.types';
3
4
  export declare class JsonRpcProvider {
4
- _rpcUrl: string;
5
+ readonly _rpcUrl: string;
5
6
  constructor(rpcUrl?: string);
6
7
  getBlock(timeFrame: 'latest' | 'earliest' | 'pending' | number, returnTransactionObjects?: boolean): Promise<Block>;
7
8
  getNetwork(): Promise<Network>;
9
+ getGasPrice(): Promise<TinyBig>;
8
10
  }
9
11
  export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { cleanBlock } from '../classes/utils/clean-block';
11
11
  import { buildRPCPostBody, post } from '../classes/utils/fetchers';
12
12
  import { hexToDecimal } from '../classes/utils/hex-to-decimal';
13
+ import { tinyBig } from '../shared/tiny-big/tiny-big';
13
14
  import chainsInfo from './utils/chains-info';
14
15
  export class JsonRpcProvider {
15
16
  constructor(rpcUrl) {
@@ -24,16 +25,22 @@ export class JsonRpcProvider {
24
25
  else {
25
26
  rpcTimeFrame = timeFrame;
26
27
  }
27
- const nodeResponse = (yield post(this._rpcUrl, buildRPCPostBody('eth_getBlockByNumber', [
28
- rpcTimeFrame,
29
- returnTransactionObjects,
30
- ])));
28
+ const req = () => __awaiter(this, void 0, void 0, function* () {
29
+ return yield post(this._rpcUrl, buildRPCPostBody('eth_getBlockByNumber', [
30
+ rpcTimeFrame,
31
+ returnTransactionObjects,
32
+ ]));
33
+ });
34
+ const nodeResponse = (yield req());
31
35
  return cleanBlock(nodeResponse, returnTransactionObjects);
32
36
  });
33
37
  }
34
38
  getNetwork() {
35
39
  return __awaiter(this, void 0, void 0, function* () {
36
- const nodeResponse = (yield post(this._rpcUrl, buildRPCPostBody('eth_chainId', [])));
40
+ const req = () => __awaiter(this, void 0, void 0, function* () {
41
+ return yield post(this._rpcUrl, buildRPCPostBody('eth_chainId', []));
42
+ });
43
+ const nodeResponse = (yield req());
37
44
  const chainId = hexToDecimal(nodeResponse);
38
45
  const info = chainsInfo[chainId];
39
46
  return {
@@ -43,6 +50,15 @@ export class JsonRpcProvider {
43
50
  };
44
51
  });
45
52
  }
53
+ getGasPrice() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const req = () => __awaiter(this, void 0, void 0, function* () {
56
+ return yield post(this._rpcUrl, buildRPCPostBody('eth_gasPrice', []));
57
+ });
58
+ const nodeResponse = (yield req());
59
+ return tinyBig(hexToDecimal(nodeResponse));
60
+ });
61
+ }
46
62
  }
47
63
  export function jsonRpcProvider(rpcUrl) {
48
64
  return new JsonRpcProvider(rpcUrl);
@@ -0,0 +1,3 @@
1
+ export declare const fakeUrls: {
2
+ readonly notRPCButRealHttp: "https://httpstat.us/200";
3
+ };
@@ -0,0 +1,3 @@
1
+ export const fakeUrls = {
2
+ notRPCButRealHttp: 'https://httpstat.us/200',
3
+ };
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  "51": string[];
46
46
  "52": string[];
47
47
  "53": string[];
48
+ "54": string[];
48
49
  "55": string[];
49
50
  "56": string[];
50
51
  "57": string[];
@@ -84,6 +85,7 @@ declare const _default: {
84
85
  "100": string[];
85
86
  "101": string[];
86
87
  "102": string[];
88
+ "105": string[];
87
89
  "106": string[];
88
90
  "107": string[];
89
91
  "108": string[];
@@ -97,9 +99,11 @@ declare const _default: {
97
99
  "127": string[];
98
100
  "128": string[];
99
101
  "137": string[];
102
+ "141": string[];
100
103
  "142": string[];
101
104
  "162": string[];
102
105
  "163": string[];
106
+ "168": string[];
103
107
  "170": string[];
104
108
  "172": string[];
105
109
  "186": string[];
@@ -108,16 +112,21 @@ declare const _default: {
108
112
  "199": string[];
109
113
  "200": string[];
110
114
  "211": string[];
115
+ "218": string[];
111
116
  "222": string[];
117
+ "225": string[];
118
+ "226": string[];
112
119
  "246": string[];
113
120
  "250": string[];
114
121
  "256": string[];
122
+ "258": string[];
115
123
  "262": string[];
116
124
  "269": string[];
117
125
  "288": string[];
118
126
  "321": string[];
119
127
  "322": string[];
120
128
  "333": string[];
129
+ "335": string[];
121
130
  "336": string[];
122
131
  "338": string[];
123
132
  "361": string[];
@@ -128,6 +137,8 @@ declare const _default: {
128
137
  "385": string[];
129
138
  "420": string[];
130
139
  "499": string[];
140
+ "512": string[];
141
+ "513": string[];
131
142
  "555": string[];
132
143
  "558": string[];
133
144
  "588": string[];
@@ -140,6 +151,7 @@ declare const _default: {
140
151
  "721": string[];
141
152
  "777": string[];
142
153
  "787": string[];
154
+ "788": string[];
143
155
  "803": string[];
144
156
  "820": string[];
145
157
  "821": string[];
@@ -150,6 +162,8 @@ declare const _default: {
150
162
  "902": string[];
151
163
  "903": string[];
152
164
  "940": string[];
165
+ "941": string[];
166
+ "942": string[];
153
167
  "977": string[];
154
168
  "998": string[];
155
169
  "999": string[];
@@ -166,35 +180,53 @@ declare const _default: {
166
180
  "1139": string[];
167
181
  "1140": string[];
168
182
  "1197": string[];
183
+ "1201": string[];
169
184
  "1202": string[];
170
185
  "1213": string[];
171
186
  "1214": string[];
172
187
  "1280": string[];
173
188
  "1284": string[];
174
189
  "1285": string[];
190
+ "1286": string[];
175
191
  "1287": string[];
176
192
  "1288": string[];
193
+ "1337": string[];
177
194
  "1618": string[];
178
195
  "1620": string[];
179
196
  "1657": string[];
197
+ "1688": string[];
180
198
  "1856": string[];
199
+ "1898": string[];
181
200
  "1987": string[];
201
+ "2001": string[];
182
202
  "2020": string[];
183
203
  "2021": string[];
184
204
  "2022": string[];
185
205
  "2025": string[];
186
206
  "2100": string[];
187
207
  "2101": string[];
208
+ "2213": string[];
209
+ "2221": string[];
188
210
  "2559": string[];
211
+ "3000": string[];
212
+ "3001": string[];
189
213
  "3331": string[];
190
214
  "3333": string[];
215
+ "3334": string[];
216
+ "3400": string[];
217
+ "3500": string[];
191
218
  "3690": string[];
219
+ "3966": string[];
220
+ "3967": string[];
192
221
  "4002": string[];
222
+ "4102": string[];
193
223
  "4689": string[];
194
224
  "4690": string[];
225
+ "4918": string[];
195
226
  "5197": string[];
196
227
  "5315": string[];
197
228
  "5700": string[];
229
+ "5777": string[];
198
230
  "5851": string[];
199
231
  "5869": string[];
200
232
  "6626": string[];
@@ -218,6 +250,7 @@ declare const _default: {
218
250
  "10000": string[];
219
251
  "10001": string[];
220
252
  "10101": string[];
253
+ "10823": string[];
221
254
  "11111": string[];
222
255
  "11437": string[];
223
256
  "12051": string[];
@@ -226,6 +259,7 @@ declare const _default: {
226
259
  "16000": string[];
227
260
  "16001": string[];
228
261
  "19845": string[];
262
+ "21816": string[];
229
263
  "24484": string[];
230
264
  "24734": string[];
231
265
  "31102": string[];
@@ -241,8 +275,10 @@ declare const _default: {
241
275
  "43113": string[];
242
276
  "43114": string[];
243
277
  "44787": string[];
278
+ "45000": string[];
244
279
  "47805": string[];
245
280
  "49797": string[];
281
+ "53935": string[];
246
282
  "55555": string[];
247
283
  "55556": string[];
248
284
  "60000": string[];
@@ -281,23 +317,26 @@ declare const _default: {
281
317
  "110006": string[];
282
318
  "110007": string[];
283
319
  "110008": string[];
320
+ "200101": string[];
284
321
  "200625": string[];
285
322
  "201018": string[];
286
323
  "201030": string[];
287
- "210309": string[];
288
324
  "210425": string[];
325
+ "234666": string[];
289
326
  "246529": string[];
290
327
  "246785": string[];
291
328
  "281121": string[];
292
329
  "333888": string[];
293
330
  "333999": string[];
294
331
  "421611": string[];
332
+ "444900": string[];
295
333
  "666666": string[];
296
334
  "888888": string[];
297
335
  "955305": string[];
298
336
  "1313114": string[];
299
337
  "1313500": string[];
300
338
  "1337702": string[];
339
+ "2203181": string[];
301
340
  "7762959": string[];
302
341
  "11155111": string[];
303
342
  "13371337": string[];
@@ -334,5 +373,6 @@ declare const _default: {
334
373
  "197710212030": string[];
335
374
  "197710212031": string[];
336
375
  "6022140761023": string[];
376
+ "868455272153094": string[];
337
377
  };
338
378
  export default _default;