essential-eth 0.4.9-beta.3 → 0.4.10
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 → lib}/cjs/classes/Contract.d.ts +0 -0
- package/{dist → lib}/cjs/classes/Contract.js +3 -8
- package/{dist → lib}/cjs/classes/test/Contract/crv-abi.d.ts +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/crv-abi.js +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/ens-abi.d.ts +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/ens-abi.js +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/fei-abi.d.ts +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/fei-abi.js +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/foo-abi.d.ts +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/foo-abi.js +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -0
- package/{dist → lib}/cjs/classes/test/Contract/uniswap-abi.js +0 -0
- package/{dist → lib}/cjs/classes/utils/clean-block.d.ts +0 -0
- package/{dist → lib}/cjs/classes/utils/clean-block.js +2 -2
- package/{dist → lib}/cjs/classes/utils/clean-transaction.d.ts +0 -0
- package/{dist → lib}/cjs/classes/utils/clean-transaction.js +2 -2
- package/{dist → lib}/cjs/classes/utils/encode-decode-transaction.d.ts +0 -0
- package/{dist → lib}/cjs/classes/utils/encode-decode-transaction.js +1 -2
- package/{dist → lib}/cjs/classes/utils/fetchers.d.ts +1 -1
- package/lib/cjs/classes/utils/fetchers.js +51 -0
- package/{dist → lib}/cjs/classes/utils/hex-to-decimal.d.ts +0 -0
- package/{dist → lib}/cjs/classes/utils/hex-to-decimal.js +0 -0
- package/lib/cjs/index.d.ts +14 -0
- package/lib/cjs/index.js +23 -0
- package/{dist → lib}/cjs/providers/JsonRpcProvider.d.ts +16 -3
- package/{dist → lib}/cjs/providers/JsonRpcProvider.js +26 -23
- package/lib/cjs/providers/test/rpc-urls.d.ts +8 -0
- package/lib/cjs/providers/test/rpc-urls.js +11 -0
- package/{dist → lib}/cjs/providers/utils/chains-info.d.ts +22 -1
- package/{dist → lib}/cjs/providers/utils/chains-info.js +66 -3
- package/{dist → lib}/cjs/shared/tiny-big/helpers.d.ts +0 -0
- package/{dist → lib}/cjs/shared/tiny-big/helpers.js +0 -0
- package/{dist → lib}/cjs/shared/tiny-big/tiny-big.d.ts +6 -0
- package/{dist → lib}/cjs/shared/tiny-big/tiny-big.js +6 -0
- package/{dist → lib}/cjs/shared/validate-type.d.ts +0 -0
- package/{dist → lib}/cjs/shared/validate-type.js +0 -0
- package/{dist → lib}/cjs/types/Block.types.d.ts +0 -0
- package/{dist → lib}/cjs/types/Block.types.js +0 -0
- package/{dist → lib}/cjs/types/Contract.types.d.ts +0 -0
- package/{dist → lib}/cjs/types/Contract.types.js +0 -0
- package/{dist → lib}/cjs/types/Network.types.d.ts +0 -0
- package/{dist → lib}/cjs/types/Network.types.js +0 -0
- package/{dist → lib}/cjs/types/Transaction.types.d.ts +0 -0
- package/{dist → lib}/cjs/types/Transaction.types.js +0 -0
- package/lib/cjs/utils/ether-to-gwei.d.ts +26 -0
- package/lib/cjs/utils/ether-to-gwei.js +34 -0
- package/{dist → lib}/cjs/utils/ether-to-wei.d.ts +4 -2
- package/{dist → 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/is-address.d.ts +24 -0
- package/{dist → lib}/cjs/utils/is-address.js +21 -2
- package/{dist → lib}/cjs/utils/to-checksum-address.d.ts +2 -2
- package/{dist → lib}/cjs/utils/to-checksum-address.js +2 -2
- package/lib/cjs/utils/wei-to-ether.d.ts +26 -0
- package/{dist → lib}/cjs/utils/wei-to-ether.js +11 -11
- package/{dist → lib}/esm/classes/Contract.d.ts +0 -0
- package/{dist → lib}/esm/classes/Contract.js +3 -8
- package/{dist → lib}/esm/classes/test/Contract/crv-abi.d.ts +0 -0
- package/{dist → lib}/esm/classes/test/Contract/crv-abi.js +0 -0
- package/{dist → lib}/esm/classes/test/Contract/ens-abi.d.ts +0 -0
- package/{dist → lib}/esm/classes/test/Contract/ens-abi.js +0 -0
- package/{dist → lib}/esm/classes/test/Contract/fei-abi.d.ts +0 -0
- package/{dist → lib}/esm/classes/test/Contract/fei-abi.js +0 -0
- package/{dist → lib}/esm/classes/test/Contract/foo-abi.d.ts +0 -0
- package/{dist → lib}/esm/classes/test/Contract/foo-abi.js +0 -0
- package/{dist → lib}/esm/classes/test/Contract/uniswap-abi.d.ts +0 -0
- package/{dist → lib}/esm/classes/test/Contract/uniswap-abi.js +0 -0
- package/{dist → lib}/esm/classes/utils/clean-block.d.ts +0 -0
- package/{dist → lib}/esm/classes/utils/clean-block.js +1 -1
- package/{dist → lib}/esm/classes/utils/clean-transaction.d.ts +0 -0
- package/{dist → lib}/esm/classes/utils/clean-transaction.js +1 -1
- package/{dist → lib}/esm/classes/utils/encode-decode-transaction.d.ts +0 -0
- package/{dist → lib}/esm/classes/utils/encode-decode-transaction.js +1 -2
- package/{dist → lib}/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/classes/utils/fetchers.js +43 -0
- package/{dist → lib}/esm/classes/utils/hex-to-decimal.d.ts +0 -0
- package/{dist → lib}/esm/classes/utils/hex-to-decimal.js +0 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +10 -0
- package/{dist → lib}/esm/providers/JsonRpcProvider.d.ts +4 -3
- package/{dist → lib}/esm/providers/JsonRpcProvider.js +14 -23
- package/lib/esm/providers/test/rpc-urls.d.ts +8 -0
- package/lib/esm/providers/test/rpc-urls.js +8 -0
- package/{dist → lib}/esm/providers/utils/chains-info.d.ts +22 -1
- package/{dist → lib}/esm/providers/utils/chains-info.js +66 -3
- package/{dist → lib}/esm/shared/tiny-big/helpers.d.ts +0 -0
- package/{dist → lib}/esm/shared/tiny-big/helpers.js +0 -0
- package/{dist → lib}/esm/shared/tiny-big/tiny-big.d.ts +0 -0
- package/{dist → lib}/esm/shared/tiny-big/tiny-big.js +0 -0
- package/{dist → lib}/esm/shared/validate-type.d.ts +0 -0
- package/{dist → lib}/esm/shared/validate-type.js +0 -0
- package/{dist → lib}/esm/types/Block.types.d.ts +0 -0
- package/{dist → lib}/esm/types/Block.types.js +0 -0
- package/{dist → lib}/esm/types/Contract.types.d.ts +0 -0
- package/{dist → lib}/esm/types/Contract.types.js +0 -0
- package/{dist → lib}/esm/types/Network.types.d.ts +0 -0
- package/{dist → lib}/esm/types/Network.types.js +0 -0
- package/{dist → lib}/esm/types/Transaction.types.d.ts +0 -0
- package/{dist → lib}/esm/types/Transaction.types.js +0 -0
- package/lib/esm/utils/ether-to-gwei.d.ts +3 -0
- package/lib/esm/utils/ether-to-gwei.js +7 -0
- package/{dist → lib}/esm/utils/ether-to-wei.d.ts +0 -0
- package/{dist → lib}/esm/utils/ether-to-wei.js +0 -0
- package/lib/esm/utils/gwei-to-ether.d.ts +3 -0
- package/lib/esm/utils/gwei-to-ether.js +7 -0
- package/{dist → lib}/esm/utils/is-address.d.ts +0 -0
- package/{dist → lib}/esm/utils/is-address.js +1 -1
- package/{dist → lib}/esm/utils/to-checksum-address.d.ts +0 -0
- package/{dist → lib}/esm/utils/to-checksum-address.js +0 -0
- package/{dist → lib}/esm/utils/wei-to-ether.d.ts +1 -1
- package/{dist → lib}/esm/utils/wei-to-ether.js +0 -0
- package/package.json +13 -17
- package/readme.md +85 -9
- package/dist/cjs/classes/utils/fetchers.js +0 -33
- package/dist/cjs/index.d.ts +0 -9
- package/dist/cjs/index.js +0 -36
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +0 -1
- package/dist/cjs/utils/index.d.ts +0 -5
- package/dist/cjs/utils/index.js +0 -11
- package/dist/cjs/utils/is-address.d.ts +0 -5
- package/dist/cjs/utils/wei-to-ether.d.ts +0 -26
- package/dist/esm/classes/utils/fetchers.js +0 -25
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.js +0 -5
- package/dist/esm/tsconfig.tsbuildinfo +0 -1
- package/dist/esm/utils/index.d.ts +0 -5
- package/dist/esm/utils/index.js +0 -5
|
File without changes
|
|
@@ -51,17 +51,12 @@ class BaseContract {
|
|
|
51
51
|
? estimateGas(data)
|
|
52
52
|
: null;
|
|
53
53
|
const req = () => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
return yield (0, fetchers_1.post)(this._provider._rpcUrl
|
|
55
|
-
Object.assign({ to: this._address.toLowerCase(), data
|
|
54
|
+
return yield (0, fetchers_1.post)(this._provider._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_call', [
|
|
55
|
+
Object.assign({ to: this._address.toLowerCase(), data }, (decimalGas
|
|
56
56
|
? { gas: `0x${decimalGas.toString(16)}` }
|
|
57
57
|
: {})),
|
|
58
58
|
'latest',
|
|
59
|
-
]))
|
|
60
|
-
if (e.code === 'ENOTFOUND') {
|
|
61
|
-
this._provider._rpcUrlCounter++;
|
|
62
|
-
return req();
|
|
63
|
-
}
|
|
64
|
-
});
|
|
59
|
+
]));
|
|
65
60
|
});
|
|
66
61
|
const nodeResponse = yield req();
|
|
67
62
|
return (0, encode_decode_transaction_1.decodeRPCResponse)(jsonABIArgument, nodeResponse);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cleanBlock = void 0;
|
|
4
|
-
const
|
|
4
|
+
const __1 = require("../..");
|
|
5
5
|
const clean_transaction_1 = require("./clean-transaction");
|
|
6
6
|
const hex_to_decimal_1 = require("./hex-to-decimal");
|
|
7
7
|
/**
|
|
@@ -29,7 +29,7 @@ function cleanBlock(block, returnTransactionObjects) {
|
|
|
29
29
|
break;
|
|
30
30
|
case 'miner':
|
|
31
31
|
if (block[key]) {
|
|
32
|
-
cleanedBlock[key] = (0,
|
|
32
|
+
cleanedBlock[key] = (0, __1.toChecksumAddress)(block[key]);
|
|
33
33
|
}
|
|
34
34
|
break;
|
|
35
35
|
}
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cleanTransaction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const __1 = require("../..");
|
|
5
5
|
const hex_to_decimal_1 = require("./hex-to-decimal");
|
|
6
6
|
/**
|
|
7
7
|
* Converts hex to decimal and checksum-addresses all addresses
|
|
@@ -28,7 +28,7 @@ function cleanTransaction(transaction) {
|
|
|
28
28
|
case 'from':
|
|
29
29
|
case 'to':
|
|
30
30
|
if (transaction[key]) {
|
|
31
|
-
cleanedTransaction[key] = (0,
|
|
31
|
+
cleanedTransaction[key] = (0, __1.toChecksumAddress)(transaction[key]);
|
|
32
32
|
}
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
File without changes
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.decodeRPCResponse = exports.encodeData = void 0;
|
|
4
4
|
const sha3_1 = require("sha3");
|
|
5
5
|
const __1 = require("../..");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
6
|
const hex_to_decimal_1 = require("./hex-to-decimal");
|
|
8
7
|
const hexTrue = '0000000000000000000000000000000000000000000000000000000000000001';
|
|
9
8
|
const hexFalse = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
@@ -98,7 +97,7 @@ function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
|
98
97
|
return output === hexTrue;
|
|
99
98
|
case 'address':
|
|
100
99
|
/* address types have 26 leading zeroes to remove */
|
|
101
|
-
return (0,
|
|
100
|
+
return (0, __1.toChecksumAddress)(`0x${output.slice(24)}`);
|
|
102
101
|
case 'uint256':
|
|
103
102
|
return (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
|
|
104
103
|
case 'bytes32':
|
|
@@ -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;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.buildRPCPostBody = exports.post = void 0;
|
|
16
|
+
const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
|
|
17
|
+
function post(url, body) {
|
|
18
|
+
return (0, isomorphic_unfetch_1.default)(url, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify(body),
|
|
24
|
+
})
|
|
25
|
+
.then((r) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const t = yield r.text();
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(t);
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
throw new Error(`Invalid JSON RPC response: "${t}"`);
|
|
32
|
+
}
|
|
33
|
+
}))
|
|
34
|
+
.then((response) => {
|
|
35
|
+
const result = response === null || response === void 0 ? void 0 : response.result;
|
|
36
|
+
if (!result) {
|
|
37
|
+
throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
|
|
38
|
+
}
|
|
39
|
+
return response.result;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.post = post;
|
|
43
|
+
function buildRPCPostBody(method, params) {
|
|
44
|
+
return {
|
|
45
|
+
jsonrpc: '2.0',
|
|
46
|
+
id: 1,
|
|
47
|
+
method,
|
|
48
|
+
params,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.buildRPCPostBody = buildRPCPostBody;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Contract } from './classes/Contract';
|
|
2
|
+
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
3
|
+
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
4
|
+
import { Block } from './types/Block.types';
|
|
5
|
+
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
6
|
+
import { Network } from './types/Network.types';
|
|
7
|
+
import { Transaction } from './types/Transaction.types';
|
|
8
|
+
import { etherToGwei } from './utils/ether-to-gwei';
|
|
9
|
+
import { etherToWei } from './utils/ether-to-wei';
|
|
10
|
+
import { gweiToEther } from './utils/gwei-to-ether';
|
|
11
|
+
import { isAddress } from './utils/is-address';
|
|
12
|
+
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
13
|
+
import { weiToEther } from './utils/wei-to-ether';
|
|
14
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, Block, ContractTypes, JSONABI, JSONABIArgument, Network, Transaction, };
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TinyBig = exports.Contract = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
|
|
4
|
+
const Contract_1 = require("./classes/Contract");
|
|
5
|
+
Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
|
|
6
|
+
const JsonRpcProvider_1 = require("./providers/JsonRpcProvider");
|
|
7
|
+
Object.defineProperty(exports, "JsonRpcProvider", { enumerable: true, get: function () { return JsonRpcProvider_1.JsonRpcProvider; } });
|
|
8
|
+
Object.defineProperty(exports, "jsonRpcProvider", { enumerable: true, get: function () { return JsonRpcProvider_1.jsonRpcProvider; } });
|
|
9
|
+
const tiny_big_1 = require("./shared/tiny-big/tiny-big");
|
|
10
|
+
Object.defineProperty(exports, "tinyBig", { enumerable: true, get: function () { return tiny_big_1.tinyBig; } });
|
|
11
|
+
Object.defineProperty(exports, "TinyBig", { enumerable: true, get: function () { return tiny_big_1.TinyBig; } });
|
|
12
|
+
const ether_to_gwei_1 = require("./utils/ether-to-gwei");
|
|
13
|
+
Object.defineProperty(exports, "etherToGwei", { enumerable: true, get: function () { return ether_to_gwei_1.etherToGwei; } });
|
|
14
|
+
const ether_to_wei_1 = require("./utils/ether-to-wei");
|
|
15
|
+
Object.defineProperty(exports, "etherToWei", { enumerable: true, get: function () { return ether_to_wei_1.etherToWei; } });
|
|
16
|
+
const gwei_to_ether_1 = require("./utils/gwei-to-ether");
|
|
17
|
+
Object.defineProperty(exports, "gweiToEther", { enumerable: true, get: function () { return gwei_to_ether_1.gweiToEther; } });
|
|
18
|
+
const is_address_1 = require("./utils/is-address");
|
|
19
|
+
Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
|
|
20
|
+
const to_checksum_address_1 = require("./utils/to-checksum-address");
|
|
21
|
+
Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return to_checksum_address_1.toChecksumAddress; } });
|
|
22
|
+
const wei_to_ether_1 = require("./utils/wei-to-ether");
|
|
23
|
+
Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });
|
|
@@ -1,12 +1,12 @@
|
|
|
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
5
|
/**
|
|
5
6
|
* The URL to your Eth node. Consider POKT or Infura
|
|
6
7
|
*/
|
|
7
|
-
readonly _rpcUrl:
|
|
8
|
-
|
|
9
|
-
constructor(rpcUrl?: string | Array<string>);
|
|
8
|
+
readonly _rpcUrl: string;
|
|
9
|
+
constructor(rpcUrl?: string);
|
|
10
10
|
/**
|
|
11
11
|
* Returns the block requested
|
|
12
12
|
* Same as `web3.eth.getBlock`
|
|
@@ -16,8 +16,21 @@ export declare class JsonRpcProvider {
|
|
|
16
16
|
* Returns the network this provider is connected to
|
|
17
17
|
*/
|
|
18
18
|
getNetwork(): Promise<Network>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current gas price in wei as TinyBig
|
|
21
|
+
* Same as `ethers.provider.getGasPrice`
|
|
22
|
+
*/
|
|
23
|
+
getGasPrice(): Promise<TinyBig>;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Helper function to avoid "new"
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```javascript
|
|
30
|
+
* jsonRpcProvider().getBlock('latest').then(block => {
|
|
31
|
+
* console.log(block.number);
|
|
32
|
+
* })
|
|
33
|
+
* // 14530496
|
|
34
|
+
* ```
|
|
22
35
|
*/
|
|
23
36
|
export declare function jsonRpcProvider(rpcUrl?: string): JsonRpcProvider;
|
|
@@ -16,19 +16,11 @@ exports.jsonRpcProvider = exports.JsonRpcProvider = void 0;
|
|
|
16
16
|
const clean_block_1 = require("../classes/utils/clean-block");
|
|
17
17
|
const fetchers_1 = require("../classes/utils/fetchers");
|
|
18
18
|
const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
|
|
19
|
+
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
19
20
|
const chains_info_1 = __importDefault(require("./utils/chains-info"));
|
|
20
21
|
class JsonRpcProvider {
|
|
21
22
|
constructor(rpcUrl) {
|
|
22
|
-
this._rpcUrl =
|
|
23
|
-
if (!rpcUrl) {
|
|
24
|
-
return ['https://free-eth-node.com/api/eth'];
|
|
25
|
-
}
|
|
26
|
-
else if (!Array.isArray(rpcUrl)) {
|
|
27
|
-
return [rpcUrl];
|
|
28
|
-
}
|
|
29
|
-
return rpcUrl;
|
|
30
|
-
})();
|
|
31
|
-
this._rpcUrlCounter = 0;
|
|
23
|
+
this._rpcUrl = rpcUrl || 'https://free-eth-node.com/api/eth';
|
|
32
24
|
}
|
|
33
25
|
/**
|
|
34
26
|
* Returns the block requested
|
|
@@ -46,15 +38,10 @@ class JsonRpcProvider {
|
|
|
46
38
|
rpcTimeFrame = timeFrame;
|
|
47
39
|
}
|
|
48
40
|
const req = () => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
return yield (0, fetchers_1.post)(this._rpcUrl
|
|
41
|
+
return yield (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_getBlockByNumber', [
|
|
50
42
|
rpcTimeFrame,
|
|
51
43
|
returnTransactionObjects,
|
|
52
|
-
]))
|
|
53
|
-
if (e.code === 'ENOTFOUND') {
|
|
54
|
-
this._rpcUrlCounter++;
|
|
55
|
-
return req();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
44
|
+
]));
|
|
58
45
|
});
|
|
59
46
|
const nodeResponse = (yield req());
|
|
60
47
|
return (0, clean_block_1.cleanBlock)(nodeResponse, returnTransactionObjects);
|
|
@@ -66,12 +53,7 @@ class JsonRpcProvider {
|
|
|
66
53
|
getNetwork() {
|
|
67
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
55
|
const req = () => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return yield (0, fetchers_1.post)(this._rpcUrl
|
|
70
|
-
if (e.code === 'ENOTFOUND') {
|
|
71
|
-
this._rpcUrlCounter++;
|
|
72
|
-
return req();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
56
|
+
return yield (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_chainId', []));
|
|
75
57
|
});
|
|
76
58
|
const nodeResponse = (yield req());
|
|
77
59
|
const chainId = (0, hex_to_decimal_1.hexToDecimal)(nodeResponse);
|
|
@@ -83,10 +65,31 @@ class JsonRpcProvider {
|
|
|
83
65
|
};
|
|
84
66
|
});
|
|
85
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Returns the current gas price in wei as TinyBig
|
|
70
|
+
* Same as `ethers.provider.getGasPrice`
|
|
71
|
+
*/
|
|
72
|
+
getGasPrice() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const req = () => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return yield (0, fetchers_1.post)(this._rpcUrl, (0, fetchers_1.buildRPCPostBody)('eth_gasPrice', []));
|
|
76
|
+
});
|
|
77
|
+
const nodeResponse = (yield req()); /* '0x153cfb1ad0' */
|
|
78
|
+
return (0, tiny_big_1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(nodeResponse));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
86
81
|
}
|
|
87
82
|
exports.JsonRpcProvider = JsonRpcProvider;
|
|
88
83
|
/**
|
|
89
84
|
* Helper function to avoid "new"
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```javascript
|
|
88
|
+
* jsonRpcProvider().getBlock('latest').then(block => {
|
|
89
|
+
* console.log(block.number);
|
|
90
|
+
* })
|
|
91
|
+
* // 14530496
|
|
92
|
+
* ```
|
|
90
93
|
*/
|
|
91
94
|
function jsonRpcProvider(rpcUrl) {
|
|
92
95
|
return new JsonRpcProvider(rpcUrl);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rpcUrls = exports.fakeUrls = void 0;
|
|
4
|
+
exports.fakeUrls = {
|
|
5
|
+
notRPCButRealHttp: 'https://httpstat.us/200',
|
|
6
|
+
};
|
|
7
|
+
exports.rpcUrls = {
|
|
8
|
+
mainnet: `${process.env.RPC_ORIGIN}/api/eth`,
|
|
9
|
+
gno: `${process.env.RPC_ORIGIN}/api/gno`,
|
|
10
|
+
bnb: `${process.env.RPC_ORIGIN}/api/bnb`,
|
|
11
|
+
};
|
|
@@ -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[];
|
|
@@ -98,9 +99,11 @@ declare const _default: {
|
|
|
98
99
|
"127": string[];
|
|
99
100
|
"128": string[];
|
|
100
101
|
"137": string[];
|
|
102
|
+
"141": string[];
|
|
101
103
|
"142": string[];
|
|
102
104
|
"162": string[];
|
|
103
105
|
"163": string[];
|
|
106
|
+
"168": string[];
|
|
104
107
|
"170": string[];
|
|
105
108
|
"172": string[];
|
|
106
109
|
"186": string[];
|
|
@@ -109,7 +112,10 @@ declare const _default: {
|
|
|
109
112
|
"199": string[];
|
|
110
113
|
"200": string[];
|
|
111
114
|
"211": string[];
|
|
115
|
+
"218": string[];
|
|
112
116
|
"222": string[];
|
|
117
|
+
"225": string[];
|
|
118
|
+
"226": string[];
|
|
113
119
|
"246": string[];
|
|
114
120
|
"250": string[];
|
|
115
121
|
"256": string[];
|
|
@@ -117,6 +123,7 @@ declare const _default: {
|
|
|
117
123
|
"262": string[];
|
|
118
124
|
"269": string[];
|
|
119
125
|
"288": string[];
|
|
126
|
+
"300": string[];
|
|
120
127
|
"321": string[];
|
|
121
128
|
"322": string[];
|
|
122
129
|
"333": string[];
|
|
@@ -145,6 +152,7 @@ declare const _default: {
|
|
|
145
152
|
"721": string[];
|
|
146
153
|
"777": string[];
|
|
147
154
|
"787": string[];
|
|
155
|
+
"788": string[];
|
|
148
156
|
"803": string[];
|
|
149
157
|
"820": string[];
|
|
150
158
|
"821": string[];
|
|
@@ -162,6 +170,7 @@ declare const _default: {
|
|
|
162
170
|
"999": string[];
|
|
163
171
|
"1001": string[];
|
|
164
172
|
"1007": string[];
|
|
173
|
+
"1008": string[];
|
|
165
174
|
"1010": string[];
|
|
166
175
|
"1012": string[];
|
|
167
176
|
"1022": string[];
|
|
@@ -180,14 +189,19 @@ declare const _default: {
|
|
|
180
189
|
"1280": string[];
|
|
181
190
|
"1284": string[];
|
|
182
191
|
"1285": string[];
|
|
192
|
+
"1286": string[];
|
|
183
193
|
"1287": string[];
|
|
184
194
|
"1288": string[];
|
|
195
|
+
"1337": string[];
|
|
185
196
|
"1618": string[];
|
|
186
197
|
"1620": string[];
|
|
187
198
|
"1657": string[];
|
|
199
|
+
"1688": string[];
|
|
188
200
|
"1856": string[];
|
|
189
201
|
"1898": string[];
|
|
202
|
+
"1984": string[];
|
|
190
203
|
"1987": string[];
|
|
204
|
+
"2001": string[];
|
|
191
205
|
"2020": string[];
|
|
192
206
|
"2021": string[];
|
|
193
207
|
"2022": string[];
|
|
@@ -195,7 +209,10 @@ declare const _default: {
|
|
|
195
209
|
"2100": string[];
|
|
196
210
|
"2101": string[];
|
|
197
211
|
"2213": string[];
|
|
212
|
+
"2221": string[];
|
|
198
213
|
"2559": string[];
|
|
214
|
+
"3000": string[];
|
|
215
|
+
"3001": string[];
|
|
199
216
|
"3331": string[];
|
|
200
217
|
"3333": string[];
|
|
201
218
|
"3334": string[];
|
|
@@ -205,12 +222,14 @@ declare const _default: {
|
|
|
205
222
|
"3966": string[];
|
|
206
223
|
"3967": string[];
|
|
207
224
|
"4002": string[];
|
|
225
|
+
"4102": string[];
|
|
208
226
|
"4689": string[];
|
|
209
227
|
"4690": string[];
|
|
210
228
|
"4918": string[];
|
|
211
229
|
"5197": string[];
|
|
212
230
|
"5315": string[];
|
|
213
231
|
"5700": string[];
|
|
232
|
+
"5777": string[];
|
|
214
233
|
"5851": string[];
|
|
215
234
|
"5869": string[];
|
|
216
235
|
"6626": string[];
|
|
@@ -259,6 +278,7 @@ declare const _default: {
|
|
|
259
278
|
"43113": string[];
|
|
260
279
|
"43114": string[];
|
|
261
280
|
"44787": string[];
|
|
281
|
+
"45000": string[];
|
|
262
282
|
"47805": string[];
|
|
263
283
|
"49797": string[];
|
|
264
284
|
"53935": string[];
|
|
@@ -300,10 +320,10 @@ declare const _default: {
|
|
|
300
320
|
"110006": string[];
|
|
301
321
|
"110007": string[];
|
|
302
322
|
"110008": string[];
|
|
323
|
+
"200101": string[];
|
|
303
324
|
"200625": string[];
|
|
304
325
|
"201018": string[];
|
|
305
326
|
"201030": string[];
|
|
306
|
-
"210309": string[];
|
|
307
327
|
"210425": string[];
|
|
308
328
|
"234666": string[];
|
|
309
329
|
"246529": string[];
|
|
@@ -319,6 +339,7 @@ declare const _default: {
|
|
|
319
339
|
"1313114": string[];
|
|
320
340
|
"1313500": string[];
|
|
321
341
|
"1337702": string[];
|
|
342
|
+
"2203181": string[];
|
|
322
343
|
"7762959": string[];
|
|
323
344
|
"11155111": string[];
|
|
324
345
|
"13371337": string[];
|