essential-eth 0.5.9 → 0.5.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/{lib/esm → dist}/classes/Contract.d.ts +11 -11
- package/dist/classes/test/Contract/crv-abi.d.ts +2 -0
- package/dist/classes/test/Contract/ens-abi.d.ts +2 -0
- package/dist/classes/test/Contract/fei-abi.d.ts +2 -0
- package/dist/classes/test/Contract/foo-abi.d.ts +2 -0
- package/dist/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/dist/classes/utils/clean-block.d.ts +3 -0
- package/{lib/esm → dist}/classes/utils/clean-log.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/clean-transaction-receipt.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/clean-transaction.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/encode-decode-transaction.d.ts +4 -4
- package/{lib/esm → dist}/classes/utils/fetchers.d.ts +9 -9
- package/{lib/esm → dist}/classes/utils/hex-to-decimal.d.ts +1 -1
- package/{lib/esm → dist}/classes/utils/prepare-transaction.d.ts +2 -2
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/{lib/esm → dist}/index.d.ts +25 -25
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.modern.mjs +2 -0
- package/dist/index.modern.mjs.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/{lib/esm → dist}/logger/logger.d.ts +11 -11
- package/dist/logger/package-version.d.ts +1 -0
- package/{lib/esm → dist}/providers/BaseProvider.d.ts +24 -24
- package/{lib/esm → dist}/providers/FallthroughProvider.d.ts +11 -11
- package/{lib/esm → dist}/providers/JsonRpcProvider.d.ts +7 -7
- package/{lib/cjs → dist}/providers/test/rpc-urls.d.ts +11 -11
- package/{lib/cjs → dist}/providers/utils/chains-info.d.ts +467 -423
- package/{lib/esm → dist}/shared/tiny-big/helpers.d.ts +1 -1
- package/{lib/esm → dist}/shared/tiny-big/tiny-big.d.ts +10 -10
- package/{lib/cjs → dist}/shared/validate-type.d.ts +3 -3
- package/{lib/cjs → dist}/types/Block.types.d.ts +40 -41
- package/{lib/cjs → dist}/types/Contract.types.d.ts +24 -24
- package/{lib/esm → dist}/types/Filter.types.d.ts +12 -12
- package/{lib/esm → dist}/types/Network.types.d.ts +5 -5
- package/{lib/esm → dist}/types/Transaction.types.d.ts +113 -113
- package/{lib/esm → dist}/utils/bytes.d.ts +40 -40
- package/{lib/esm → dist}/utils/compute-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/compute-public-key.d.ts +2 -2
- package/{lib/esm → dist}/utils/ether-to-gwei.d.ts +3 -3
- package/dist/utils/ether-to-wei.d.ts +3 -0
- package/dist/utils/gwei-to-ether.d.ts +3 -0
- package/{lib/esm → dist}/utils/hash-message.d.ts +2 -2
- package/{lib/esm → dist}/utils/is-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/keccak256.d.ts +2 -2
- package/{lib/esm → dist}/utils/solidity-keccak256.d.ts +2 -2
- package/{lib/esm → dist}/utils/split-signature.d.ts +2 -2
- package/{lib/esm → dist}/utils/to-checksum-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/to-utf8-bytes.d.ts +1 -1
- package/dist/utils/wei-to-ether.d.ts +3 -0
- package/package.json +42 -19
- package/lib/cjs/classes/Contract.d.ts +0 -78
- package/lib/cjs/classes/Contract.js +0 -140
- package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
- package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
- package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
- package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
- package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
- package/lib/cjs/classes/utils/clean-block.d.ts +0 -121
- package/lib/cjs/classes/utils/clean-block.js +0 -160
- package/lib/cjs/classes/utils/clean-log.d.ts +0 -9
- package/lib/cjs/classes/utils/clean-log.js +0 -37
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -14
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +0 -50
- package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -14
- package/lib/cjs/classes/utils/clean-transaction.js +0 -51
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +0 -16
- package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -137
- package/lib/cjs/classes/utils/fetchers.d.ts +0 -39
- package/lib/cjs/classes/utils/fetchers.js +0 -81
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +0 -18
- package/lib/cjs/classes/utils/hex-to-decimal.js +0 -24
- package/lib/cjs/classes/utils/prepare-transaction.d.ts +0 -6
- package/lib/cjs/classes/utils/prepare-transaction.js +0 -45
- package/lib/cjs/index.d.ts +0 -25
- package/lib/cjs/index.js +0 -54
- package/lib/cjs/logger/logger.d.ts +0 -11
- package/lib/cjs/logger/logger.js +0 -36
- package/lib/cjs/logger/package-version.d.ts +0 -1
- package/lib/cjs/logger/package-version.js +0 -5
- package/lib/cjs/providers/BaseProvider.d.ts +0 -353
- package/lib/cjs/providers/BaseProvider.js +0 -512
- package/lib/cjs/providers/FallthroughProvider.d.ts +0 -24
- package/lib/cjs/providers/FallthroughProvider.js +0 -65
- package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -33
- package/lib/cjs/providers/JsonRpcProvider.js +0 -46
- package/lib/cjs/providers/test/rpc-urls.js +0 -14
- package/lib/cjs/providers/utils/chains-info.js +0 -1270
- package/lib/cjs/shared/tiny-big/helpers.d.ts +0 -17
- package/lib/cjs/shared/tiny-big/helpers.js +0 -97
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -58
- package/lib/cjs/shared/tiny-big/tiny-big.js +0 -101
- package/lib/cjs/shared/validate-type.js +0 -9
- package/lib/cjs/types/Block.types.js +0 -2
- package/lib/cjs/types/Contract.types.js +0 -2
- package/lib/cjs/types/Filter.types.d.ts +0 -16
- package/lib/cjs/types/Filter.types.js +0 -2
- package/lib/cjs/types/Network.types.d.ts +0 -8
- package/lib/cjs/types/Network.types.js +0 -2
- package/lib/cjs/types/Transaction.types.d.ts +0 -123
- package/lib/cjs/types/Transaction.types.js +0 -2
- package/lib/cjs/utils/bytes.d.ts +0 -289
- package/lib/cjs/utils/bytes.js +0 -711
- package/lib/cjs/utils/compute-address.d.ts +0 -17
- package/lib/cjs/utils/compute-address.js +0 -33
- package/lib/cjs/utils/compute-public-key.d.ts +0 -18
- package/lib/cjs/utils/compute-public-key.js +0 -26
- package/lib/cjs/utils/ether-to-gwei.d.ts +0 -27
- package/lib/cjs/utils/ether-to-gwei.js +0 -35
- package/lib/cjs/utils/ether-to-wei.d.ts +0 -27
- package/lib/cjs/utils/ether-to-wei.js +0 -35
- package/lib/cjs/utils/gwei-to-ether.d.ts +0 -27
- package/lib/cjs/utils/gwei-to-ether.js +0 -35
- package/lib/cjs/utils/hash-message.d.ts +0 -14
- package/lib/cjs/utils/hash-message.js +0 -28
- package/lib/cjs/utils/is-address.d.ts +0 -24
- package/lib/cjs/utils/is-address.js +0 -39
- package/lib/cjs/utils/keccak256.d.ts +0 -16
- package/lib/cjs/utils/keccak256.js +0 -31
- package/lib/cjs/utils/solidity-keccak256.d.ts +0 -39
- package/lib/cjs/utils/solidity-keccak256.js +0 -138
- package/lib/cjs/utils/split-signature.d.ts +0 -24
- package/lib/cjs/utils/split-signature.js +0 -163
- package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
- package/lib/cjs/utils/to-checksum-address.js +0 -46
- package/lib/cjs/utils/to-utf8-bytes.d.ts +0 -15
- package/lib/cjs/utils/to-utf8-bytes.js +0 -21
- package/lib/cjs/utils/wei-to-ether.d.ts +0 -27
- package/lib/cjs/utils/wei-to-ether.js +0 -45
- package/lib/esm/classes/Contract.js +0 -65
- package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
- package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
- package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
- package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
- package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
- package/lib/esm/classes/utils/clean-block.d.ts +0 -3
- package/lib/esm/classes/utils/clean-block.js +0 -35
- package/lib/esm/classes/utils/clean-log.js +0 -26
- package/lib/esm/classes/utils/clean-transaction-receipt.js +0 -34
- package/lib/esm/classes/utils/clean-transaction.js +0 -33
- package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
- package/lib/esm/classes/utils/fetchers.js +0 -43
- package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
- package/lib/esm/classes/utils/prepare-transaction.js +0 -34
- package/lib/esm/index.js +0 -20
- package/lib/esm/logger/logger.js +0 -33
- package/lib/esm/logger/package-version.d.ts +0 -1
- package/lib/esm/logger/package-version.js +0 -1
- package/lib/esm/providers/BaseProvider.js +0 -157
- package/lib/esm/providers/FallthroughProvider.js +0 -41
- package/lib/esm/providers/JsonRpcProvider.js +0 -15
- package/lib/esm/providers/test/rpc-urls.d.ts +0 -11
- package/lib/esm/providers/test/rpc-urls.js +0 -11
- package/lib/esm/providers/utils/chains-info.d.ts +0 -423
- package/lib/esm/providers/utils/chains-info.js +0 -1266
- package/lib/esm/shared/tiny-big/helpers.js +0 -58
- package/lib/esm/shared/tiny-big/tiny-big.js +0 -45
- package/lib/esm/shared/validate-type.d.ts +0 -3
- package/lib/esm/shared/validate-type.js +0 -5
- package/lib/esm/types/Block.types.d.ts +0 -40
- package/lib/esm/types/Block.types.js +0 -1
- package/lib/esm/types/Contract.types.d.ts +0 -24
- package/lib/esm/types/Contract.types.js +0 -1
- package/lib/esm/types/Filter.types.js +0 -1
- package/lib/esm/types/Network.types.js +0 -1
- package/lib/esm/types/Transaction.types.js +0 -1
- package/lib/esm/utils/bytes.js +0 -245
- package/lib/esm/utils/compute-address.js +0 -11
- package/lib/esm/utils/compute-public-key.js +0 -6
- package/lib/esm/utils/ether-to-gwei.js +0 -7
- package/lib/esm/utils/ether-to-wei.d.ts +0 -3
- package/lib/esm/utils/ether-to-wei.js +0 -7
- package/lib/esm/utils/gwei-to-ether.d.ts +0 -3
- package/lib/esm/utils/gwei-to-ether.js +0 -7
- package/lib/esm/utils/hash-message.js +0 -12
- package/lib/esm/utils/is-address.js +0 -12
- package/lib/esm/utils/keccak256.js +0 -13
- package/lib/esm/utils/solidity-keccak256.js +0 -85
- package/lib/esm/utils/split-signature.js +0 -126
- package/lib/esm/utils/to-checksum-address.js +0 -25
- package/lib/esm/utils/to-utf8-bytes.js +0 -3
- package/lib/esm/utils/wei-to-ether.d.ts +0 -3
- package/lib/esm/utils/wei-to-ether.js +0 -16
package/package.json
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "essential-eth",
|
|
3
3
|
"description": "Ultralight JS for Ethereum",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.10",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"private": false,
|
|
8
|
+
"source": "src/index.ts",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"browser": "./dist/index.umd.js",
|
|
11
|
+
"umd:main": "./dist/index.umd.js",
|
|
12
|
+
"jsnext:main": "./dist/index.modern.js",
|
|
13
|
+
"module": "./dist/index.module.js",
|
|
14
|
+
"syntax": {
|
|
15
|
+
"esmodules": "./dist/index.modern.js"
|
|
16
|
+
},
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"typings": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"browser": "./dist/index.module.js",
|
|
22
|
+
"umd": "./dist/index.umd.js",
|
|
23
|
+
"import": "./dist/index.module.js",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
9
27
|
"files": [
|
|
10
|
-
"
|
|
28
|
+
"dist/"
|
|
11
29
|
],
|
|
12
30
|
"bugs": {
|
|
13
31
|
"url": "https://github.com/dawsbot/essential-eth/issues"
|
|
@@ -19,30 +37,27 @@
|
|
|
19
37
|
"name": "etherToWei",
|
|
20
38
|
"path": "src/index.ts",
|
|
21
39
|
"import": "{ etherToWei }",
|
|
22
|
-
"limit": "3.
|
|
40
|
+
"limit": "3.58kb"
|
|
23
41
|
},
|
|
24
42
|
{
|
|
25
43
|
"name": "JsonRpcProvider",
|
|
26
44
|
"path": "src/index.ts",
|
|
27
45
|
"import": "{ JsonRpcProvider }",
|
|
28
|
-
"limit": "
|
|
46
|
+
"limit": "20.24kb"
|
|
29
47
|
},
|
|
30
48
|
{
|
|
31
49
|
"name": "Contract",
|
|
32
50
|
"path": "src/index.ts",
|
|
33
51
|
"import": "{ Contract }",
|
|
34
|
-
"limit": "
|
|
52
|
+
"limit": "15.86kb"
|
|
35
53
|
}
|
|
36
54
|
],
|
|
37
55
|
"scripts": {
|
|
38
56
|
"size": "size-limit",
|
|
39
|
-
"test": "npm-run-all --parallel jest
|
|
57
|
+
"test": "npm-run-all --parallel jest build lint",
|
|
40
58
|
"test:all-node-versions": "npx trevor",
|
|
41
59
|
"lint": "eslint --cache --fix .",
|
|
42
|
-
"
|
|
43
|
-
"tsc:esm": "tsc -p tsconfig.json",
|
|
44
|
-
"tsc:cjs": "tsc -p tsconfig-cjs.json",
|
|
45
|
-
"build": "rm -rf lib && npm run compile",
|
|
60
|
+
"build": "rm -rf lib && microbundle",
|
|
46
61
|
"build:readme": "bash ./scripts/markdown-magic/build-readme.sh",
|
|
47
62
|
"jest": "jest",
|
|
48
63
|
"build:chains-info": "npx ts-node scripts/fetch-chains-info.ts # used in getNetwork()",
|
|
@@ -70,28 +85,29 @@
|
|
|
70
85
|
"eslint": "^8.16.0",
|
|
71
86
|
"eslint-plugin-jest": "^26.2.2",
|
|
72
87
|
"eslint-plugin-jsdoc": "38.0.2",
|
|
73
|
-
"ethers": "^5.6.
|
|
88
|
+
"ethers": "^5.6.9",
|
|
74
89
|
"express": "^4.17.1",
|
|
75
90
|
"husky": "^7.0.4",
|
|
76
91
|
"jest": "^27.5.1",
|
|
77
92
|
"jest-dev-server": "^6.0.3",
|
|
78
93
|
"just-omit": "^2.0.1",
|
|
79
94
|
"lint-staged": "^12.4.1",
|
|
95
|
+
"microbundle": "^0.15.0",
|
|
80
96
|
"npm-run-all": "^4.1.5",
|
|
81
97
|
"perf_hooks": "^0.0.1",
|
|
82
|
-
"prettier": "^2.
|
|
98
|
+
"prettier": "^2.7.1",
|
|
83
99
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
84
100
|
"size-limit": "^7.0.8",
|
|
85
101
|
"ts-jest": "^27.1.4",
|
|
86
102
|
"ts-node": "^10.2.1",
|
|
87
103
|
"typedoc": "^0.22.15",
|
|
88
|
-
"typescript": "^4.
|
|
89
|
-
"web3": "^1.7.
|
|
104
|
+
"typescript": "^4.7.4",
|
|
105
|
+
"web3": "^1.7.5"
|
|
90
106
|
},
|
|
91
107
|
"dependencies": {
|
|
92
108
|
"@noble/secp256k1": "^1.5.5",
|
|
93
|
-
"@types/big.js": "^6.1.
|
|
94
|
-
"big.js": "^6.2.
|
|
109
|
+
"@types/big.js": "^6.1.5",
|
|
110
|
+
"big.js": "^6.2.1",
|
|
95
111
|
"isomorphic-unfetch": "^3.1.0",
|
|
96
112
|
"sha3": "^2.1.4"
|
|
97
113
|
},
|
|
@@ -105,5 +121,12 @@
|
|
|
105
121
|
"trailingComma": "all",
|
|
106
122
|
"tabWidth": 2,
|
|
107
123
|
"singleQuote": true
|
|
108
|
-
}
|
|
124
|
+
},
|
|
125
|
+
"keywords": [
|
|
126
|
+
"ethereum",
|
|
127
|
+
"polygon",
|
|
128
|
+
"evm",
|
|
129
|
+
"web-performance",
|
|
130
|
+
"tiny"
|
|
131
|
+
]
|
|
109
132
|
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { JsonRpcProvider } from '../providers/JsonRpcProvider';
|
|
2
|
-
import { ContractInterface } from '../types/Contract.types';
|
|
3
|
-
export declare class BaseContract {
|
|
4
|
-
/**
|
|
5
|
-
* The URL to your Eth node. Consider POKT or Infura
|
|
6
|
-
*/
|
|
7
|
-
private readonly _address;
|
|
8
|
-
private readonly _provider;
|
|
9
|
-
/**
|
|
10
|
-
* @param addressOrName The ethereum address of the smart-contract
|
|
11
|
-
* @param contractInterface The JSON ABI of the smart-contract (like http://api.etherscan.io/api?module=contract&action=getabi&address=0x090d4613473dee047c3f2706764f49e0821d256e&format=raw)
|
|
12
|
-
* @param signerOrProvider An instantiated essential-eth provider
|
|
13
|
-
* @example
|
|
14
|
-
*/
|
|
15
|
-
constructor(addressOrName: string, contractInterface: ContractInterface, signerOrProvider: JsonRpcProvider);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Applies the unique contract's methods to the instantiated Contract in the constructor based-upon the provided ABI
|
|
19
|
-
*
|
|
20
|
-
* @param object
|
|
21
|
-
* @param name
|
|
22
|
-
* @param value
|
|
23
|
-
* @example
|
|
24
|
-
*/
|
|
25
|
-
export declare function defineReadOnly<T>(object: T, name: string, value: any): void;
|
|
26
|
-
/**
|
|
27
|
-
* @alpha
|
|
28
|
-
* Only accepts ABIS in JSON format. This allows for stronger typing and assurances of data-types
|
|
29
|
-
* Only read-only function calls currently supported.
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* import { Contract, JsonRpcProvider } from 'essential-eth';
|
|
33
|
-
* // UNI airdrop contract
|
|
34
|
-
* const contractAddress = '0x090D4613473dEE047c3f2706764f49E0821D256e';
|
|
35
|
-
* const provider = new JsonRpcProvider();
|
|
36
|
-
*
|
|
37
|
-
* const JSONABI = [
|
|
38
|
-
* {
|
|
39
|
-
* inputs: [
|
|
40
|
-
* {
|
|
41
|
-
* internalType: 'uint256',
|
|
42
|
-
* name: 'index',
|
|
43
|
-
* type: 'uint256',
|
|
44
|
-
* },
|
|
45
|
-
* ],
|
|
46
|
-
* name: 'isClaimed',
|
|
47
|
-
* outputs: [
|
|
48
|
-
* {
|
|
49
|
-
* internalType: 'bool',
|
|
50
|
-
* name: '',
|
|
51
|
-
* type: 'bool',
|
|
52
|
-
* },
|
|
53
|
-
* ],
|
|
54
|
-
* stateMutability: 'view',
|
|
55
|
-
* type: 'function',
|
|
56
|
-
* },
|
|
57
|
-
* ]
|
|
58
|
-
*
|
|
59
|
-
* const contract = new Contract(
|
|
60
|
-
* contractAddress,
|
|
61
|
-
* JSONABI,
|
|
62
|
-
* provider,
|
|
63
|
-
* );
|
|
64
|
-
*
|
|
65
|
-
* (async () => {
|
|
66
|
-
* // prints boolean as to whether index 0 has claimed airdrop or not
|
|
67
|
-
* console.log(await contract.isClaimed(0));
|
|
68
|
-
* })()
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export declare class Contract extends BaseContract {
|
|
74
|
-
/**
|
|
75
|
-
* The function names on any given contract. Like "isClaimed", "merkleRoot", etc.
|
|
76
|
-
*/
|
|
77
|
-
readonly [key: string]: any;
|
|
78
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Contract = exports.defineReadOnly = exports.BaseContract = void 0;
|
|
13
|
-
const encode_decode_transaction_1 = require("./utils/encode-decode-transaction");
|
|
14
|
-
const fetchers_1 = require("./utils/fetchers");
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @param txnData
|
|
18
|
-
* @example
|
|
19
|
-
*/
|
|
20
|
-
function estimateGas(txnData) {
|
|
21
|
-
// https://ethereum.stackexchange.com/questions/1570/what-does-intrinsic-gas-too-low-mean/1694
|
|
22
|
-
txnData.split('').reduce((previousValue, currentValue) => {
|
|
23
|
-
// 0 characters are 4 gwei, all others are 48 gwei
|
|
24
|
-
const characterCost = currentValue === '0' ? 4 : 68;
|
|
25
|
-
return previousValue + characterCost;
|
|
26
|
-
}, 0);
|
|
27
|
-
}
|
|
28
|
-
class BaseContract {
|
|
29
|
-
/**
|
|
30
|
-
* @param addressOrName The ethereum address of the smart-contract
|
|
31
|
-
* @param contractInterface The JSON ABI of the smart-contract (like http://api.etherscan.io/api?module=contract&action=getabi&address=0x090d4613473dee047c3f2706764f49e0821d256e&format=raw)
|
|
32
|
-
* @param signerOrProvider An instantiated essential-eth provider
|
|
33
|
-
* @example
|
|
34
|
-
*/
|
|
35
|
-
constructor(addressOrName, contractInterface, signerOrProvider) {
|
|
36
|
-
this._address = addressOrName;
|
|
37
|
-
this._provider = signerOrProvider;
|
|
38
|
-
contractInterface
|
|
39
|
-
.filter((jsonABIArgument) => jsonABIArgument.type === 'function')
|
|
40
|
-
.forEach((jsonABIArgument) => {
|
|
41
|
-
if ('name' in jsonABIArgument &&
|
|
42
|
-
typeof jsonABIArgument.name === 'string') {
|
|
43
|
-
defineReadOnly(this, jsonABIArgument.name, (..._args) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
let functionArguments = _args;
|
|
45
|
-
let options = {};
|
|
46
|
-
// remove options from encoding
|
|
47
|
-
const lastArg = _args[_args.length - 1];
|
|
48
|
-
if (!Array.isArray(lastArg) && typeof lastArg === 'object') {
|
|
49
|
-
options = lastArg;
|
|
50
|
-
functionArguments = _args.slice(0, _args.length - 1);
|
|
51
|
-
}
|
|
52
|
-
const data = (0, encode_decode_transaction_1.encodeData)(jsonABIArgument, functionArguments);
|
|
53
|
-
const decimalGas = typeof options.gasLimit === 'number'
|
|
54
|
-
? options.gasLimit /* user passed in "gasLimit" directly */
|
|
55
|
-
: typeof (jsonABIArgument === null || jsonABIArgument === void 0 ? void 0 : jsonABIArgument.gas) ===
|
|
56
|
-
'number' /* ABI specified "gas". */
|
|
57
|
-
? estimateGas(data)
|
|
58
|
-
: null;
|
|
59
|
-
const req = () => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return yield (0, fetchers_1.post)(this._provider.selectRpcUrl(), (0, fetchers_1.buildRPCPostBody)('eth_call', [
|
|
61
|
-
Object.assign({ to: this._address.toLowerCase(), data }, (decimalGas
|
|
62
|
-
? { gas: `0x${decimalGas.toString(16)}` }
|
|
63
|
-
: {})),
|
|
64
|
-
'latest',
|
|
65
|
-
]));
|
|
66
|
-
});
|
|
67
|
-
const nodeResponse = yield req();
|
|
68
|
-
return (0, encode_decode_transaction_1.decodeRPCResponse)(jsonABIArgument, nodeResponse);
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.BaseContract = BaseContract;
|
|
75
|
-
/**
|
|
76
|
-
* Applies the unique contract's methods to the instantiated Contract in the constructor based-upon the provided ABI
|
|
77
|
-
*
|
|
78
|
-
* @param object
|
|
79
|
-
* @param name
|
|
80
|
-
* @param value
|
|
81
|
-
* @example
|
|
82
|
-
*/
|
|
83
|
-
function defineReadOnly(object, name, value) {
|
|
84
|
-
Object.defineProperty(object, name, {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
value: value,
|
|
87
|
-
writable: false,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
exports.defineReadOnly = defineReadOnly;
|
|
91
|
-
/**
|
|
92
|
-
* @alpha
|
|
93
|
-
* Only accepts ABIS in JSON format. This allows for stronger typing and assurances of data-types
|
|
94
|
-
* Only read-only function calls currently supported.
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* import { Contract, JsonRpcProvider } from 'essential-eth';
|
|
98
|
-
* // UNI airdrop contract
|
|
99
|
-
* const contractAddress = '0x090D4613473dEE047c3f2706764f49E0821D256e';
|
|
100
|
-
* const provider = new JsonRpcProvider();
|
|
101
|
-
*
|
|
102
|
-
* const JSONABI = [
|
|
103
|
-
* {
|
|
104
|
-
* inputs: [
|
|
105
|
-
* {
|
|
106
|
-
* internalType: 'uint256',
|
|
107
|
-
* name: 'index',
|
|
108
|
-
* type: 'uint256',
|
|
109
|
-
* },
|
|
110
|
-
* ],
|
|
111
|
-
* name: 'isClaimed',
|
|
112
|
-
* outputs: [
|
|
113
|
-
* {
|
|
114
|
-
* internalType: 'bool',
|
|
115
|
-
* name: '',
|
|
116
|
-
* type: 'bool',
|
|
117
|
-
* },
|
|
118
|
-
* ],
|
|
119
|
-
* stateMutability: 'view',
|
|
120
|
-
* type: 'function',
|
|
121
|
-
* },
|
|
122
|
-
* ]
|
|
123
|
-
*
|
|
124
|
-
* const contract = new Contract(
|
|
125
|
-
* contractAddress,
|
|
126
|
-
* JSONABI,
|
|
127
|
-
* provider,
|
|
128
|
-
* );
|
|
129
|
-
*
|
|
130
|
-
* (async () => {
|
|
131
|
-
* // prints boolean as to whether index 0 has claimed airdrop or not
|
|
132
|
-
* console.log(await contract.isClaimed(0));
|
|
133
|
-
* })()
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
class Contract extends BaseContract {
|
|
139
|
-
}
|
|
140
|
-
exports.Contract = Contract;
|