essential-eth 0.2.2 → 0.3.3

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.
Files changed (114) hide show
  1. package/lib/cjs/classes/Contract.d.ts +69 -0
  2. package/lib/cjs/classes/Contract.js +122 -0
  3. package/lib/cjs/{rpc → classes}/get-block.test.d.ts +0 -0
  4. package/lib/cjs/{rpc → classes}/get-block.test.js +5 -5
  5. package/lib/cjs/classes/test/Contract/crv-abi.d.ts +2 -0
  6. package/lib/cjs/classes/test/Contract/crv-abi.js +488 -0
  7. package/lib/{esm/rpc/get-block.test.d.ts → cjs/classes/test/Contract/crv.test.d.ts} +0 -0
  8. package/lib/cjs/classes/test/Contract/crv.test.js +48 -0
  9. package/lib/cjs/classes/test/Contract/fei-abi.d.ts +2 -0
  10. package/lib/cjs/classes/test/Contract/fei-abi.js +526 -0
  11. package/lib/cjs/classes/test/Contract/fei.test.d.ts +1 -0
  12. package/lib/cjs/classes/test/Contract/fei.test.js +62 -0
  13. package/lib/cjs/classes/test/Contract/foo-abi.d.ts +2 -0
  14. package/lib/cjs/classes/test/Contract/foo-abi.js +42 -0
  15. package/lib/cjs/classes/test/Contract/foo.test.d.ts +1 -0
  16. package/lib/cjs/classes/test/Contract/foo.test.js +25 -0
  17. package/lib/cjs/classes/test/Contract/uni.test.d.ts +1 -0
  18. package/lib/cjs/classes/test/Contract/uni.test.js +67 -0
  19. package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +2 -0
  20. package/lib/cjs/classes/test/Contract/uniswap-abi.js +121 -0
  21. package/lib/cjs/{rpc → classes}/utils/clean-block.d.ts +0 -0
  22. package/lib/cjs/{rpc → classes}/utils/clean-block.js +0 -0
  23. package/lib/cjs/{rpc → classes}/utils/clean-transaction.d.ts +0 -0
  24. package/lib/cjs/{rpc → classes}/utils/clean-transaction.js +0 -0
  25. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +3 -0
  26. package/lib/cjs/classes/utils/encode-decode-transaction.js +100 -0
  27. package/lib/cjs/classes/utils/fetchers.d.ts +9 -0
  28. package/lib/cjs/{rpc → classes}/utils/fetchers.js +8 -1
  29. package/lib/cjs/{rpc → classes}/utils/hex-to-decimal.d.ts +0 -0
  30. package/lib/cjs/{rpc → classes}/utils/hex-to-decimal.js +0 -0
  31. package/lib/cjs/index.d.ts +10 -6
  32. package/lib/cjs/index.js +12 -9
  33. package/lib/cjs/{rpc/index.d.ts → providers/JsonRpcProvider.d.ts} +5 -1
  34. package/lib/cjs/{rpc/index.js → providers/JsonRpcProvider.js} +14 -7
  35. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +2 -2
  36. package/lib/cjs/types/Contract.types.d.ts +22 -0
  37. package/lib/cjs/types/Contract.types.js +2 -0
  38. package/lib/cjs/{ether-to-wei.d.ts → utils/ether-to-wei.d.ts} +3 -2
  39. package/lib/cjs/{ether-to-wei.js → utils/ether-to-wei.js} +4 -8
  40. package/lib/cjs/{is-address.d.ts → utils/is-address.d.ts} +0 -0
  41. package/lib/cjs/{is-address.js → utils/is-address.js} +3 -3
  42. package/lib/cjs/utils/tests/ether-to-wei.test.d.ts +1 -0
  43. package/lib/cjs/utils/tests/ether-to-wei.test.js +66 -0
  44. package/lib/cjs/utils/tests/is-address.test.d.ts +1 -0
  45. package/lib/cjs/utils/tests/is-address.test.js +56 -0
  46. package/lib/cjs/utils/tests/to-checksum-address.test.d.ts +1 -0
  47. package/lib/cjs/utils/tests/to-checksum-address.test.js +43 -0
  48. package/lib/cjs/utils/tests/wei-to-ether.test.d.ts +1 -0
  49. package/lib/cjs/utils/tests/wei-to-ether.test.js +69 -0
  50. package/lib/cjs/{to-checksum-address.d.ts → utils/to-checksum-address.d.ts} +0 -0
  51. package/lib/cjs/{to-checksum-address.js → utils/to-checksum-address.js} +1 -1
  52. package/lib/cjs/{wei-to-ether.d.ts → utils/wei-to-ether.d.ts} +3 -1
  53. package/lib/cjs/{wei-to-ether.js → utils/wei-to-ether.js} +4 -8
  54. package/lib/esm/classes/Contract.d.ts +12 -0
  55. package/lib/esm/classes/Contract.js +63 -0
  56. package/lib/esm/classes/get-block.test.d.ts +1 -0
  57. package/lib/esm/{rpc → classes}/get-block.test.js +5 -5
  58. package/lib/esm/classes/test/Contract/crv-abi.d.ts +2 -0
  59. package/lib/esm/classes/test/Contract/crv-abi.js +470 -0
  60. package/lib/esm/classes/test/Contract/crv.test.d.ts +1 -0
  61. package/lib/esm/classes/test/Contract/crv.test.js +43 -0
  62. package/lib/esm/classes/test/Contract/fei-abi.d.ts +2 -0
  63. package/lib/esm/classes/test/Contract/fei-abi.js +521 -0
  64. package/lib/esm/classes/test/Contract/fei.test.d.ts +1 -0
  65. package/lib/esm/classes/test/Contract/fei.test.js +46 -0
  66. package/lib/esm/classes/test/Contract/foo-abi.d.ts +2 -0
  67. package/lib/esm/classes/test/Contract/foo-abi.js +33 -0
  68. package/lib/esm/classes/test/Contract/foo.test.d.ts +1 -0
  69. package/lib/esm/classes/test/Contract/foo.test.js +14 -0
  70. package/lib/esm/classes/test/Contract/uni.test.d.ts +1 -0
  71. package/lib/esm/classes/test/Contract/uni.test.js +59 -0
  72. package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
  73. package/lib/esm/classes/test/Contract/uniswap-abi.js +116 -0
  74. package/lib/esm/{rpc → classes}/utils/clean-block.d.ts +0 -0
  75. package/lib/esm/{rpc → classes}/utils/clean-block.js +0 -0
  76. package/lib/esm/{rpc → classes}/utils/clean-transaction.d.ts +0 -0
  77. package/lib/esm/{rpc → classes}/utils/clean-transaction.js +0 -0
  78. package/lib/esm/classes/utils/encode-decode-transaction.d.ts +3 -0
  79. package/lib/esm/classes/utils/encode-decode-transaction.js +85 -0
  80. package/lib/esm/classes/utils/fetchers.d.ts +9 -0
  81. package/lib/esm/{rpc → classes}/utils/fetchers.js +8 -1
  82. package/lib/esm/{rpc → classes}/utils/hex-to-decimal.d.ts +0 -0
  83. package/lib/esm/{rpc → classes}/utils/hex-to-decimal.js +0 -0
  84. package/lib/esm/index.d.ts +10 -6
  85. package/lib/esm/index.js +7 -6
  86. package/lib/esm/{rpc/index.d.ts → providers/JsonRpcProvider.d.ts} +2 -1
  87. package/lib/esm/{rpc/index.js → providers/JsonRpcProvider.js} +8 -5
  88. package/lib/esm/shared/tiny-big/tiny-big.d.ts +2 -2
  89. package/lib/esm/types/Contract.types.d.ts +22 -0
  90. package/lib/esm/types/Contract.types.js +1 -0
  91. package/lib/esm/utils/ether-to-wei.d.ts +3 -0
  92. package/lib/esm/utils/ether-to-wei.js +7 -0
  93. package/lib/esm/{is-address.d.ts → utils/is-address.d.ts} +0 -0
  94. package/lib/esm/{is-address.js → utils/is-address.js} +2 -2
  95. package/lib/esm/utils/tests/ether-to-wei.test.d.ts +1 -0
  96. package/lib/esm/utils/tests/ether-to-wei.test.js +36 -0
  97. package/lib/esm/utils/tests/is-address.test.d.ts +1 -0
  98. package/lib/esm/utils/tests/is-address.test.js +49 -0
  99. package/lib/esm/utils/tests/to-checksum-address.test.d.ts +1 -0
  100. package/lib/esm/utils/tests/to-checksum-address.test.js +36 -0
  101. package/lib/esm/utils/tests/wei-to-ether.test.d.ts +1 -0
  102. package/lib/esm/utils/tests/wei-to-ether.test.js +38 -0
  103. package/lib/esm/{to-checksum-address.d.ts → utils/to-checksum-address.d.ts} +0 -0
  104. package/lib/esm/{to-checksum-address.js → utils/to-checksum-address.js} +1 -1
  105. package/lib/esm/utils/wei-to-ether.d.ts +3 -0
  106. package/lib/esm/utils/wei-to-ether.js +7 -0
  107. package/package.json +11 -11
  108. package/readme.md +68 -5
  109. package/lib/cjs/rpc/utils/fetchers.d.ts +0 -7
  110. package/lib/esm/ether-to-wei.d.ts +0 -2
  111. package/lib/esm/ether-to-wei.js +0 -8
  112. package/lib/esm/rpc/utils/fetchers.d.ts +0 -7
  113. package/lib/esm/wei-to-ether.d.ts +0 -1
  114. package/lib/esm/wei-to-ether.js +0 -8
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ethers_1 = require("ethers");
7
+ const web3_1 = __importDefault(require("web3"));
8
+ const index_1 = require("../../index");
9
+ describe('is-address', () => {
10
+ it('should validate real addresses', () => {
11
+ const addresses = [
12
+ '0x52908400098527886E0F7030069857D2E4169EE7',
13
+ '0x8617E340B3D01FA5F11F306F4090FD50E238070D',
14
+ '0xde709f2102306220921060314715629080e2fb77',
15
+ '0x27b1fdb04752bbc536007a920d24acb045561c26',
16
+ '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed',
17
+ '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
18
+ '0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB',
19
+ '0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb',
20
+ '27b1fdb04752bbc536007a920d24acb045561c26' /* leading "0x" is not required */,
21
+ ];
22
+ addresses.forEach((address) => {
23
+ expect((0, index_1.isAddress)(address)).toStrictEqual(ethers_1.utils.isAddress(address));
24
+ expect((0, index_1.isAddress)(address)).toStrictEqual(web3_1.default.utils.isAddress(address));
25
+ });
26
+ });
27
+ it('should return false on invalid addresses', () => {
28
+ const addresses = [
29
+ '0x5290840009852',
30
+ '0x8617E340b3D01FA5F11F306F4090FD50E238070D',
31
+ '0x8617e340b3d01FA5F11F306F4090FD50E238070D' /* invalid checksum */,
32
+ ' 0xde709f2102306220921060314715629080e2fb77',
33
+ 'dawsbot.eth' /* ens invalid */,
34
+ '',
35
+ 'xyz',
36
+ '0x123',
37
+ ];
38
+ addresses.forEach((address) => {
39
+ const essentialEthIsAddress = (0, index_1.isAddress)(address);
40
+ const ethersIsAddress = ethers_1.utils.isAddress(address);
41
+ const web3IsAddress = web3_1.default.utils.isAddress(address);
42
+ expect(essentialEthIsAddress).toStrictEqual(ethersIsAddress);
43
+ expect(essentialEthIsAddress).toStrictEqual(web3IsAddress);
44
+ });
45
+ });
46
+ it('invalid type inputs', () => {
47
+ expect(() => {
48
+ // @ts-expect-error should not accept boolean
49
+ (0, index_1.isAddress)(false);
50
+ }).toThrow('string required. Received boolean');
51
+ expect(() => {
52
+ // @ts-expect-error should not accept array
53
+ (0, index_1.isAddress)([1, 2, 3]);
54
+ }).toThrow('string required. Received object');
55
+ });
56
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ethers_1 = require("ethers");
7
+ const web3_1 = __importDefault(require("web3"));
8
+ const index_1 = require("../../index");
9
+ describe('ether-to-wei', () => {
10
+ it('happy path', () => {
11
+ const addresses = [
12
+ '0x52908400098527886E0F7030069857D2E4169EE7',
13
+ '0x8617E340B3D01FA5F11F306F4090FD50E238070D',
14
+ '0xde709f2102306220921060314715629080e2fb77',
15
+ '0x27b1fdb04752bbc536007a920d24acb045561c26',
16
+ '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed',
17
+ '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
18
+ '0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB',
19
+ '0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb',
20
+ ];
21
+ addresses.forEach((address) => {
22
+ expect((0, index_1.toChecksumAddress)(address)).toStrictEqual(ethers_1.utils.getAddress(address));
23
+ expect((0, index_1.toChecksumAddress)(address)).toStrictEqual(web3_1.default.utils.toChecksumAddress(address));
24
+ });
25
+ });
26
+ it('invalid inputs', () => {
27
+ const invalidChecksumAddress = '0x8617E340b3D01FA5F11F306F4090FD50E238070D';
28
+ expect(() => {
29
+ (0, index_1.toChecksumAddress)(invalidChecksumAddress);
30
+ }).toThrow(`Invalid Checksum address for "${invalidChecksumAddress}"`);
31
+ expect(() => {
32
+ // @ts-expect-error should not accept boolean
33
+ (0, index_1.toChecksumAddress)(false);
34
+ }).toThrow('string required. Received boolean');
35
+ expect(() => {
36
+ // @ts-expect-error should not accept array
37
+ (0, index_1.toChecksumAddress)([1, 2, 3]);
38
+ }).toThrow('string required. Received object');
39
+ expect(() => {
40
+ (0, index_1.toChecksumAddress)('0x1');
41
+ }).toThrow('Invalid Ethereum address "0x1"');
42
+ });
43
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const big_js_1 = __importDefault(require("big.js"));
26
+ const ethers = __importStar(require("ethers"));
27
+ const web3_1 = __importDefault(require("web3"));
28
+ const index_1 = require("../../index");
29
+ describe('wei-to-ether', () => {
30
+ it('happy path', () => {
31
+ expect((0, index_1.weiToEther)('100000000000000000000.0').toString()).toStrictEqual('100');
32
+ expect((0, index_1.weiToEther)(100000000000000000000.0).toString()).toStrictEqual('100');
33
+ expect((0, index_1.weiToEther)('1000000000000000000000.0').toNumber()).toStrictEqual(1000);
34
+ expect((0, index_1.weiToEther)(1000000000000000000000.0).toNumber()).toStrictEqual(1000);
35
+ expect((0, index_1.weiToEther)((0, index_1.tinyBig)('1000000000000000000000.0')).toNumber()).toStrictEqual(1000);
36
+ expect((0, index_1.weiToEther)((0, index_1.tinyBig)(1000000000000000000000.0)).toNumber()).toStrictEqual(1000);
37
+ expect((0, index_1.weiToEther)((0, big_js_1.default)('1000000000000000000000.0')).toNumber()).toStrictEqual(1000);
38
+ expect((0, index_1.weiToEther)((0, big_js_1.default)(1000000000000000000000.0)).toNumber()).toStrictEqual(1000);
39
+ });
40
+ describe('matches ethers and web3 toString', () => {
41
+ it('toString', () => {
42
+ expect((0, index_1.weiToEther)('10').toString()).toStrictEqual(ethers.utils.formatEther('10'));
43
+ expect((0, index_1.weiToEther)('1000000000000000000000').toString()).toStrictEqual('1000');
44
+ expect((0, index_1.weiToEther)('10').toString()).toStrictEqual(web3_1.default.utils.fromWei('10', 'ether'));
45
+ expect((0, index_1.weiToEther)('1000000000000000000000').toString()).toStrictEqual(web3_1.default.utils.fromWei('1000000000000000000000', 'ether'));
46
+ });
47
+ it('toNumber', () => {
48
+ /* easy */
49
+ expect((0, index_1.weiToEther)('9').toNumber()).toStrictEqual(Number(ethers.utils.formatEther('9')));
50
+ // expect(weiToEther("9").toNumber()).toStrictEqual(
51
+ // Number(ethers.utils.formatEther("9")),
52
+ // );
53
+ expect((0, index_1.weiToEther)('9').toNumber()).toStrictEqual(Number(web3_1.default.utils.fromWei('9', 'ether')));
54
+ /* hard because they respond with scientific notation or overflowing */
55
+ expect((0, index_1.weiToEther)('999999').toNumber()).toStrictEqual(Number(ethers.utils.formatEther('999999')) /* overflow error if you use the ".toNumber()", */);
56
+ expect((0, index_1.weiToEther)('999999').toNumber()).toStrictEqual(Number(web3_1.default.utils.fromWei('999999', 'ether')));
57
+ });
58
+ });
59
+ it('wrong types', () => {
60
+ expect(() => {
61
+ // @ts-expect-error should not accept boolean
62
+ (0, index_1.weiToEther)(false);
63
+ }).toThrow();
64
+ expect(() => {
65
+ // @ts-expect-error should not accept array
66
+ (0, index_1.weiToEther)([1, 2, 3]);
67
+ }).toThrow();
68
+ });
69
+ });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toChecksumAddress = void 0;
4
4
  const sha3_1 = require("sha3");
5
- const validate_type_1 = require("./shared/validate-type");
5
+ const validate_type_1 = require("../shared/validate-type");
6
6
  /**
7
7
  * Returns an Ethereum address in proper mixed-case checksum.
8
8
  * Does NOT support ICAP
@@ -1,3 +1,5 @@
1
+ import Big from 'big.js';
2
+ import { TinyBig } from './../shared/tiny-big/tiny-big';
1
3
  /**
2
4
  * Convert from Ether to Wei
3
5
  *
@@ -21,4 +23,4 @@
21
23
  * // 1000000000000000000000
22
24
  * ```
23
25
  */
24
- export declare function weiToEther(weiQuantity: string | number): import("./shared/tiny-big/tiny-big").TinyBig;
26
+ export declare function weiToEther(weiQuantity: string | number | TinyBig | Big): TinyBig;
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.weiToEther = void 0;
7
- const big_js_1 = __importDefault(require("big.js"));
8
- const tiny_big_1 = require("./shared/tiny-big/tiny-big");
9
- const validate_type_1 = require("./shared/validate-type");
4
+ const tiny_big_1 = require("../shared/tiny-big/tiny-big");
5
+ const validate_type_1 = require("../shared/validate-type");
10
6
  /**
11
7
  * Convert from Ether to Wei
12
8
  *
@@ -31,8 +27,8 @@ const validate_type_1 = require("./shared/validate-type");
31
27
  * ```
32
28
  */
33
29
  function weiToEther(weiQuantity) {
34
- (0, validate_type_1.validateType)(weiQuantity, ['string', 'number']);
35
- const result = (0, big_js_1.default)(weiQuantity).div('1000000000000000000').toString();
30
+ (0, validate_type_1.validateType)(weiQuantity, ['string', 'number', 'object']);
31
+ const result = (0, tiny_big_1.tinyBig)(weiQuantity).div('1000000000000000000');
36
32
  return (0, tiny_big_1.tinyBig)(result);
37
33
  }
38
34
  exports.weiToEther = weiToEther;
@@ -0,0 +1,12 @@
1
+ import { JsonRpcProvider } from '../providers/JsonRpcProvider';
2
+ import { ContractInterface } from '../types/Contract.types';
3
+ export declare class BaseContract {
4
+ readonly _address: string;
5
+ readonly _contractInterface: ContractInterface;
6
+ readonly _provider: JsonRpcProvider;
7
+ constructor(addressOrName: string, contractInterface: ContractInterface, signerOrProvider: JsonRpcProvider);
8
+ }
9
+ export declare function defineReadOnly<T>(object: T, name: string, value: any): void;
10
+ export declare class Contract extends BaseContract {
11
+ readonly [key: string]: any;
12
+ }
@@ -0,0 +1,63 @@
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
+ };
10
+ import { decodeRPCResponse, encodeData, } from './utils/encode-decode-transaction';
11
+ import { buildRPCPostBody, post } from './utils/fetchers';
12
+ function estimateGas(txnData) {
13
+ txnData.split('').reduce((previousValue, currentValue) => {
14
+ const characterCost = currentValue === '0' ? 4 : 68;
15
+ return previousValue + characterCost;
16
+ }, 0);
17
+ }
18
+ export class BaseContract {
19
+ constructor(addressOrName, contractInterface, signerOrProvider) {
20
+ this._address = addressOrName;
21
+ this._contractInterface = contractInterface;
22
+ this._provider = signerOrProvider;
23
+ contractInterface
24
+ .filter((jsonABIArgument) => jsonABIArgument.type === 'function')
25
+ .forEach((jsonABIArgument) => {
26
+ if ('name' in jsonABIArgument &&
27
+ typeof jsonABIArgument.name === 'string') {
28
+ defineReadOnly(this, jsonABIArgument.name, (..._args) => __awaiter(this, void 0, void 0, function* () {
29
+ let functionArguments = _args;
30
+ let options = {};
31
+ const lastArg = _args[_args.length - 1];
32
+ if (!Array.isArray(lastArg) && typeof lastArg === 'object') {
33
+ options = lastArg;
34
+ functionArguments = _args.slice(0, _args.length - 1);
35
+ }
36
+ const data = encodeData(jsonABIArgument, functionArguments);
37
+ const decimalGas = typeof options.gasLimit === 'number'
38
+ ? options.gasLimit
39
+ : typeof (jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : jsonABIArgument.gas) ===
40
+ 'number'
41
+ ? estimateGas(data)
42
+ : 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
+ ]));
49
+ return decodeRPCResponse(jsonABIArgument, nodeResponse);
50
+ }));
51
+ }
52
+ });
53
+ }
54
+ }
55
+ export function defineReadOnly(object, name, value) {
56
+ Object.defineProperty(object, name, {
57
+ enumerable: true,
58
+ value: value,
59
+ writable: false,
60
+ });
61
+ }
62
+ export class Contract extends BaseContract {
63
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import Big from 'big.js';
11
11
  import omit from 'just-omit';
12
12
  import Web3 from 'web3';
13
- import { EssentialEth } from '.';
13
+ import { JsonRpcProvider } from '../providers/JsonRpcProvider';
14
14
  const rpcUrl = 'https://free-eth-node.com/api/eth';
15
15
  describe('matches web3', () => {
16
16
  function testBlockEquality(block1, block2) {
@@ -22,7 +22,7 @@ describe('matches web3', () => {
22
22
  .toNumber()).toBeLessThan(4000000);
23
23
  }
24
24
  it('should allow default eth node to get latest block', () => __awaiter(void 0, void 0, void 0, function* () {
25
- const essentialEth = new EssentialEth();
25
+ const essentialEth = new JsonRpcProvider();
26
26
  const web3 = new Web3(rpcUrl);
27
27
  const [eeLatestBlock, web3LatestBlock] = yield Promise.all([
28
28
  essentialEth.getBlock('latest'),
@@ -31,7 +31,7 @@ describe('matches web3', () => {
31
31
  testBlockEquality(eeLatestBlock, web3LatestBlock);
32
32
  }));
33
33
  it('should get latest block', () => __awaiter(void 0, void 0, void 0, function* () {
34
- const essentialEth = new EssentialEth(rpcUrl);
34
+ const essentialEth = new JsonRpcProvider(rpcUrl);
35
35
  const web3 = new Web3(rpcUrl);
36
36
  const [eeLatestBlock, web3LatestBlock] = yield Promise.all([
37
37
  essentialEth.getBlock('latest'),
@@ -40,7 +40,7 @@ describe('matches web3', () => {
40
40
  testBlockEquality(eeLatestBlock, web3LatestBlock);
41
41
  }));
42
42
  it('should get earliest block', () => __awaiter(void 0, void 0, void 0, function* () {
43
- const essentialEth = new EssentialEth(rpcUrl);
43
+ const essentialEth = new JsonRpcProvider(rpcUrl);
44
44
  const web3 = new Web3(rpcUrl);
45
45
  const [eeEarliestBlock, web3EarliestBlock] = yield Promise.all([
46
46
  essentialEth.getBlock('earliest'),
@@ -50,7 +50,7 @@ describe('matches web3', () => {
50
50
  }));
51
51
  const blockNumber = Math.floor(Math.random() * 13250630);
52
52
  it(`should get random block as decimal integer. (block #${blockNumber})`, () => __awaiter(void 0, void 0, void 0, function* () {
53
- const essentialEth = new EssentialEth(rpcUrl);
53
+ const essentialEth = new JsonRpcProvider(rpcUrl);
54
54
  const web3 = new Web3(rpcUrl);
55
55
  const [eeRandomBlock, web3RandomBlock] = yield Promise.all([
56
56
  essentialEth.getBlock(blockNumber, true),
@@ -0,0 +1,2 @@
1
+ import { JSONABI } from '../../../types/Contract.types';
2
+ export declare const abi: JSONABI;