essential-eth 0.4.9 → 0.5.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/cjs/classes/utils/clean-block.d.ts +3 -3
- package/lib/cjs/classes/utils/clean-block.js +3 -2
- package/lib/cjs/classes/utils/clean-transaction.d.ts +3 -3
- package/lib/cjs/classes/utils/clean-transaction.js +10 -6
- package/lib/cjs/classes/utils/fetchers.d.ts +3 -3
- package/lib/cjs/index.d.ts +6 -3
- package/lib/cjs/index.js +7 -1
- package/lib/cjs/providers/JsonRpcProvider.d.ts +198 -3
- package/lib/cjs/providers/JsonRpcProvider.js +222 -19
- package/lib/cjs/providers/test/rpc-urls.d.ts +7 -0
- package/lib/cjs/providers/test/rpc-urls.js +8 -1
- package/lib/cjs/providers/utils/chains-info.d.ts +10 -0
- package/lib/cjs/providers/utils/chains-info.js +31 -1
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +6 -0
- package/lib/cjs/shared/tiny-big/tiny-big.js +13 -1
- package/lib/cjs/types/Block.types.d.ts +9 -19
- package/lib/cjs/types/Transaction.types.d.ts +23 -14
- package/lib/cjs/utils/ether-to-gwei.d.ts +26 -0
- package/lib/cjs/utils/ether-to-gwei.js +34 -0
- package/lib/cjs/utils/ether-to-wei.d.ts +4 -2
- package/lib/cjs/utils/ether-to-wei.js +4 -2
- package/lib/cjs/utils/gwei-to-ether.d.ts +26 -0
- package/lib/cjs/utils/gwei-to-ether.js +34 -0
- package/lib/cjs/utils/hex-zero-pad.d.ts +32 -0
- package/lib/cjs/utils/hex-zero-pad.js +52 -0
- package/lib/cjs/utils/is-address.d.ts +19 -0
- package/lib/cjs/utils/is-address.js +19 -0
- package/lib/cjs/utils/to-checksum-address.d.ts +2 -2
- package/lib/cjs/utils/to-checksum-address.js +2 -2
- package/lib/cjs/utils/wei-to-ether.d.ts +12 -12
- package/lib/cjs/utils/wei-to-ether.js +11 -11
- package/lib/esm/classes/utils/clean-block.d.ts +2 -2
- package/lib/esm/classes/utils/clean-block.js +2 -1
- package/lib/esm/classes/utils/clean-transaction.d.ts +2 -2
- package/lib/esm/classes/utils/clean-transaction.js +10 -6
- package/lib/esm/classes/utils/fetchers.d.ts +3 -3
- package/lib/esm/index.d.ts +6 -3
- package/lib/esm/index.js +4 -1
- package/lib/esm/providers/JsonRpcProvider.d.ts +6 -2
- package/lib/esm/providers/JsonRpcProvider.js +29 -18
- package/lib/esm/providers/test/rpc-urls.d.ts +7 -0
- package/lib/esm/providers/test/rpc-urls.js +7 -0
- package/lib/esm/providers/utils/chains-info.d.ts +10 -0
- package/lib/esm/providers/utils/chains-info.js +31 -1
- package/lib/esm/shared/tiny-big/tiny-big.js +7 -1
- package/lib/esm/types/Block.types.d.ts +8 -19
- package/lib/esm/types/Transaction.types.d.ts +22 -14
- package/lib/esm/utils/ether-to-gwei.d.ts +3 -0
- package/lib/esm/utils/ether-to-gwei.js +7 -0
- package/lib/esm/utils/gwei-to-ether.d.ts +3 -0
- package/lib/esm/utils/gwei-to-ether.js +7 -0
- package/lib/esm/utils/hex-zero-pad.d.ts +1 -0
- package/lib/esm/utils/hex-zero-pad.js +17 -0
- package/lib/esm/utils/wei-to-ether.d.ts +1 -1
- package/package.json +7 -7
- package/readme.md +302 -62
|
@@ -4,26 +4,26 @@ exports.weiToEther = void 0;
|
|
|
4
4
|
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
5
|
const validate_type_1 = require("../shared/validate-type");
|
|
6
6
|
/**
|
|
7
|
-
* Convert from
|
|
7
|
+
* Convert from Wei to Ether
|
|
8
8
|
*
|
|
9
|
-
* Similar to ["formatEther" in ethers.js](https://docs.ethers.io/
|
|
9
|
+
* Similar to ["formatEther" in ethers.js](https://docs.ethers.io/v5/api/utils/display-logic/#utils-formatEther)
|
|
10
10
|
*
|
|
11
|
-
* Similar to ["fromWei" in web3](https://web3js.readthedocs.io/en/v1.
|
|
11
|
+
* Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```javascript
|
|
15
|
-
*
|
|
16
|
-
* // '
|
|
17
|
-
*
|
|
18
|
-
* '
|
|
15
|
+
* weiToEther('1000000000000000000000').toString()
|
|
16
|
+
* // '1000'
|
|
17
|
+
* weiToEther(1000000000000000000000).toString()
|
|
18
|
+
* // '1000'
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* ```javascript
|
|
23
|
-
*
|
|
24
|
-
* //
|
|
25
|
-
*
|
|
26
|
-
* //
|
|
23
|
+
* weiToEther('1000000000000000000000').toNumber()
|
|
24
|
+
* // 1000
|
|
25
|
+
* weiToEther(1000000000000000000000).toNumber()
|
|
26
|
+
* // 1000
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
function weiToEther(weiQuantity) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockResponse } from '../..';
|
|
2
2
|
import { RPCBlock } from '../../types/Block.types';
|
|
3
|
-
export declare function cleanBlock(block: RPCBlock, returnTransactionObjects: boolean):
|
|
3
|
+
export declare function cleanBlock(block: RPCBlock, returnTransactionObjects: boolean): BlockResponse;
|
|
@@ -27,7 +27,8 @@ export function cleanBlock(block, returnTransactionObjects) {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
if (returnTransactionObjects) {
|
|
30
|
-
|
|
30
|
+
const txns = block.transactions;
|
|
31
|
+
txns.forEach((transaction, index) => {
|
|
31
32
|
cleanedBlock.transactions[index] = cleanTransaction(transaction);
|
|
32
33
|
});
|
|
33
34
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RPCTransaction,
|
|
2
|
-
export declare function cleanTransaction(transaction: RPCTransaction):
|
|
1
|
+
import { RPCTransaction, TransactionResponse } from '../../types/Transaction.types';
|
|
2
|
+
export declare function cleanTransaction(transaction: RPCTransaction): TransactionResponse;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toChecksumAddress } from '../..';
|
|
1
|
+
import { tinyBig, toChecksumAddress } from '../..';
|
|
2
2
|
import { hexToDecimal } from './hex-to-decimal';
|
|
3
3
|
export function cleanTransaction(transaction) {
|
|
4
4
|
const cleanedTransaction = Object.assign({}, transaction);
|
|
@@ -7,22 +7,26 @@ export function cleanTransaction(transaction) {
|
|
|
7
7
|
return;
|
|
8
8
|
switch (key) {
|
|
9
9
|
case 'blockNumber':
|
|
10
|
-
case '
|
|
10
|
+
case 'chainId':
|
|
11
11
|
case 'nonce':
|
|
12
12
|
case 'transactionIndex':
|
|
13
13
|
case 'type':
|
|
14
|
+
case 'v':
|
|
14
15
|
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
15
16
|
break;
|
|
16
|
-
case 'gasPrice':
|
|
17
|
-
case 'value':
|
|
18
|
-
cleanedTransaction[key] = hexToDecimal(transaction[key]);
|
|
19
|
-
break;
|
|
20
17
|
case 'from':
|
|
21
18
|
case 'to':
|
|
22
19
|
if (transaction[key]) {
|
|
23
20
|
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
24
21
|
}
|
|
25
22
|
break;
|
|
23
|
+
case 'value':
|
|
24
|
+
case 'gas':
|
|
25
|
+
case 'gasPrice':
|
|
26
|
+
case 'maxFeePerGas':
|
|
27
|
+
case 'maxPriorityFeePerGas':
|
|
28
|
+
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
29
|
+
break;
|
|
26
30
|
}
|
|
27
31
|
});
|
|
28
32
|
return cleanedTransaction;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
2
|
-
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice';
|
|
3
|
-
export declare function buildRPCPostBody(method: RPCMethodName, params:
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash';
|
|
3
|
+
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
|
6
6
|
method: RPCMethodName;
|
|
7
|
-
params:
|
|
7
|
+
params: unknown[];
|
|
8
8
|
};
|
|
9
9
|
export {};
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Contract } from './classes/Contract';
|
|
2
2
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
3
3
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
4
|
-
import {
|
|
4
|
+
import { BlockResponse } from './types/Block.types';
|
|
5
5
|
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
6
6
|
import { Network } from './types/Network.types';
|
|
7
|
-
import {
|
|
7
|
+
import { TransactionResponse } from './types/Transaction.types';
|
|
8
|
+
import { etherToGwei } from './utils/ether-to-gwei';
|
|
8
9
|
import { etherToWei } from './utils/ether-to-wei';
|
|
10
|
+
import { gweiToEther } from './utils/gwei-to-ether';
|
|
11
|
+
import { hexZeroPad } from './utils/hex-zero-pad';
|
|
9
12
|
import { isAddress } from './utils/is-address';
|
|
10
13
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
11
14
|
import { weiToEther } from './utils/wei-to-ether';
|
|
12
|
-
export { etherToWei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, Contract, TinyBig,
|
|
15
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hexZeroPad, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Contract } from './classes/Contract';
|
|
2
2
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
3
3
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
4
|
+
import { etherToGwei } from './utils/ether-to-gwei';
|
|
4
5
|
import { etherToWei } from './utils/ether-to-wei';
|
|
6
|
+
import { gweiToEther } from './utils/gwei-to-ether';
|
|
7
|
+
import { hexZeroPad } from './utils/hex-zero-pad';
|
|
5
8
|
import { isAddress } from './utils/is-address';
|
|
6
9
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
7
10
|
import { weiToEther } from './utils/wei-to-ether';
|
|
8
|
-
export { etherToWei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, Contract, TinyBig, };
|
|
11
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hexZeroPad, Contract, TinyBig, };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
-
import {
|
|
2
|
+
import { BlockResponse, BlockTag } from '../types/Block.types';
|
|
3
3
|
import { Network } from '../types/Network.types';
|
|
4
|
+
import { TransactionResponse } from '../types/Transaction.types';
|
|
4
5
|
export declare class JsonRpcProvider {
|
|
5
6
|
readonly _rpcUrl: string;
|
|
7
|
+
private post;
|
|
6
8
|
constructor(rpcUrl?: string);
|
|
7
|
-
getBlock(timeFrame:
|
|
9
|
+
getBlock(timeFrame: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
8
10
|
getNetwork(): Promise<Network>;
|
|
9
11
|
getGasPrice(): Promise<TinyBig>;
|
|
12
|
+
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
13
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
10
14
|
}
|
|
11
15
|
export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
|
|
@@ -8,12 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { cleanBlock } from '../classes/utils/clean-block';
|
|
11
|
+
import { cleanTransaction } from '../classes/utils/clean-transaction';
|
|
11
12
|
import { buildRPCPostBody, post } from '../classes/utils/fetchers';
|
|
12
13
|
import { hexToDecimal } from '../classes/utils/hex-to-decimal';
|
|
13
14
|
import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
14
15
|
import chainsInfo from './utils/chains-info';
|
|
15
16
|
export class JsonRpcProvider {
|
|
16
17
|
constructor(rpcUrl) {
|
|
18
|
+
this.post = (body) => post(this._rpcUrl, body);
|
|
17
19
|
this._rpcUrl = rpcUrl || 'https://free-eth-node.com/api/eth';
|
|
18
20
|
}
|
|
19
21
|
getBlock(timeFrame, returnTransactionObjects = false) {
|
|
@@ -25,23 +27,17 @@ export class JsonRpcProvider {
|
|
|
25
27
|
else {
|
|
26
28
|
rpcTimeFrame = timeFrame;
|
|
27
29
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
const nodeResponse = (yield req());
|
|
35
|
-
return cleanBlock(nodeResponse, returnTransactionObjects);
|
|
30
|
+
const rpcBlock = (yield this.post(buildRPCPostBody('eth_getBlockByNumber', [
|
|
31
|
+
rpcTimeFrame,
|
|
32
|
+
returnTransactionObjects,
|
|
33
|
+
])));
|
|
34
|
+
return cleanBlock(rpcBlock, returnTransactionObjects);
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
getNetwork() {
|
|
39
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
const nodeResponse = (yield req());
|
|
44
|
-
const chainId = hexToDecimal(nodeResponse);
|
|
39
|
+
const hexChainId = (yield this.post(buildRPCPostBody('eth_chainId', [])));
|
|
40
|
+
const chainId = hexToDecimal(hexChainId);
|
|
45
41
|
const info = chainsInfo[chainId];
|
|
46
42
|
return {
|
|
47
43
|
chainId: Number(chainId),
|
|
@@ -52,11 +48,26 @@ export class JsonRpcProvider {
|
|
|
52
48
|
}
|
|
53
49
|
getGasPrice() {
|
|
54
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
const hexGasPrice = (yield this.post(buildRPCPostBody('eth_gasPrice', [])));
|
|
52
|
+
return tinyBig(hexToDecimal(hexGasPrice));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getBalance(address, blockTag = 'latest') {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const hexBalance = (yield this.post(buildRPCPostBody('eth_getBalance', [address, blockTag])));
|
|
58
|
+
return tinyBig(hexToDecimal(hexBalance));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getTransaction(hash) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
64
|
+
this.post(buildRPCPostBody('eth_getTransactionByHash', [hash])),
|
|
65
|
+
this.getBlock('latest'),
|
|
66
|
+
]);
|
|
67
|
+
const cleanedTransaction = cleanTransaction(rpcTransaction);
|
|
68
|
+
cleanedTransaction.confirmations =
|
|
69
|
+
blockNumber.number - cleanedTransaction.blockNumber + 1;
|
|
70
|
+
return cleanedTransaction;
|
|
60
71
|
});
|
|
61
72
|
}
|
|
62
73
|
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
export const fakeUrls = {
|
|
2
2
|
notRPCButRealHttp: 'https://httpstat.us/200',
|
|
3
3
|
};
|
|
4
|
+
export const rpcUrls = {
|
|
5
|
+
mainnet: `${process.env.RPC_ORIGIN}/api/eth`,
|
|
6
|
+
gno: `${process.env.RPC_ORIGIN}/api/gno`,
|
|
7
|
+
bnb: `${process.env.RPC_ORIGIN}/api/bnb`,
|
|
8
|
+
arb1: `${process.env.RPC_ORIGIN}/api/arb1`,
|
|
9
|
+
gor: `${process.env.RPC_ORIGIN}/api/gor`,
|
|
10
|
+
};
|
|
@@ -66,7 +66,9 @@ declare const _default: {
|
|
|
66
66
|
"76": string[];
|
|
67
67
|
"77": string[];
|
|
68
68
|
"78": string[];
|
|
69
|
+
"79": string[];
|
|
69
70
|
"80": string[];
|
|
71
|
+
"81": string[];
|
|
70
72
|
"82": string[];
|
|
71
73
|
"83": string[];
|
|
72
74
|
"85": string[];
|
|
@@ -123,6 +125,7 @@ declare const _default: {
|
|
|
123
125
|
"262": string[];
|
|
124
126
|
"269": string[];
|
|
125
127
|
"288": string[];
|
|
128
|
+
"300": string[];
|
|
126
129
|
"321": string[];
|
|
127
130
|
"322": string[];
|
|
128
131
|
"333": string[];
|
|
@@ -146,6 +149,7 @@ declare const _default: {
|
|
|
146
149
|
"600": string[];
|
|
147
150
|
"666": string[];
|
|
148
151
|
"686": string[];
|
|
152
|
+
"700": string[];
|
|
149
153
|
"707": string[];
|
|
150
154
|
"708": string[];
|
|
151
155
|
"721": string[];
|
|
@@ -169,6 +173,7 @@ declare const _default: {
|
|
|
169
173
|
"999": string[];
|
|
170
174
|
"1001": string[];
|
|
171
175
|
"1007": string[];
|
|
176
|
+
"1008": string[];
|
|
172
177
|
"1010": string[];
|
|
173
178
|
"1012": string[];
|
|
174
179
|
"1022": string[];
|
|
@@ -197,6 +202,7 @@ declare const _default: {
|
|
|
197
202
|
"1688": string[];
|
|
198
203
|
"1856": string[];
|
|
199
204
|
"1898": string[];
|
|
205
|
+
"1984": string[];
|
|
200
206
|
"1987": string[];
|
|
201
207
|
"2001": string[];
|
|
202
208
|
"2020": string[];
|
|
@@ -205,6 +211,8 @@ declare const _default: {
|
|
|
205
211
|
"2025": string[];
|
|
206
212
|
"2100": string[];
|
|
207
213
|
"2101": string[];
|
|
214
|
+
"2152": string[];
|
|
215
|
+
"2153": string[];
|
|
208
216
|
"2213": string[];
|
|
209
217
|
"2221": string[];
|
|
210
218
|
"2559": string[];
|
|
@@ -259,6 +267,7 @@ declare const _default: {
|
|
|
259
267
|
"16000": string[];
|
|
260
268
|
"16001": string[];
|
|
261
269
|
"19845": string[];
|
|
270
|
+
"21337": string[];
|
|
262
271
|
"21816": string[];
|
|
263
272
|
"24484": string[];
|
|
264
273
|
"24734": string[];
|
|
@@ -288,6 +297,7 @@ declare const _default: {
|
|
|
288
297
|
"62320": string[];
|
|
289
298
|
"63000": string[];
|
|
290
299
|
"63001": string[];
|
|
300
|
+
"69420": string[];
|
|
291
301
|
"70000": string[];
|
|
292
302
|
"70001": string[];
|
|
293
303
|
"70002": string[];
|
|
@@ -204,9 +204,15 @@ export default {
|
|
|
204
204
|
"78": [
|
|
205
205
|
"primuschain"
|
|
206
206
|
],
|
|
207
|
+
"79": [
|
|
208
|
+
"zenith"
|
|
209
|
+
],
|
|
207
210
|
"80": [
|
|
208
211
|
"GeneChain"
|
|
209
212
|
],
|
|
213
|
+
"81": [
|
|
214
|
+
"VIL"
|
|
215
|
+
],
|
|
210
216
|
"82": [
|
|
211
217
|
"Meter"
|
|
212
218
|
],
|
|
@@ -375,6 +381,9 @@ export default {
|
|
|
375
381
|
"288": [
|
|
376
382
|
"Boba"
|
|
377
383
|
],
|
|
384
|
+
"300": [
|
|
385
|
+
"ogc"
|
|
386
|
+
],
|
|
378
387
|
"321": [
|
|
379
388
|
"kcs"
|
|
380
389
|
],
|
|
@@ -444,6 +453,9 @@ export default {
|
|
|
444
453
|
"686": [
|
|
445
454
|
"kar"
|
|
446
455
|
],
|
|
456
|
+
"700": [
|
|
457
|
+
"SNS"
|
|
458
|
+
],
|
|
447
459
|
"707": [
|
|
448
460
|
"bcs"
|
|
449
461
|
],
|
|
@@ -513,6 +525,9 @@ export default {
|
|
|
513
525
|
"1007": [
|
|
514
526
|
"tnew"
|
|
515
527
|
],
|
|
528
|
+
"1008": [
|
|
529
|
+
"eun"
|
|
530
|
+
],
|
|
516
531
|
"1010": [
|
|
517
532
|
"EVC"
|
|
518
533
|
],
|
|
@@ -577,7 +592,7 @@ export default {
|
|
|
577
592
|
"mrock"
|
|
578
593
|
],
|
|
579
594
|
"1337": [
|
|
580
|
-
"cennz-
|
|
595
|
+
"cennz-old"
|
|
581
596
|
],
|
|
582
597
|
"1618": [
|
|
583
598
|
"cate"
|
|
@@ -597,6 +612,9 @@ export default {
|
|
|
597
612
|
"1898": [
|
|
598
613
|
"boya"
|
|
599
614
|
],
|
|
615
|
+
"1984": [
|
|
616
|
+
"euntest"
|
|
617
|
+
],
|
|
600
618
|
"1987": [
|
|
601
619
|
"egem"
|
|
602
620
|
],
|
|
@@ -621,6 +639,12 @@ export default {
|
|
|
621
639
|
"2101": [
|
|
622
640
|
"esp"
|
|
623
641
|
],
|
|
642
|
+
"2152": [
|
|
643
|
+
"fra"
|
|
644
|
+
],
|
|
645
|
+
"2153": [
|
|
646
|
+
"findora-testnet"
|
|
647
|
+
],
|
|
624
648
|
"2213": [
|
|
625
649
|
"evanesco"
|
|
626
650
|
],
|
|
@@ -783,6 +807,9 @@ export default {
|
|
|
783
807
|
"19845": [
|
|
784
808
|
"btcix"
|
|
785
809
|
],
|
|
810
|
+
"21337": [
|
|
811
|
+
"cennz-a"
|
|
812
|
+
],
|
|
786
813
|
"21816": [
|
|
787
814
|
"oml"
|
|
788
815
|
],
|
|
@@ -870,6 +897,9 @@ export default {
|
|
|
870
897
|
"63001": [
|
|
871
898
|
"ecs-testnet"
|
|
872
899
|
],
|
|
900
|
+
"69420": [
|
|
901
|
+
"cndr"
|
|
902
|
+
],
|
|
873
903
|
"70000": [
|
|
874
904
|
"TKM0"
|
|
875
905
|
],
|
|
@@ -2,7 +2,13 @@ import Big from 'big.js';
|
|
|
2
2
|
import { scientificStrToDecimalStr } from './helpers';
|
|
3
3
|
export class TinyBig extends Big {
|
|
4
4
|
constructor(value) {
|
|
5
|
-
|
|
5
|
+
try {
|
|
6
|
+
super(value);
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
console.error(`TinyBig cannot parse value (value=${value})`);
|
|
10
|
+
throw e;
|
|
11
|
+
}
|
|
6
12
|
}
|
|
7
13
|
toHexString() {
|
|
8
14
|
return `0x${BigInt(this.toString()).toString(16)}`;
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
difficulty: number;
|
|
5
|
-
extraData: string;
|
|
1
|
+
import { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
|
|
2
|
+
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
3
|
+
export declare type BlockResponse = Modify<RPCBlock, {
|
|
6
4
|
gasLimit: number;
|
|
7
5
|
gasUsed: number;
|
|
8
|
-
hash: string;
|
|
9
|
-
logsBloom: string;
|
|
10
|
-
miner: string;
|
|
11
|
-
mixHash: string;
|
|
12
|
-
nonce: string;
|
|
13
6
|
number: number;
|
|
14
|
-
parentHash: string;
|
|
15
|
-
receiptsRoot: string;
|
|
16
|
-
sha3Uncles: string;
|
|
17
7
|
size: number;
|
|
18
|
-
stateRoot: string;
|
|
19
8
|
timestamp: number;
|
|
20
|
-
|
|
21
|
-
transactions: string
|
|
22
|
-
|
|
23
|
-
uncles: unknown[];
|
|
24
|
-
}
|
|
9
|
+
baseFeePerGas: number;
|
|
10
|
+
transactions: Array<string | BlockTransactionResponse>;
|
|
11
|
+
}>;
|
|
25
12
|
export interface RPCBlock {
|
|
26
13
|
baseFeePerGas: string;
|
|
27
14
|
difficulty: string;
|
|
@@ -45,3 +32,5 @@ export interface RPCBlock {
|
|
|
45
32
|
transactionsRoot: string;
|
|
46
33
|
uncles: unknown[];
|
|
47
34
|
}
|
|
35
|
+
export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
|
|
36
|
+
export {};
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
+
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
3
|
+
export interface RPCTransaction extends RPCBlockTransaction {
|
|
4
|
+
maxFeePerGas: string;
|
|
5
|
+
maxPriorityFeePerGas: string;
|
|
6
|
+
}
|
|
7
|
+
export declare type TransactionResponse = Modify<RPCTransaction, {
|
|
3
8
|
blockNumber: number;
|
|
4
|
-
|
|
5
|
-
gas: number;
|
|
6
|
-
gasPrice: string;
|
|
7
|
-
hash: string;
|
|
8
|
-
input: string;
|
|
9
|
+
chainId: number;
|
|
9
10
|
nonce: number;
|
|
10
|
-
r: string;
|
|
11
|
-
s: string;
|
|
12
|
-
to: string;
|
|
13
11
|
transactionIndex: number;
|
|
14
12
|
type: number;
|
|
15
|
-
v:
|
|
16
|
-
value:
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
v: number;
|
|
14
|
+
value: TinyBig;
|
|
15
|
+
gasPrice: TinyBig;
|
|
16
|
+
gas: TinyBig;
|
|
17
|
+
gasLimit: TinyBig;
|
|
18
|
+
} & {
|
|
19
|
+
maxFeePerGas: TinyBig;
|
|
20
|
+
maxPriorityFeePerGas: TinyBig;
|
|
21
|
+
confirmations: number;
|
|
22
|
+
}>;
|
|
23
|
+
export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
|
|
24
|
+
export interface RPCBlockTransaction {
|
|
19
25
|
blockHash: string;
|
|
20
26
|
blockNumber: string;
|
|
27
|
+
chainId: string;
|
|
21
28
|
from: string;
|
|
22
29
|
gas: string;
|
|
23
30
|
gasPrice: string;
|
|
@@ -32,3 +39,4 @@ export interface RPCTransaction {
|
|
|
32
39
|
v: string;
|
|
33
40
|
value: string;
|
|
34
41
|
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
+
import { validateType } from '../shared/validate-type';
|
|
3
|
+
export function etherToGwei(etherQuantity) {
|
|
4
|
+
validateType(etherQuantity, ['string', 'number', 'object']);
|
|
5
|
+
const result = tinyBig(etherQuantity).times('1000000000');
|
|
6
|
+
return tinyBig(result);
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
2
|
+
import { validateType } from '../shared/validate-type';
|
|
3
|
+
export function gweiToEther(gweiQuantity) {
|
|
4
|
+
validateType(gweiQuantity, ['string', 'number', 'object']);
|
|
5
|
+
const result = tinyBig(gweiQuantity).div('1000000000');
|
|
6
|
+
return tinyBig(result);
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hexZeroPad(hexValue: string | number, length: number): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validateType } from '../shared/validate-type';
|
|
2
|
+
export function hexZeroPad(hexValue, length) {
|
|
3
|
+
validateType(hexValue, ['string', 'number']);
|
|
4
|
+
let val;
|
|
5
|
+
if (typeof hexValue === 'string') {
|
|
6
|
+
if (!hexValue.startsWith('0x'))
|
|
7
|
+
throw new Error(`value is not a hex string or number. Consider prepending with "0x" (value="${hexValue}")`);
|
|
8
|
+
val = hexValue.substring(2);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
val = hexValue.toString(16);
|
|
12
|
+
}
|
|
13
|
+
if (val.length > length * 2) {
|
|
14
|
+
throw new Error(`value is longer than length (hexValue=${hexValue}, length=${length})`);
|
|
15
|
+
}
|
|
16
|
+
return `0x${val.padStart(length * 2, '0')}`;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "essential-eth",
|
|
3
3
|
"description": "Ultralight JS library for Ethereum utilities",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"@types/jest-dev-server": "^5.0.0",
|
|
37
37
|
"@types/node": "^16.10.1",
|
|
38
38
|
"@types/prettier": "^2.4.4",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
40
|
-
"@typescript-eslint/parser": "^5.
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.19.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.19.0",
|
|
41
41
|
"body-parser": "^1.19.0",
|
|
42
42
|
"dotenv": "^16.0.0",
|
|
43
|
-
"eslint": "^8.
|
|
44
|
-
"eslint-plugin-jest": "^26.1.
|
|
45
|
-
"ethers": "^5.6.
|
|
43
|
+
"eslint": "^8.13.0",
|
|
44
|
+
"eslint-plugin-jest": "^26.1.4",
|
|
45
|
+
"ethers": "^5.6.3",
|
|
46
46
|
"express": "^4.17.1",
|
|
47
47
|
"husky": "^4.3.0",
|
|
48
48
|
"jest": "^27.5.1",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"ts-node": "^10.2.1",
|
|
57
57
|
"typedoc": "^0.22.13",
|
|
58
58
|
"typescript": "^4.6.3",
|
|
59
|
-
"web3": "^1.7.
|
|
59
|
+
"web3": "^1.7.3"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@types/big.js": "^6.1.3",
|