essential-eth 0.4.11 → 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 +1 -1
- package/lib/cjs/index.d.ts +4 -3
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/providers/JsonRpcProvider.d.ts +172 -2
- package/lib/cjs/providers/JsonRpcProvider.js +193 -23
- package/lib/cjs/providers/utils/chains-info.d.ts +6 -0
- package/lib/cjs/providers/utils/chains-info.js +18 -0
- package/lib/cjs/shared/tiny-big/tiny-big.js +7 -1
- package/lib/cjs/types/Block.types.d.ts +8 -19
- package/lib/cjs/types/Transaction.types.d.ts +23 -14
- package/lib/cjs/utils/hex-zero-pad.d.ts +32 -0
- package/lib/cjs/utils/hex-zero-pad.js +52 -0
- 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 +1 -1
- package/lib/esm/index.d.ts +4 -3
- package/lib/esm/index.js +2 -1
- package/lib/esm/providers/JsonRpcProvider.d.ts +5 -2
- package/lib/esm/providers/JsonRpcProvider.js +25 -23
- package/lib/esm/providers/utils/chains-info.d.ts +6 -0
- package/lib/esm/providers/utils/chains-info.js +18 -0
- package/lib/esm/shared/tiny-big/tiny-big.js +7 -1
- package/lib/esm/types/Block.types.d.ts +7 -19
- package/lib/esm/types/Transaction.types.d.ts +22 -14
- package/lib/esm/utils/hex-zero-pad.d.ts +1 -0
- package/lib/esm/utils/hex-zero-pad.js +17 -0
- package/package.json +7 -7
- package/readme.md +225 -62
|
@@ -208,9 +208,15 @@ exports.default = {
|
|
|
208
208
|
"78": [
|
|
209
209
|
"primuschain"
|
|
210
210
|
],
|
|
211
|
+
"79": [
|
|
212
|
+
"zenith"
|
|
213
|
+
],
|
|
211
214
|
"80": [
|
|
212
215
|
"GeneChain"
|
|
213
216
|
],
|
|
217
|
+
"81": [
|
|
218
|
+
"VIL"
|
|
219
|
+
],
|
|
214
220
|
"82": [
|
|
215
221
|
"Meter"
|
|
216
222
|
],
|
|
@@ -451,6 +457,9 @@ exports.default = {
|
|
|
451
457
|
"686": [
|
|
452
458
|
"kar"
|
|
453
459
|
],
|
|
460
|
+
"700": [
|
|
461
|
+
"SNS"
|
|
462
|
+
],
|
|
454
463
|
"707": [
|
|
455
464
|
"bcs"
|
|
456
465
|
],
|
|
@@ -634,6 +643,12 @@ exports.default = {
|
|
|
634
643
|
"2101": [
|
|
635
644
|
"esp"
|
|
636
645
|
],
|
|
646
|
+
"2152": [
|
|
647
|
+
"fra"
|
|
648
|
+
],
|
|
649
|
+
"2153": [
|
|
650
|
+
"findora-testnet"
|
|
651
|
+
],
|
|
637
652
|
"2213": [
|
|
638
653
|
"evanesco"
|
|
639
654
|
],
|
|
@@ -886,6 +901,9 @@ exports.default = {
|
|
|
886
901
|
"63001": [
|
|
887
902
|
"ecs-testnet"
|
|
888
903
|
],
|
|
904
|
+
"69420": [
|
|
905
|
+
"cndr"
|
|
906
|
+
],
|
|
889
907
|
"70000": [
|
|
890
908
|
"TKM0"
|
|
891
909
|
],
|
|
@@ -12,7 +12,13 @@ const helpers_1 = require("./helpers");
|
|
|
12
12
|
*/
|
|
13
13
|
class TinyBig extends big_js_1.default {
|
|
14
14
|
constructor(value) {
|
|
15
|
-
|
|
15
|
+
try {
|
|
16
|
+
super(value);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.error(`TinyBig cannot parse value (value=${value})`);
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
24
|
* Used anytime you're passing in "value" to ethers or web3
|
|
@@ -1,27 +1,15 @@
|
|
|
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
|
-
|
|
24
|
-
}
|
|
9
|
+
baseFeePerGas: number;
|
|
10
|
+
transactions: Array<string | BlockTransactionResponse>;
|
|
11
|
+
}>;
|
|
12
|
+
/** Exact response from backend */
|
|
25
13
|
export interface RPCBlock {
|
|
26
14
|
baseFeePerGas: string;
|
|
27
15
|
difficulty: string;
|
|
@@ -46,3 +34,4 @@ export interface RPCBlock {
|
|
|
46
34
|
uncles: unknown[];
|
|
47
35
|
}
|
|
48
36
|
export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
|
|
37
|
+
export {};
|
|
@@ -1,23 +1,31 @@
|
|
|
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
|
+
/** What JSONRPC responds with in getBlock transaction array */
|
|
25
|
+
export interface RPCBlockTransaction {
|
|
19
26
|
blockHash: string;
|
|
20
27
|
blockNumber: string;
|
|
28
|
+
chainId: string;
|
|
21
29
|
from: string;
|
|
22
30
|
gas: string;
|
|
23
31
|
gasPrice: string;
|
|
@@ -32,3 +40,4 @@ export interface RPCTransaction {
|
|
|
32
40
|
v: string;
|
|
33
41
|
value: string;
|
|
34
42
|
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a hex string padded to a specified length of bytes.
|
|
3
|
+
*
|
|
4
|
+
* Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
|
|
5
|
+
*
|
|
6
|
+
* Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
|
|
7
|
+
*
|
|
8
|
+
* @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
|
|
9
|
+
* @param length - The final length in bytes
|
|
10
|
+
*
|
|
11
|
+
* @throws - If the value is not a hex string or number
|
|
12
|
+
* @throws - If the value is longer than the length
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```javascript
|
|
16
|
+
* hexZeroPad('0x60', 2);
|
|
17
|
+
* // '0x0060'
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```javascript
|
|
22
|
+
* hexZeroPad(0x60, 3);
|
|
23
|
+
* // '0x000060'
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```javascript
|
|
28
|
+
* hexZeroPad('12345', 1);
|
|
29
|
+
* // Throws
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function hexZeroPad(hexValue: string | number, length: number): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hexZeroPad = void 0;
|
|
4
|
+
const validate_type_1 = require("../shared/validate-type");
|
|
5
|
+
/**
|
|
6
|
+
* Returns a hex string padded to a specified length of bytes.
|
|
7
|
+
*
|
|
8
|
+
* Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
|
|
9
|
+
*
|
|
10
|
+
* Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
|
|
11
|
+
*
|
|
12
|
+
* @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
|
|
13
|
+
* @param length - The final length in bytes
|
|
14
|
+
*
|
|
15
|
+
* @throws - If the value is not a hex string or number
|
|
16
|
+
* @throws - If the value is longer than the length
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```javascript
|
|
20
|
+
* hexZeroPad('0x60', 2);
|
|
21
|
+
* // '0x0060'
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```javascript
|
|
26
|
+
* hexZeroPad(0x60, 3);
|
|
27
|
+
* // '0x000060'
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```javascript
|
|
32
|
+
* hexZeroPad('12345', 1);
|
|
33
|
+
* // Throws
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function hexZeroPad(hexValue, length) {
|
|
37
|
+
(0, validate_type_1.validateType)(hexValue, ['string', 'number']);
|
|
38
|
+
let val;
|
|
39
|
+
if (typeof hexValue === 'string') {
|
|
40
|
+
if (!hexValue.startsWith('0x'))
|
|
41
|
+
throw new Error(`value is not a hex string or number. Consider prepending with "0x" (value="${hexValue}")`);
|
|
42
|
+
val = hexValue.substring(2);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
val = hexValue.toString(16);
|
|
46
|
+
}
|
|
47
|
+
if (val.length > length * 2) {
|
|
48
|
+
throw new Error(`value is longer than length (hexValue=${hexValue}, length=${length})`);
|
|
49
|
+
}
|
|
50
|
+
return `0x${val.padStart(length * 2, '0')}`;
|
|
51
|
+
}
|
|
52
|
+
exports.hexZeroPad = hexZeroPad;
|
|
@@ -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,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' | 'eth_gasPrice' | 'eth_getBalance';
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash';
|
|
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
|
@@ -1,14 +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
8
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
9
9
|
import { etherToWei } from './utils/ether-to-wei';
|
|
10
10
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
11
|
+
import { hexZeroPad } from './utils/hex-zero-pad';
|
|
11
12
|
import { isAddress } from './utils/is-address';
|
|
12
13
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
13
14
|
import { weiToEther } from './utils/wei-to-ether';
|
|
14
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, 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
|
@@ -4,7 +4,8 @@ import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
|
4
4
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
5
5
|
import { etherToWei } from './utils/ether-to-wei';
|
|
6
6
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
7
|
+
import { hexZeroPad } from './utils/hex-zero-pad';
|
|
7
8
|
import { isAddress } from './utils/is-address';
|
|
8
9
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
9
10
|
import { weiToEther } from './utils/wei-to-ether';
|
|
10
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, };
|
|
11
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hexZeroPad, Contract, TinyBig, };
|
|
@@ -1,12 +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: BlockTag, returnTransactionObjects?: boolean): Promise<
|
|
9
|
+
getBlock(timeFrame: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
8
10
|
getNetwork(): Promise<Network>;
|
|
9
11
|
getGasPrice(): Promise<TinyBig>;
|
|
10
12
|
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
13
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
11
14
|
}
|
|
12
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,20 +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
|
-
const nodeResponse = (yield req());
|
|
59
|
-
return tinyBig(hexToDecimal(nodeResponse));
|
|
51
|
+
const hexGasPrice = (yield this.post(buildRPCPostBody('eth_gasPrice', [])));
|
|
52
|
+
return tinyBig(hexToDecimal(hexGasPrice));
|
|
60
53
|
});
|
|
61
54
|
}
|
|
62
55
|
getBalance(address, blockTag = 'latest') {
|
|
63
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
}
|
|
@@ -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[];
|
|
@@ -147,6 +149,7 @@ declare const _default: {
|
|
|
147
149
|
"600": string[];
|
|
148
150
|
"666": string[];
|
|
149
151
|
"686": string[];
|
|
152
|
+
"700": string[];
|
|
150
153
|
"707": string[];
|
|
151
154
|
"708": string[];
|
|
152
155
|
"721": string[];
|
|
@@ -208,6 +211,8 @@ declare const _default: {
|
|
|
208
211
|
"2025": string[];
|
|
209
212
|
"2100": string[];
|
|
210
213
|
"2101": string[];
|
|
214
|
+
"2152": string[];
|
|
215
|
+
"2153": string[];
|
|
211
216
|
"2213": string[];
|
|
212
217
|
"2221": string[];
|
|
213
218
|
"2559": string[];
|
|
@@ -292,6 +297,7 @@ declare const _default: {
|
|
|
292
297
|
"62320": string[];
|
|
293
298
|
"63000": string[];
|
|
294
299
|
"63001": string[];
|
|
300
|
+
"69420": string[];
|
|
295
301
|
"70000": string[];
|
|
296
302
|
"70001": string[];
|
|
297
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
|
],
|
|
@@ -447,6 +453,9 @@ export default {
|
|
|
447
453
|
"686": [
|
|
448
454
|
"kar"
|
|
449
455
|
],
|
|
456
|
+
"700": [
|
|
457
|
+
"SNS"
|
|
458
|
+
],
|
|
450
459
|
"707": [
|
|
451
460
|
"bcs"
|
|
452
461
|
],
|
|
@@ -630,6 +639,12 @@ export default {
|
|
|
630
639
|
"2101": [
|
|
631
640
|
"esp"
|
|
632
641
|
],
|
|
642
|
+
"2152": [
|
|
643
|
+
"fra"
|
|
644
|
+
],
|
|
645
|
+
"2153": [
|
|
646
|
+
"findora-testnet"
|
|
647
|
+
],
|
|
633
648
|
"2213": [
|
|
634
649
|
"evanesco"
|
|
635
650
|
],
|
|
@@ -882,6 +897,9 @@ export default {
|
|
|
882
897
|
"63001": [
|
|
883
898
|
"ecs-testnet"
|
|
884
899
|
],
|
|
900
|
+
"69420": [
|
|
901
|
+
"cndr"
|
|
902
|
+
],
|
|
885
903
|
"70000": [
|
|
886
904
|
"TKM0"
|
|
887
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;
|
|
@@ -46,3 +33,4 @@ export interface RPCBlock {
|
|
|
46
33
|
uncles: unknown[];
|
|
47
34
|
}
|
|
48
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 @@
|
|
|
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
|
+
}
|