evm-contracts-tools 0.0.1

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/README.md ADDED
@@ -0,0 +1,101 @@
1
+ [comment]: <> (SPDX-License-Identifier: AGPL-3.0)
2
+
3
+ [comment]: <> (------------------------------------------------------)
4
+ [comment]: <> (Copyright © 2024, 2025, 2026 Pellegrino Prevete)
5
+ [comment]: <> (All rights reserved)
6
+ [comment]: <> (------------------------------------------------------)
7
+
8
+ [comment]: <> (This program is free software: you can redistribute)
9
+ [comment]: <> (it and/or modify it under the terms of the GNU Affero)
10
+ [comment]: <> (General Public License as published by the Free)
11
+ [comment]: <> (Software Foundation, either version 3 of the License.)
12
+
13
+ [comment]: <> (This program is distributed in the hope that it will be)
14
+ [comment]: <> (useful, but WITHOUT ANY WARRANTY; without even the)
15
+ [comment]: <> (implied warranty of MERCHANTABILITY or FITNESS FOR)
16
+ [comment]: <> (A PARTICULAR PURPOSE. See the)
17
+ [comment]: <> (See the GNU Affero General Public License for)
18
+ [comment]: <> (more details.)
19
+
20
+ [comment]: <> (You should have received a copy of the GNU Affero)
21
+ [comment]: <> (General Public License along with this program.)
22
+ [comment]: <> (If not, see <https://www.gnu.org/licenses/>.)
23
+
24
+ # EVM Smart Contracts Tools
25
+
26
+ A full-suite collection of useful JavaScript
27
+ programs and libraries to enable seamless development
28
+ of native computer applications designed to interact
29
+ with Ethereum Virtual Machine-compatible networks.
30
+
31
+ Particular focus has been put onto giving users the ability
32
+ to seamlessly call publicly verified smart contracts functions
33
+ same as they would do to retrieve information from any other standard
34
+ local program.
35
+
36
+ In order to do so, the `evm-contract-call` program obtains networks'
37
+ informations from the
38
+ [EVM Chains Info](
39
+ https://github.com/themartiancompany/evm-chains-info)
40
+ and automatically retrieves eventually missing smart
41
+ contracts artifacts from online sources using the
42
+ [EVM Contracts ABI Get](
43
+ https://github.com/themartiancompany/evm-contracts-abi-get)
44
+ utility.
45
+
46
+ The `evm-contract-call` program uses the
47
+ [Ethers](
48
+ https://github.com/ethers-io/ethers.js)
49
+ JavaScript library to
50
+ communicate with Ethereum Virtual Machine-compatible
51
+ blockchain networks and integrates natively with
52
+ and depends on the
53
+ [EVM Wallet](
54
+ https://github.com/themartiancompany/evm-wallet),
55
+ but it's also possible to directly provide seeds files.
56
+
57
+ The tools are a required software dependency for
58
+ [libEVM](
59
+ https://github.com/themartiancompany/libevm).
60
+
61
+ ## Installation
62
+
63
+ The tools in this source repo
64
+ can be installed from source using GNU Make.
65
+
66
+ ```bash
67
+ make \
68
+ install
69
+ ```
70
+
71
+ The collection has been officially published
72
+ on the the uncensorable
73
+ [Ur](
74
+ https://github.com/themartiancompany/ur)
75
+ user repository and application store as
76
+ `evm-contracts-tools`.
77
+ The source code is published on the
78
+ [Ethereum Virtual Machine File System](
79
+ https://github.com/themartiancompany/evmfs)
80
+ so it can't possibly be taken down.
81
+
82
+ To install it from there just type
83
+
84
+ ```bash
85
+ ur \
86
+ evm-contracts-tools
87
+ ```
88
+
89
+ A censorable HTTP Github mirror of the recipe published there,
90
+ containing a full list of the software dependencies needed to run the
91
+ tools is hosted on
92
+ [evm-contracts-tools-ur](
93
+ https://github.com/themartiancompany/evm-contracts-tools-ur).
94
+
95
+ Be aware the mirror could go offline any time as Github and more
96
+ in general all HTTP resources are inherently unstable and censorable.
97
+
98
+ ## License
99
+
100
+ This program is released by Pellegrino Prevete under the terms
101
+ of the GNU Affero General Public License version 3.
package/fs-worker.js ADDED
@@ -0,0 +1 @@
1
+ (()=>{var e={816(e,o,n){function t(){let e;return"undefined"==typeof window&&void 0!==n.g&&n.g.global===n.g&&"function"!=typeof n||(e=function(){let e;try{e=n(816)}catch(e){console.log(e);const o="Error importing the '@themartiancompany/opfs' module as 'opfs'. If you got this error while bundling a webpack for a project depending on this module double check its 'webpack.config.js' file or whether the 'opfs' module is listed in developer dependencies and install them.I'm sorry for this inconvenience but Node packagement system does not currently distinguish 'development' from 'build' dependencies.";throw console.error(o),e}return e}()),e}const r=t();e.exports=r,e.exports.getModule=function(e){let o;if(""==_module_name||"undefined"==typeof _module_name)o=t();else if("opfs"==_module_name)o=n(816);else{if("fs"!=_module_name){const e="Unknown file system module "+`'${_module_name}'.`.const;throw _error={msg:e},console.error(e),_error}o=n(816)}return o}},314(e,o,n){const t=n(816);_sync_agent=t.startSyncAgent,e.exports={_sync_agent},_sync_agent()}},o={};function n(t){var r=o[t];if(void 0!==r)return r.exports;var s=o[t]={exports:{}};return e[t](s,s.exports,n),s.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(314)})();
@@ -0,0 +1,438 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ /** ----------------------------------------------------------------------
6
+ * Copyright ©
7
+ * Pellegrino Prevete
8
+ * 2024, 2025, 2026
9
+ *
10
+ * All rights reserved
11
+ * ----------------------------------------------------------------------
12
+ *
13
+ * This program is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ */
26
+
27
+ const
28
+ _libcrash =
29
+ require(
30
+ '../libcrash-js/crash-js');
31
+ _cmdline_check =
32
+ _libcrash._cmdline_check;
33
+ _error_display =
34
+ _libcrash._error_display;
35
+ _msg_info =
36
+ _libcrash._msg_info;
37
+ _msg_error =
38
+ _libcrash._msg_error;
39
+ _printf =
40
+ _libcrash._printf;
41
+ const
42
+ { ethers } =
43
+ require(
44
+ "ethers");
45
+ _ethers =
46
+ ethers;
47
+ _wei_to_ether =
48
+ _ethers.formatEther;
49
+ const
50
+ _transaction_get_module =
51
+ require(
52
+ '../evm-transactions-tools/transaction-get');
53
+ _transaction_get =
54
+ _transaction_get_module._transaction_get;
55
+ const
56
+ _transaction_receipt_get_module =
57
+ require(
58
+ '../evm-transactions-tools/transaction-receipt-get');
59
+ _transaction_receipt_get =
60
+ _transaction_receipt_get_module._transaction_receipt_get;
61
+ const
62
+ _deployer_get_module =
63
+ require(
64
+ './deployer-get');
65
+ _deployer_get =
66
+ _deployer_get_module._deployer_get;
67
+
68
+ function
69
+ _global_variables() {
70
+ app_name =
71
+ "bytecode-creation-get";
72
+ wallet_seed =
73
+ "";
74
+ retries_max =
75
+ "";
76
+ api_key_path =
77
+ "";
78
+ chain_id =
79
+ "";
80
+ chain_name =
81
+ "";
82
+ target_network =
83
+ "";
84
+ contract_address =
85
+ "";
86
+ transaction_deployment =
87
+ "";
88
+ contract_bytecode_path =
89
+ "";
90
+ quiet =
91
+ "";
92
+ }
93
+
94
+ function
95
+ _delay(
96
+ _time) {
97
+ return new Promise(resolve => setTimeout(resolve, _time));
98
+ }
99
+
100
+ async function
101
+ _bytecode_creation_get(
102
+ _wallet_seed,
103
+ _retries_max,
104
+ _api_key_path,
105
+ _chain_id,
106
+ _chain_name,
107
+ _target_network,
108
+ _contract_address,
109
+ _transaction_deployment,
110
+ _bytecode_path) {
111
+ let
112
+ _attempt,
113
+ _bytecode,
114
+ _deployer,
115
+ _deployer_get_opts,
116
+ _transaction_get_opts,
117
+ _tx,
118
+ _wallet_password; //,
119
+ // _receipt,
120
+ // _transaction_receipt_get_opts,
121
+ if ( _bytecode_path == undefined ) {
122
+ _bytecode_path =
123
+ "";
124
+ }
125
+ if ( _contract_address == undefined ) {
126
+ _contract_address =
127
+ "";
128
+ }
129
+ _contract_address =
130
+ _contract_address.toLowerCase();
131
+ _attempt =
132
+ 1;
133
+ _wallet_password =
134
+ "";
135
+ _output_path =
136
+ "";
137
+ _transaction_get_opts = [
138
+ _retries_max,
139
+ _wallet_seed,
140
+ _wallet_password,
141
+ _chain_id,
142
+ _chain_name,
143
+ _target_network,
144
+ _api_key_path,
145
+ _output_path,
146
+ _transaction_deployment
147
+ ];
148
+ _transaction_receipt_get_opts = [
149
+ _retries_max,
150
+ _wallet_seed,
151
+ _wallet_password,
152
+ _chain_id,
153
+ _chain_name,
154
+ _target_network,
155
+ _api_key_path,
156
+ _output_path,
157
+ _transaction_deployment
158
+ ];
159
+ while ( _attempt <= _retries_max ) {
160
+ try {
161
+ _tx =
162
+ await _transaction_get.apply(
163
+ null,
164
+ _transaction_get_opts);
165
+ if ( _tx == undefined ) {
166
+ throw { "error": {
167
+ "message":
168
+ "Undefined transaction." } };
169
+ }
170
+ else if ( _tx != undefined ) {
171
+ _bytecode =
172
+ _tx.data;
173
+ _file_write(
174
+ _bytecode_path,
175
+ _bytecode);
176
+ }
177
+ break
178
+ } catch (
179
+ _error) {
180
+ _error_display(
181
+ _error);
182
+ // TODO: Do not break the loop
183
+ // only on network errors.
184
+ _attempt =
185
+ _attempt + 1;
186
+ _msg_error(
187
+ "Increasing retry and waiting 3 seconds.",
188
+ 0);
189
+ await _delay(
190
+ 3000);
191
+ }
192
+ }
193
+ if ( _attempt > _retries_max ) {
194
+ throw "Maximum number of retries reached.";
195
+ }
196
+ return _bytecode;
197
+ }
198
+
199
+ function
200
+ _config_show() {
201
+ let
202
+ _line,
203
+ _method_args,
204
+ _text;
205
+ _text =
206
+ [];
207
+ _text.push(
208
+ "bytecode-creation-get configuration:");
209
+ _text.push(
210
+ " Wallet seed: {wallet_seed}".replace(
211
+ "{wallet_seed}",
212
+ wallet_seed));
213
+ _text.push(
214
+ " Max retries: {retries_max}".replace(
215
+ "{retries_max}",
216
+ retries_max));
217
+ _text.push(
218
+ " API Key path: {api_key_path}".replace(
219
+ "{api_key_path}",
220
+ api_key_path));
221
+ _text.push(
222
+ " Chain ID: {chain_id}".replace(
223
+ "{chain_id}",
224
+ chain_id));
225
+ _text.push(
226
+ " Chain Name: {chain_name}".replace(
227
+ "{chain_name}",
228
+ chain_name));
229
+ _text.push(
230
+ " Target network: {target_network}".replace(
231
+ "{target_network}",
232
+ target_network));
233
+ _text.push(
234
+ " Contract address: {contract_address}".replace(
235
+ "{contract_address}",
236
+ contract_address));
237
+ _text.push(
238
+ " Deployment transaction: {transaction_deployment}".replace(
239
+ "{transaction_deployment}",
240
+ transaction_deployment));
241
+ for (_line of _text) {
242
+ _msg_info(
243
+ _line);
244
+ }
245
+ }
246
+
247
+ function
248
+ _usage(
249
+ _exit) {
250
+ let
251
+ _display_fun,
252
+ _line,
253
+ _text;
254
+ _text = [
255
+ "Returns the creation bytecode for a contract given its deployment transaction hash.",
256
+ "",
257
+ "Usage:",
258
+ " bytecode-creation-get",
259
+ " <quiet>",
260
+ " <wallet_seed>",
261
+ " <retries_max>",
262
+ " <api_key_path>",
263
+ " <chain_id>",
264
+ " <chain_name>",
265
+ " <target_network>",
266
+ " <contract_address>",
267
+ " <transaction_deployment>",
268
+ " <contract_bytecode_path>",
269
+ "",
270
+ "Args:",
271
+ " <quiet> Can be 'y' or 'n'",
272
+ " Default: y",
273
+ " <wallet_seed> Path of the file containing",
274
+ " the seed phrase.",
275
+ " <retries_max> Maximum number of retries before",
276
+ " failing.",
277
+ " <api_key_path> Path of the API key for the",
278
+ " contract ABI provider service",
279
+ " <chain_id> Chain ID for the network.",
280
+ " <chain_name> Name for the network.",
281
+ " <target_network> Network on which the contract",
282
+ " resides.",
283
+ " <contract_address> Address of the contract",
284
+ " <transaction_deployment> Contract deployment transaction.",
285
+ " <contract_bytecode_path> Where to save contract bytecode.",
286
+ "",
287
+ " Options:",
288
+ " -h This help."
289
+ ];
290
+ for (_line of _text) {
291
+ _msg_info(
292
+ _line);
293
+ }
294
+ process.exit(
295
+ _exit);
296
+ }
297
+
298
+ function
299
+ _overrides_set() {
300
+ if ( retries_max == "" ) {
301
+ retries_max =
302
+ 10;
303
+ }
304
+ }
305
+
306
+ function
307
+ _cmdline_parse() {
308
+ quiet =
309
+ "y";
310
+ process.argv.forEach(
311
+ function (
312
+ _value,
313
+ _index,
314
+ _array) {
315
+ if ( _index == 2 ) {
316
+ quiet =
317
+ _value;
318
+ }
319
+ if ( _index == 3 ) {
320
+ wallet_seed =
321
+ _value;
322
+ }
323
+ if ( _index == 4 ) {
324
+ retries_max =
325
+ _value;
326
+ }
327
+ if ( _index == 5 ) {
328
+ api_key_path =
329
+ _value;
330
+ }
331
+ if ( _index == 6 ) {
332
+ chain_id =
333
+ _value;
334
+ }
335
+ if ( _index == 7 ) {
336
+ chain_name =
337
+ _value;
338
+ }
339
+ if ( _index == 8 ) {
340
+ target_network =
341
+ _value;
342
+ }
343
+ if ( _index == 9 ) {
344
+ contract_address =
345
+ _value;
346
+ }
347
+ if ( _index == 10 ) {
348
+ transaction_deployment =
349
+ _value;
350
+ }
351
+ if ( _index == 11 ) {
352
+ contract_bytecode_path =
353
+ _value;
354
+ }
355
+ if ( _value == "-h" ||
356
+ _value == "--help" ) {
357
+ quiet =
358
+ "n";
359
+ _usage(
360
+ 0);
361
+ }
362
+ }
363
+ );
364
+ if ( transaction_deployment == "" ) {
365
+ _msg_error(
366
+ "No deployment transaction specified.",
367
+ 0);
368
+ quiet =
369
+ "n";
370
+ _usage(
371
+ 1);
372
+ }
373
+ if ( contract_bytecode_path == "" ) {
374
+ _msg_error(
375
+ "No contract bytecode path specified.",
376
+ 0);
377
+ quiet =
378
+ "n";
379
+ _usage(
380
+ 1);
381
+ }
382
+ }
383
+ async function
384
+ _bytecode_creation_get_cmdline(
385
+ _app_opts) {
386
+ let
387
+ _bytecode,
388
+ _msg;
389
+ try {
390
+ _bytecode =
391
+ await _bytecode_creation_get.apply(
392
+ null,
393
+ _app_opts);
394
+ if ( _bytecode != undefined ) {
395
+ _msg_info(
396
+ `Bytecode has length '${_bytecode.length}'`);
397
+ // _printf(
398
+ // _bytecode.toString());
399
+ }
400
+ else {
401
+ _msg =
402
+ "It has not been possible to retrieve " +
403
+ "the bytecode from the transaction.";
404
+ throw _msg;
405
+ }
406
+ } catch (
407
+ _error) {
408
+ _msg_error(
409
+ _error,
410
+ 1);
411
+ }
412
+ }
413
+
414
+ if ( _cmdline_check(
415
+ "bytecode-creation-get") ) {
416
+ _global_variables();
417
+ _cmdline_parse();
418
+ _overrides_set();
419
+ _config_show();
420
+ app_opts = [
421
+ wallet_seed,
422
+ retries_max,
423
+ api_key_path,
424
+ chain_id,
425
+ chain_name,
426
+ target_network,
427
+ contract_address,
428
+ transaction_deployment,
429
+ contract_bytecode_path
430
+ ];
431
+ _bytecode_creation_get_cmdline(
432
+ app_opts);
433
+ }
434
+
435
+ module.exports = {
436
+ _bytecode_creation_get:
437
+ _bytecode_creation_get
438
+ };