essential-eth 0.5.9 → 0.5.10-next.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/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/{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.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 +21 -14
- 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
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeRPCResponse = exports.encodeData = exports.hexFalse = void 0;
|
|
4
|
-
const sha3_1 = require("sha3");
|
|
5
|
-
const __1 = require("../..");
|
|
6
|
-
const hex_to_decimal_1 = require("./hex-to-decimal");
|
|
7
|
-
exports.hexFalse = '0'.repeat(64);
|
|
8
|
-
const hexTrue = '0'.repeat(63) + '1';
|
|
9
|
-
/**
|
|
10
|
-
* Expands an integer type to use a default of 256 bits. Used for consistency; not required in Solidity
|
|
11
|
-
*
|
|
12
|
-
* @see https://ethereum.stackexchange.com/questions/43241/why-write-uint256-instead-of-uint-if-theyre-the-same-thing
|
|
13
|
-
* @param type the type to explicitly define as 256 bits
|
|
14
|
-
* @returns the integer type expanded to explicitly be 256 bits when possible
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* expandType('uint[]');
|
|
18
|
-
* // 'uint256[]'
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
function expandType(type) {
|
|
22
|
-
// https://docs.soliditylang.org/en/v0.8.7/types.html#integers
|
|
23
|
-
if (type === 'uint[]') {
|
|
24
|
-
return 'uint256[]';
|
|
25
|
-
}
|
|
26
|
-
else if (type === 'int[]') {
|
|
27
|
-
return 'int256[]';
|
|
28
|
-
}
|
|
29
|
-
return type;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param jsonABIArgument
|
|
34
|
-
* @param args
|
|
35
|
-
* @example
|
|
36
|
-
*/
|
|
37
|
-
function encodeData(jsonABIArgument, args) {
|
|
38
|
-
const hash = new sha3_1.Keccak(256);
|
|
39
|
-
/* first 4 bytes will create the data parameter */
|
|
40
|
-
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map((input) => expandType(input.type))})`;
|
|
41
|
-
// encoding learnt from https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api
|
|
42
|
-
const functionHash = hash.update(functionString).digest('hex');
|
|
43
|
-
// no arrays
|
|
44
|
-
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
45
|
-
let shouldValidateInputLength = true;
|
|
46
|
-
// inputs contains 1 or more arrays
|
|
47
|
-
if (jsonABIArgument.inputs.find((input) => input.type.includes('['))) {
|
|
48
|
-
shouldValidateInputLength = false;
|
|
49
|
-
}
|
|
50
|
-
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
51
|
-
throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
|
|
52
|
-
}
|
|
53
|
-
const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
|
|
54
|
-
var _a;
|
|
55
|
-
if (input.type.includes('[')) {
|
|
56
|
-
// strip array and length like "[2]" from type
|
|
57
|
-
const basicType = (_a = /([^[]*)\[.*$/g.exec(input.type)) === null || _a === void 0 ? void 0 : _a[1];
|
|
58
|
-
args.forEach((arg) => {
|
|
59
|
-
acc = acc.concat([[arg, basicType]]);
|
|
60
|
-
});
|
|
61
|
-
return acc;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return acc.concat([[args[i], input.type]]);
|
|
65
|
-
}
|
|
66
|
-
}, []);
|
|
67
|
-
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
68
|
-
let rawArg = arg;
|
|
69
|
-
switch (inputType) {
|
|
70
|
-
case 'bool':
|
|
71
|
-
return arg ? hexTrue : exports.hexFalse;
|
|
72
|
-
case 'address':
|
|
73
|
-
// remove leading "0x"
|
|
74
|
-
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
if (inputType.startsWith('bytes')) {
|
|
78
|
-
// encode each character to hex
|
|
79
|
-
const argEncoded = rawArg
|
|
80
|
-
.split('')
|
|
81
|
-
.map((character) => character.charCodeAt(0).toString(16))
|
|
82
|
-
.join('');
|
|
83
|
-
const paddedEncodedArg = argEncoded.padEnd(64, '0');
|
|
84
|
-
return paddedEncodedArg;
|
|
85
|
-
}
|
|
86
|
-
else if (inputType === 'uint256') {
|
|
87
|
-
const argEncoded = BigInt(arg).toString(16);
|
|
88
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
89
|
-
return paddedEncodedArg;
|
|
90
|
-
}
|
|
91
|
-
else if (inputType.startsWith('uint')) {
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const argEncoded = rawArg.toString(16);
|
|
99
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
100
|
-
return paddedEncodedArg;
|
|
101
|
-
});
|
|
102
|
-
const functionEncoded = functionHash.slice(0, 8);
|
|
103
|
-
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
104
|
-
return data;
|
|
105
|
-
}
|
|
106
|
-
exports.encodeData = encodeData;
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
* @param jsonABIArgument
|
|
110
|
-
* @param nodeResponse
|
|
111
|
-
* @example
|
|
112
|
-
*/
|
|
113
|
-
function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
114
|
-
const rawOutputs = jsonABIArgument.outputs;
|
|
115
|
-
// chunk response every 64 characters
|
|
116
|
-
const encodedOutputs = nodeResponse.slice(2).match(/.{1,64}/g);
|
|
117
|
-
const outputs = (encodedOutputs || []).map((output, i) => {
|
|
118
|
-
const outputType = (rawOutputs || [])[i].type;
|
|
119
|
-
switch (outputType) {
|
|
120
|
-
case 'bool':
|
|
121
|
-
return output === hexTrue;
|
|
122
|
-
case 'address':
|
|
123
|
-
/* address types have 26 leading zeroes to remove */
|
|
124
|
-
return (0, __1.toChecksumAddress)(`0x${output.slice(24)}`);
|
|
125
|
-
case 'uint256':
|
|
126
|
-
return (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
|
|
127
|
-
case 'bytes32':
|
|
128
|
-
return `0x${output}`;
|
|
129
|
-
case 'uint8':
|
|
130
|
-
return Number((0, hex_to_decimal_1.hexToDecimal)(`0x${output}`));
|
|
131
|
-
default:
|
|
132
|
-
throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
return outputs.length === 1 ? outputs[0] : outputs;
|
|
136
|
-
}
|
|
137
|
-
exports.decodeRPCResponse = decodeRPCResponse;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
|
|
3
|
-
*
|
|
4
|
-
* @param url the URL to send the request to
|
|
5
|
-
* @param body the body data (JSON) to send with the request
|
|
6
|
-
* @returns the JSON response from the server
|
|
7
|
-
* @example
|
|
8
|
-
* ```javascript
|
|
9
|
-
* post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
|
|
10
|
-
* // '0x66fa8dbfd'
|
|
11
|
-
*
|
|
12
|
-
* post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
|
|
13
|
-
* // '0x312faeb995df61d4'
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
17
|
-
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
|
|
18
|
-
/**
|
|
19
|
-
* Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
|
|
20
|
-
*
|
|
21
|
-
* @param method the RPC method to be invoked
|
|
22
|
-
* @param params the parameters to be passed to the defined method
|
|
23
|
-
* @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
|
|
24
|
-
* @example
|
|
25
|
-
* ```javascript
|
|
26
|
-
* buildRPCPostBody('eth_gasPrice', []);
|
|
27
|
-
* // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
|
|
28
|
-
*
|
|
29
|
-
* buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
|
|
30
|
-
* // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
34
|
-
jsonrpc: string;
|
|
35
|
-
id: number;
|
|
36
|
-
method: RPCMethodName;
|
|
37
|
-
params: unknown[];
|
|
38
|
-
};
|
|
39
|
-
export {};
|
|
@@ -1,81 +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
|
-
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
|
-
/**
|
|
18
|
-
* Makes a post request with the specified JSON data, normally to the a Ethereum JSON RPC API endpoint
|
|
19
|
-
*
|
|
20
|
-
* @param url the URL to send the request to
|
|
21
|
-
* @param body the body data (JSON) to send with the request
|
|
22
|
-
* @returns the JSON response from the server
|
|
23
|
-
* @example
|
|
24
|
-
* ```javascript
|
|
25
|
-
* post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] });
|
|
26
|
-
* // '0x66fa8dbfd'
|
|
27
|
-
*
|
|
28
|
-
* post('https://free-eth-node.com/api/eth', { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] });
|
|
29
|
-
* // '0x312faeb995df61d4'
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
function post(url, body) {
|
|
33
|
-
return (0, isomorphic_unfetch_1.default)(url, {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: {
|
|
36
|
-
'Content-Type': 'application/json',
|
|
37
|
-
},
|
|
38
|
-
body: JSON.stringify(body),
|
|
39
|
-
})
|
|
40
|
-
.then((r) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const t = yield r.text();
|
|
42
|
-
try {
|
|
43
|
-
return JSON.parse(t);
|
|
44
|
-
}
|
|
45
|
-
catch (_a) {
|
|
46
|
-
throw new Error(`Invalid JSON RPC response: "${t}"`);
|
|
47
|
-
}
|
|
48
|
-
}))
|
|
49
|
-
.then((response) => {
|
|
50
|
-
const result = response === null || response === void 0 ? void 0 : response.result;
|
|
51
|
-
if (!result) {
|
|
52
|
-
throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
|
|
53
|
-
}
|
|
54
|
-
return response.result;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
exports.post = post;
|
|
58
|
-
/**
|
|
59
|
-
* Prepares data to be sent using the {@link post} function. Data is prepared per the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
|
|
60
|
-
*
|
|
61
|
-
* @param method the RPC method to be invoked
|
|
62
|
-
* @param params the parameters to be passed to the defined method
|
|
63
|
-
* @returns a POST method body matching the {@link https://en.wikipedia.org/wiki/JSON-RPC#Examples JSON RPC v2 spec}
|
|
64
|
-
* @example
|
|
65
|
-
* ```javascript
|
|
66
|
-
* buildRPCPostBody('eth_gasPrice', []);
|
|
67
|
-
* // { jsonrpc: '2.0', id: 1, method: 'eth_gasPrice', params: [] }
|
|
68
|
-
*
|
|
69
|
-
* buildRPCPostBody('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest']);
|
|
70
|
-
* // { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [ '0x4a986a6dCA6dbf99bC3d17F8D71aFb0d60e740f8', 'latest' ] }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
function buildRPCPostBody(method, params) {
|
|
74
|
-
return {
|
|
75
|
-
jsonrpc: '2.0',
|
|
76
|
-
id: 1,
|
|
77
|
-
method,
|
|
78
|
-
params,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
exports.buildRPCPostBody = buildRPCPostBody;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a hexadecimal string it's decimal equivalent.
|
|
3
|
-
* This is needed instead of parseInt because parseInt loses precision.
|
|
4
|
-
*
|
|
5
|
-
* @param hex the hex string to be converted to decimal
|
|
6
|
-
* @returns a decimal value equivalent to the hex string given
|
|
7
|
-
* @example
|
|
8
|
-
* ```javascript
|
|
9
|
-
* hexToDecimal('0x34');
|
|
10
|
-
* // 52
|
|
11
|
-
* ```
|
|
12
|
-
* @example
|
|
13
|
-
* ```javascript
|
|
14
|
-
* hexToDecimal('0x628608');
|
|
15
|
-
* // 6456840
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function hexToDecimal(hex: string): string;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hexToDecimal = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Converts a hexadecimal string it's decimal equivalent.
|
|
6
|
-
* This is needed instead of parseInt because parseInt loses precision.
|
|
7
|
-
*
|
|
8
|
-
* @param hex the hex string to be converted to decimal
|
|
9
|
-
* @returns a decimal value equivalent to the hex string given
|
|
10
|
-
* @example
|
|
11
|
-
* ```javascript
|
|
12
|
-
* hexToDecimal('0x34');
|
|
13
|
-
* // 52
|
|
14
|
-
* ```
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* hexToDecimal('0x628608');
|
|
18
|
-
* // 6456840
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
function hexToDecimal(hex) {
|
|
22
|
-
return BigInt(hex).toString();
|
|
23
|
-
}
|
|
24
|
-
exports.hexToDecimal = hexToDecimal;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
exports.prepareTransaction = void 0;
|
|
7
|
-
const big_js_1 = __importDefault(require("big.js"));
|
|
8
|
-
const tiny_big_1 = require("../../shared/tiny-big/tiny-big");
|
|
9
|
-
const bytes_1 = require("../../utils/bytes");
|
|
10
|
-
/**
|
|
11
|
-
* @param transaction
|
|
12
|
-
* @example
|
|
13
|
-
*/
|
|
14
|
-
function prepareTransaction(transaction) {
|
|
15
|
-
const preparedTransaction = Object.assign({}, transaction);
|
|
16
|
-
Object.keys(transaction).forEach((key) => {
|
|
17
|
-
switch (key) {
|
|
18
|
-
case 'gas':
|
|
19
|
-
case 'gasPrice':
|
|
20
|
-
case 'nonce':
|
|
21
|
-
case 'maxFeePerGas':
|
|
22
|
-
case 'maxPriorityFeePerGas':
|
|
23
|
-
case 'value': {
|
|
24
|
-
const value = transaction[key];
|
|
25
|
-
if (value instanceof tiny_big_1.TinyBig) {
|
|
26
|
-
preparedTransaction[key] = value.toHexString();
|
|
27
|
-
}
|
|
28
|
-
else if (value instanceof big_js_1.default) {
|
|
29
|
-
preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
|
|
30
|
-
}
|
|
31
|
-
else if (typeof transaction[key] === 'number')
|
|
32
|
-
preparedTransaction[key] =
|
|
33
|
-
'0x' + transaction[key].toString(16);
|
|
34
|
-
else
|
|
35
|
-
preparedTransaction[key] = transaction[key].toString();
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'data':
|
|
39
|
-
preparedTransaction[key] = (0, bytes_1.hexlify)(transaction[key]);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return preparedTransaction;
|
|
44
|
-
}
|
|
45
|
-
exports.prepareTransaction = prepareTransaction;
|
package/lib/cjs/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
-
import { ConstructorOptions, FallthroughProvider } from './providers/FallthroughProvider';
|
|
3
|
-
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
|
-
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
-
import { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
|
|
6
|
-
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
7
|
-
import { Filter, FilterByBlockHash } from './types/Filter.types';
|
|
8
|
-
import { Network } from './types/Network.types';
|
|
9
|
-
import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, RPCTransactionRequest, TransactionReceipt, TransactionRequest, TransactionResponse } from './types/Transaction.types';
|
|
10
|
-
import { computeAddress } from './utils/compute-address';
|
|
11
|
-
import { computePublicKey } from './utils/compute-public-key';
|
|
12
|
-
import { etherToGwei } from './utils/ether-to-gwei';
|
|
13
|
-
import { etherToWei } from './utils/ether-to-wei';
|
|
14
|
-
import { gweiToEther } from './utils/gwei-to-ether';
|
|
15
|
-
import { hashMessage } from './utils/hash-message';
|
|
16
|
-
import { isAddress } from './utils/is-address';
|
|
17
|
-
import { splitSignature } from './utils/split-signature';
|
|
18
|
-
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
19
|
-
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
20
|
-
import { weiToEther } from './utils/wei-to-ether';
|
|
21
|
-
export * from './utils/bytes';
|
|
22
|
-
export * from './utils/hash-message';
|
|
23
|
-
export * from './utils/keccak256';
|
|
24
|
-
export * from './utils/solidity-keccak256';
|
|
25
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, Filter, FilterByBlockHash, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
|
package/lib/cjs/index.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.BaseContract = exports.TinyBig = exports.Contract = exports.computePublicKey = exports.computeAddress = exports.toUtf8Bytes = exports.splitSignature = exports.hashMessage = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.FallthroughProvider = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
|
|
18
|
-
const Contract_1 = require("./classes/Contract");
|
|
19
|
-
Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return Contract_1.BaseContract; } });
|
|
20
|
-
Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
|
|
21
|
-
const FallthroughProvider_1 = require("./providers/FallthroughProvider");
|
|
22
|
-
Object.defineProperty(exports, "FallthroughProvider", { enumerable: true, get: function () { return FallthroughProvider_1.FallthroughProvider; } });
|
|
23
|
-
const JsonRpcProvider_1 = require("./providers/JsonRpcProvider");
|
|
24
|
-
Object.defineProperty(exports, "JsonRpcProvider", { enumerable: true, get: function () { return JsonRpcProvider_1.JsonRpcProvider; } });
|
|
25
|
-
Object.defineProperty(exports, "jsonRpcProvider", { enumerable: true, get: function () { return JsonRpcProvider_1.jsonRpcProvider; } });
|
|
26
|
-
const tiny_big_1 = require("./shared/tiny-big/tiny-big");
|
|
27
|
-
Object.defineProperty(exports, "tinyBig", { enumerable: true, get: function () { return tiny_big_1.tinyBig; } });
|
|
28
|
-
Object.defineProperty(exports, "TinyBig", { enumerable: true, get: function () { return tiny_big_1.TinyBig; } });
|
|
29
|
-
const compute_address_1 = require("./utils/compute-address");
|
|
30
|
-
Object.defineProperty(exports, "computeAddress", { enumerable: true, get: function () { return compute_address_1.computeAddress; } });
|
|
31
|
-
const compute_public_key_1 = require("./utils/compute-public-key");
|
|
32
|
-
Object.defineProperty(exports, "computePublicKey", { enumerable: true, get: function () { return compute_public_key_1.computePublicKey; } });
|
|
33
|
-
const ether_to_gwei_1 = require("./utils/ether-to-gwei");
|
|
34
|
-
Object.defineProperty(exports, "etherToGwei", { enumerable: true, get: function () { return ether_to_gwei_1.etherToGwei; } });
|
|
35
|
-
const ether_to_wei_1 = require("./utils/ether-to-wei");
|
|
36
|
-
Object.defineProperty(exports, "etherToWei", { enumerable: true, get: function () { return ether_to_wei_1.etherToWei; } });
|
|
37
|
-
const gwei_to_ether_1 = require("./utils/gwei-to-ether");
|
|
38
|
-
Object.defineProperty(exports, "gweiToEther", { enumerable: true, get: function () { return gwei_to_ether_1.gweiToEther; } });
|
|
39
|
-
const hash_message_1 = require("./utils/hash-message");
|
|
40
|
-
Object.defineProperty(exports, "hashMessage", { enumerable: true, get: function () { return hash_message_1.hashMessage; } });
|
|
41
|
-
const is_address_1 = require("./utils/is-address");
|
|
42
|
-
Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
|
|
43
|
-
const split_signature_1 = require("./utils/split-signature");
|
|
44
|
-
Object.defineProperty(exports, "splitSignature", { enumerable: true, get: function () { return split_signature_1.splitSignature; } });
|
|
45
|
-
const to_checksum_address_1 = require("./utils/to-checksum-address");
|
|
46
|
-
Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return to_checksum_address_1.toChecksumAddress; } });
|
|
47
|
-
const to_utf8_bytes_1 = require("./utils/to-utf8-bytes");
|
|
48
|
-
Object.defineProperty(exports, "toUtf8Bytes", { enumerable: true, get: function () { return to_utf8_bytes_1.toUtf8Bytes; } });
|
|
49
|
-
const wei_to_ether_1 = require("./utils/wei-to-ether");
|
|
50
|
-
Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });
|
|
51
|
-
__exportStar(require("./utils/bytes"), exports);
|
|
52
|
-
__exportStar(require("./utils/hash-message"), exports);
|
|
53
|
-
__exportStar(require("./utils/keccak256"), exports);
|
|
54
|
-
__exportStar(require("./utils/solidity-keccak256"), exports);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare class Logger {
|
|
2
|
-
private packageVersion;
|
|
3
|
-
constructor();
|
|
4
|
-
throwError(message: string, args: {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}): never;
|
|
7
|
-
throwArgumentError(message: string, arg: string, value: any): never;
|
|
8
|
-
checkSafeUint53(value: number, message?: string): void;
|
|
9
|
-
}
|
|
10
|
-
export declare const logger: Logger;
|
|
11
|
-
export {};
|
package/lib/cjs/logger/logger.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logger = void 0;
|
|
4
|
-
const package_version_1 = require("./package-version");
|
|
5
|
-
class Logger {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.packageVersion = package_version_1.version;
|
|
8
|
-
}
|
|
9
|
-
throwError(message, args) {
|
|
10
|
-
const argsLength = Object.keys(args).length;
|
|
11
|
-
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
12
|
-
}
|
|
13
|
-
throwArgumentError(message, arg, value) {
|
|
14
|
-
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
15
|
-
}
|
|
16
|
-
checkSafeUint53(value, message = 'value not safe') {
|
|
17
|
-
if (typeof value !== 'number') {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
21
|
-
this.throwError(message, {
|
|
22
|
-
operation: 'checkSafeInteger',
|
|
23
|
-
fault: 'out-of-safe-range',
|
|
24
|
-
value: value,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (value % 1) {
|
|
28
|
-
this.throwError(message, {
|
|
29
|
-
operation: 'checkSafeInteger',
|
|
30
|
-
fault: 'non-integer',
|
|
31
|
-
value: value,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.logger = new Logger();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const version = "0.5.9";
|