essential-eth 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/logger/package-version.d.ts +1 -1
- package/lib/cjs/logger/package-version.js +1 -1
- package/lib/cjs/providers/BaseProvider.d.ts +20 -0
- package/lib/cjs/providers/BaseProvider.js +25 -0
- package/lib/cjs/providers/types.d.ts +7 -0
- package/lib/cjs/providers/types.js +2 -0
- package/lib/cjs/utils/wei-to-ether.js +12 -2
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/logger/package-version.d.ts +1 -1
- package/lib/esm/logger/package-version.js +1 -1
- package/lib/esm/providers/BaseProvider.d.ts +2 -0
- package/lib/esm/providers/BaseProvider.js +7 -0
- package/lib/esm/providers/types.d.ts +7 -0
- package/lib/esm/providers/types.js +1 -0
- package/lib/esm/utils/wei-to-ether.js +11 -2
- package/package.json +1 -1
|
@@ -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_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_blockNumber';
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_blockNumber' | 'eth_estimateGas';
|
|
3
3
|
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { splitSignature } from './utils/split-signature';
|
|
|
17
17
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
18
18
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
19
19
|
import { weiToEther } from './utils/wei-to-ether';
|
|
20
|
+
export * from './providers/types';
|
|
20
21
|
export * from './utils/bytes';
|
|
21
22
|
export * from './utils/hash-message';
|
|
22
23
|
export * from './utils/keccak256';
|
package/lib/cjs/index.js
CHANGED
|
@@ -48,6 +48,7 @@ const to_utf8_bytes_1 = require("./utils/to-utf8-bytes");
|
|
|
48
48
|
Object.defineProperty(exports, "toUtf8Bytes", { enumerable: true, get: function () { return to_utf8_bytes_1.toUtf8Bytes; } });
|
|
49
49
|
const wei_to_ether_1 = require("./utils/wei-to-ether");
|
|
50
50
|
Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });
|
|
51
|
+
__exportStar(require("./providers/types"), exports);
|
|
51
52
|
__exportStar(require("./utils/bytes"), exports);
|
|
52
53
|
__exportStar(require("./utils/hash-message"), exports);
|
|
53
54
|
__exportStar(require("./utils/keccak256"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.5.
|
|
1
|
+
export declare const version = "0.5.6";
|
|
@@ -2,6 +2,7 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
2
2
|
import { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
3
|
import { Network } from '../types/Network.types';
|
|
4
4
|
import { TransactionReceipt, TransactionResponse } from '../types/Transaction.types';
|
|
5
|
+
import { TransactionRequest } from './types';
|
|
5
6
|
export declare abstract class BaseProvider {
|
|
6
7
|
/**
|
|
7
8
|
* ignore
|
|
@@ -281,4 +282,23 @@ export declare abstract class BaseProvider {
|
|
|
281
282
|
* ```
|
|
282
283
|
*/
|
|
283
284
|
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
285
|
+
/**
|
|
286
|
+
* Returns an estimate of the amount of gas that would be required to submit transaction to the network.
|
|
287
|
+
* An estimate may not be accurate since there could be another transaction on the network that was not accounted for, but after being mined affected relevant state.
|
|
288
|
+
*
|
|
289
|
+
* * Same as ["estimateGas" in ethers.js](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas)
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```js
|
|
293
|
+
* await provider.estimateGas({
|
|
294
|
+
* // Wrapped ETH address
|
|
295
|
+
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
296
|
+
* data: "0xd0e30db0",
|
|
297
|
+
* value: etherToWei('1.0').toHexString(),
|
|
298
|
+
* });
|
|
299
|
+
* // { TinyBig: "27938" }
|
|
300
|
+
*
|
|
301
|
+
* ```
|
|
302
|
+
* */
|
|
303
|
+
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
284
304
|
}
|
|
@@ -376,5 +376,30 @@ class BaseProvider {
|
|
|
376
376
|
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(hexBalance));
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* Returns an estimate of the amount of gas that would be required to submit transaction to the network.
|
|
381
|
+
* An estimate may not be accurate since there could be another transaction on the network that was not accounted for, but after being mined affected relevant state.
|
|
382
|
+
*
|
|
383
|
+
* * Same as ["estimateGas" in ethers.js](https://docs.ethers.io/v5/api/providers/provider/#Provider-estimateGas)
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```js
|
|
387
|
+
* await provider.estimateGas({
|
|
388
|
+
* // Wrapped ETH address
|
|
389
|
+
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
390
|
+
* data: "0xd0e30db0",
|
|
391
|
+
* value: etherToWei('1.0').toHexString(),
|
|
392
|
+
* });
|
|
393
|
+
* // { TinyBig: "27938" }
|
|
394
|
+
*
|
|
395
|
+
* ```
|
|
396
|
+
* */
|
|
397
|
+
estimateGas(transaction) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
const body = (0, fetchers_1.buildRPCPostBody)('eth_estimateGas', [transaction]);
|
|
400
|
+
const gasUsed = (yield this.post(body));
|
|
401
|
+
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(gasUsed));
|
|
402
|
+
});
|
|
403
|
+
}
|
|
379
404
|
}
|
|
380
405
|
exports.BaseProvider = BaseProvider;
|
|
@@ -28,7 +28,17 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
28
28
|
*/
|
|
29
29
|
function weiToEther(weiQuantity) {
|
|
30
30
|
(0, validate_type_1.validateType)(weiQuantity, ['string', 'number', 'object']);
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// eslint-disable-next-line no-useless-catch
|
|
32
|
+
try {
|
|
33
|
+
let _weiQuantity = weiQuantity;
|
|
34
|
+
if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
|
|
35
|
+
_weiQuantity = BigInt(weiQuantity).toString();
|
|
36
|
+
}
|
|
37
|
+
const result = (0, tiny_big_1.tinyBig)(_weiQuantity).div('1000000000000000000');
|
|
38
|
+
return (0, tiny_big_1.tinyBig)(result);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
44
|
exports.weiToEther = weiToEther;
|
|
@@ -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_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_blockNumber';
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_blockNumber' | 'eth_estimateGas';
|
|
3
3
|
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { splitSignature } from './utils/split-signature';
|
|
|
17
17
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
18
18
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
19
19
|
import { weiToEther } from './utils/wei-to-ether';
|
|
20
|
+
export * from './providers/types';
|
|
20
21
|
export * from './utils/bytes';
|
|
21
22
|
export * from './utils/hash-message';
|
|
22
23
|
export * from './utils/keccak256';
|
package/lib/esm/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { splitSignature } from './utils/split-signature';
|
|
|
13
13
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
14
14
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
15
15
|
import { weiToEther } from './utils/wei-to-ether';
|
|
16
|
+
export * from './providers/types';
|
|
16
17
|
export * from './utils/bytes';
|
|
17
18
|
export * from './utils/hash-message';
|
|
18
19
|
export * from './utils/keccak256';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.5.
|
|
1
|
+
export declare const version = "0.5.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.5.
|
|
1
|
+
export const version = '0.5.6';
|
|
@@ -2,6 +2,7 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
2
2
|
import { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
3
|
import { Network } from '../types/Network.types';
|
|
4
4
|
import { TransactionReceipt, TransactionResponse } from '../types/Transaction.types';
|
|
5
|
+
import { TransactionRequest } from './types';
|
|
5
6
|
export declare abstract class BaseProvider {
|
|
6
7
|
abstract selectRpcUrl(): string;
|
|
7
8
|
abstract post(body: Record<string, unknown>): Promise<any>;
|
|
@@ -16,4 +17,5 @@ export declare abstract class BaseProvider {
|
|
|
16
17
|
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
17
18
|
getGasPrice(): Promise<TinyBig>;
|
|
18
19
|
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
20
|
+
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
19
21
|
}
|
|
@@ -104,4 +104,11 @@ export class BaseProvider {
|
|
|
104
104
|
return tinyBig(hexToDecimal(hexBalance));
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
+
estimateGas(transaction) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const body = buildRPCPostBody('eth_estimateGas', [transaction]);
|
|
110
|
+
const gasUsed = (yield this.post(body));
|
|
111
|
+
return tinyBig(hexToDecimal(gasUsed));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
107
114
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,6 +2,15 @@ import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
2
2
|
import { validateType } from '../shared/validate-type';
|
|
3
3
|
export function weiToEther(weiQuantity) {
|
|
4
4
|
validateType(weiQuantity, ['string', 'number', 'object']);
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
try {
|
|
6
|
+
let _weiQuantity = weiQuantity;
|
|
7
|
+
if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
|
|
8
|
+
_weiQuantity = BigInt(weiQuantity).toString();
|
|
9
|
+
}
|
|
10
|
+
const result = tinyBig(_weiQuantity).div('1000000000000000000');
|
|
11
|
+
return tinyBig(result);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
7
16
|
}
|