-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevm-cli
More file actions
4064 lines (3610 loc) · 168 KB
/
evm-cli
File metadata and controls
4064 lines (3610 loc) · 168 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
APP_ID="HERE YOUR APP ID"
API_KEY="HERE YOUR API KEY"
email="HERE YOUR EMAIL" # ONLY REQUIRED TO USE CUSTODIED WALLETS FUNCTIONS
cat << banner
░░░░░░░██╗░█████╗░████████████████╗██╗░░░░░░███╗░░██╗ ░█▀▀█ ▒█▀▀█ ▀█▀ █▀▀
██╗░░░██╔╝██╔══██╗╚══██╔═════██╔══╝██║░░░██╗████╗░██║ ▒█▄▄█ ▒█▄▄█ ▒█░ ▀▀█
╚██╗░██╔╝░██║░░██║░░░██║░░░░░██║░░░██║░░░██║██╔██╗██║ ▒█░▒█ ▒█░░░ ▄█▄ ▀▀▀
░╚████╔╝░░██║░░██║░░░██║░░░░░██║░░░██║░░░██║██║╚████║
░░╚██╔╝░░░╚█████╔╝░░░██║░░░░░██║░░░╚██████╔╝██║░╚███║ EVM CLI v1.0.1
░░░╚═╝░░░░░╚════╝░░░░╚═╝░░░░░╚═╝░░░░╚═════╝░╚═╝░░╚══╝ Scripted by @borj404
banner
help(){ # HELP MENU
cat << menu
Type the function and fill in the required parameters
Press ⏎ after each prompt to continue
To undo the previous entry type << , .. , !undo , !back or !del
"All parameter inputs are handled dynamically, so you must NOT quote strings, even in arrays"
(Optional parameters are indicated in parentheses)
All token amounts must be entered in standard units, not in wei as stated in the docs
For detailed information about this APIs, visit: https://docs.vottun.io/
❮❮❮ AVAILABLE FUNCTIONS ❯❯❯
IPFS
~$ up_file ―▸ Upload a binary file to IPFS
~$ up_folder ―▸ Upload a folder or zip with multiple files to IPFS
~$ up_metadata ―▸ Upload a JSON file to IPFS
ERC-20
~$ deploy20 ―▸ Deploy an ERC-20 smart contract
~$ transfer20 ―▸ Transfer tokens to an address
~$ transfer_from ―▸ Transfer tokens from a sender's account to a receiver's address
~$ incr_allowance ―▸ Grant a spender account the right to manage a specified amount of tokens
~$ decr_allowance ―▸ Revoke a spender account the right to manage a specified amount of tokens
~$ allowance ―▸ Display the total amount of tokens the owner has authorized the spender to transact
~$ name ―▸ Display the name of a smart contract
~$ symbol ―▸ Display the symbol of a smart contract
~$ supply ―▸ Display the total supply of tokens created in an ERC-20 smart contract
~$ decimals ―▸ Display the decimals used for tokens in an ERC-20 smart contract
~$ balance20 ―▸ Display the balance of tokens held by an address
ERC-721
~$ deploy721 ―▸ Deploy an ERC-721 smart contract
~$ mint721 ―▸ Mint an NFT with the provided metadata to the specified address
~$ transfer721 ―▸ Transfer an NFT to an address
~$ balance721 ―▸ Display the NFT balance of an address in the specified smart contract and network
~$ uri721 ―▸ Display the metadata URI for an NFT in the specified contract
~$ owner ―▸ Display the address of the owner of an NFT
ERC-1155
~$ deploy1155 ―▸ Deploy an ERC-1155 smart contract
~$ mint1155 ―▸ Mint the specified amount of copies of an NFT with the provided metadata to the given address
~$ mint_batch ―▸ Mint the specified amount of copies of multiple NFTs with the provided metadata to the given address
~$ transfer1155 ―▸ Transfer the specified amount of copies of an NFT to the given address
~$ transfer_batch ―▸ Transfer the specified amount of copies of multiple NFTs to the given address
~$ balance1155 ―▸ Display the amount of an NFT for the given address and smart contract on a specified network
~$ uri1155 ―▸ Display the URI of the metadata for the NFT from the given contract
POAP
~$ deployPOAP ―▸ Deploy a POAP smart contract and mint the tokens
~$ transferPOAP ―▸ Transfer an NFT to the given address
~$ balancePOAP ―▸ Display the amount of an NFT for the given address and smart contract on a specified network
~$ uriPOAP ―▸ Display the URI of the metadata for the NFT from the given contract
CUSTODIED WALLETS
~$ new_wallet ―▸ Generates a one-time-use hash and retrieves the URL to create a new custodied wallet
~$ get_address ―▸ Retrieve the wallet's public address (for the 1st account) for one of our users
~$ get_wallets ―▸ Retrieve all custodied wallets created for you
~$ otp ―▸ Request a one-time email OTP to sign a mutable transaction within the next 120 seconds
~$ send_tx ―▸ Call any public function implemented in a smart contract and modify its state (for view or pure functions, use "query")
~$ send_nat ―▸ Transfer native assets from your custodied wallet
WEB3 CORE
~$ deploy ―▸ Deploy a smart contract on the blockchain of your choice
~$ call_function ―▸ Call any public function implemented in a smart contract and modify its state (for view or pure functions, use "query")
~$ query ―▸ Call any public function implemented in a smart contract without change its state (view or pure functions)
~$ get_nets ―▸ Request the list of available blockchain networks
~$ get_specs ―▸ Request the list of available contract specifications
~$ query_address ―▸ Query an address to determine if it is a smart contract
~$ query_tx ―▸ Query transaction information from the blockchain
~$ query_status ―▸ Query the status of a transaction
~$ query_ref ―▸ Query the status of a transaction using the customer reference
~$ query_gas ―▸ Query the current gas price for a specified blockchain network
~$ query_nat ―▸ Query the balance of native currency for a specified address
~$ gas_deploy ―▸ Estimate the gas required for a smart contract deployment
~$ gas_tx ―▸ Estimate the gas required to call any public function implemented in a smart contract
~$ gas_nat ―▸ Estimate the gas required to transfer native assets
menu
}
auth=("--header" "x-application-vkn: $APP_ID" "--header" "Authorization: Bearer $API_KEY")
ct_json="--header 'Content-Type: application/json'"
_check_input() {
local prompt="$1" var_name="$2" undo_step="$3" required="$4" validate_cmd="$5" empty_err="$6" format_err="$7"
while true; do
read -e -p "$prompt" input
if [[ "$input" =~ ^(<<|\.\.|!undo|!back|!del)$ ]]; then
if [[ "$undo_step" -ne -1 ]]; then
return 99
else
echo "Nothing to undo!"
continue
fi
fi
if [[ "$required" == "true" && -z "$input" ]]; then
echo "Error: $empty_err"
elif [ -n "$input" ] && ! eval "$validate_cmd"; then
echo "Error: $format_err"
else
eval "$var_name=\"\$input\""
return 0
fi
done
}
_step_back() {
[[ $? -eq 99 ]] && step=$((step - 1))
}
_parse_params() {
local input="$1"
[[ "$input" =~ ^[0-9]+$ && (${#input} -gt 31 || "$input" =~ (999999999999999|000000000000000)) ]] && { echo "\"$input\""; return; }
if [[ "$input" =~ ^\[.*\]$ ]]; then
local result="[" trimmed buffer="" depth=0 first=true
trimmed=$(echo "$input" | sed -E 's/^\[|\]$//g')
while IFS= read -r -n1 char; do
[[ "$char" == "[" ]] && ((depth++))
[[ "$char" == "]" ]] && ((depth--))
if [[ "$char" == "," && $depth -eq 0 ]]; then
if [ -n "$buffer" ]; then
$first || result+=", "
result+="$(_parse_params "$buffer")"
buffer=""
first=false
fi
else
buffer+="$char"
fi
done <<< "$trimmed"
[[ -n "$buffer" ]] && {
$first || result+=", "
result+="$(_parse_params "$buffer")"
}
result+="]"
echo "$result"
return
fi
[[ "$input" =~ ^\"[0-9]+\"$|^\"(true|false)\"$|^[0-9]+$|^(true|false)$ ]] && echo "$input" || echo "\"$input\""
}
_display_params() {
local -n params_ref=$1
[[ ${#params_ref[@]} -gt 0 ]] && {
echo "Params: ["
local total=${#params_ref[@]}
for ((i=0; i<total; i++)); do
param="${params_ref[$i]}"
if [[ "$param" =~ ^\[.*\]$ ]]; then
echo -n " ["
local first=true
while IFS= read -r item; do
$first || echo -n ", "; first=false
[[ "$item" =~ ^[0-9]+$|^(true|false)$ ]] && echo -n "$item" || echo -n "\"${item//\"/}\""
done <<< "$(echo "$param" | sed -E 's/^\[|\]$//g' | tr ',' '\n')"
echo -n "]"
elif [[ "$param" =~ ^[0-9]+$ && (${#param} -gt 31 || "$param" =~ (999999999999999|000000000000000)) ]]; then
echo -n " $param"
elif [[ "$param" =~ ^[0-9]+$|^(true|false)$|^\".*\"$ ]]; then
echo -n " $param"
else
echo -n " \"$param\""
fi
[[ $i -lt $((total-1)) ]] && echo "," || echo ""
done
echo "]"
}
}
_confirmation() {
while true; do
read -e -p "Do you want to proceed with these parameters? (Y/N): " confirm
[[ "$confirm" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && return 99
case "$confirm" in
[Yy]*)
echo
return 0
;;
[Nn]*)
echo
echo "Process cancelled."
return 1
;;
*)
echo "Invalid input! Try again..."
;;
esac
done
}
_network_details() {
local network=$1 net_name currency url_address url_tx
currency="ETH"
case $network in
# TESTNET
11155111)
net_name="Ethereum Sepolia"
url_address="https://sepolia.etherscan.io/address/"
url_tx="https://sepolia.etherscan.io/tx/"
;;
421614)
net_name="Arbitrum Sepolia"
url_address="https://sepolia.arbiscan.io/address/"
url_tx="https://sepolia.arbiscan.io/tx/"
;;
84532)
net_name="Base Sepolia"
url_address="https://sepolia.basescan.org/address/"
url_tx="https://sepolia.basescan.org/tx/"
;;
97)
net_name="BNB Smart Chain Testnet"
currency="BNB"
url_address="https://testnet.bscscan.com/address/"
url_tx="https://testnet.bscscan.com/tx/"
;;
80002)
net_name="Polygon Amoy"
currency="POL"
url_address="https://amoy.polygonscan.com/address/"
url_tx="https://amoy.polygonscan.com/tx/"
;;
43113)
net_name="Avalanche Fuji"
currency="AVAX"
url_address="https://43113.testnet.snowtrace.io/address/"
url_tx="https://43113.testnet.snowtrace.io/tx/"
;;
31)
net_name="Rootstock Testnet"
currency="RBTC"
url_address="https://explorer.testnet.rootstock.io/address/"
url_tx="https://explorer.testnet.rootstock.io/tx/"
;;
51)
net_name="XDC Apothem Network"
currency="TXDC"
url_address="https://explorer.apothem.network/address/"
url_tx="https://explorer.apothem.network/tx/"
;;
# MAINNET
1)
net_name="Ethereum"
url_address="https://etherscan.io/address/"
url_tx="https://etherscan.io/tx/"
;;
42161)
net_name="Arbitrum One"
url_address="https://arbiscan.io/address/"
url_tx="https://arbiscan.io/tx/"
;;
42170)
net_name="Arbitrum Nova"
url_address="https://nova.arbiscan.io/address/"
url_tx="https://nova.arbiscan.io/tx/"
;;
8453)
net_name="Base"
url_address="https://basescan.org/address/"
url_tx="https://basescan.org/tx/"
;;
56)
net_name="BNB Smart Chain"
currency="BNB"
url_address="https://bscscan.com/address/"
url_tx="https://bscscan.com/tx/"
;;
137)
net_name="Polygon"
currency="POL"
url_address="https://polygonscan.com/address/"
url_tx="https://polygonscan.com/tx/"
;;
43114)
net_name="Avalanche"
currency="AVAX"
url_address="https://avascan.info/blockchain/c/address/"
url_tx="https://avascan.info/blockchain/c/tx/"
;;
30)
net_name="Rootstock"
currency="RBTC"
url_address="https://explorer.rootstock.io/address/"
url_tx="https://explorer.rootstock.io/tx/"
;;
50)
net_name="XDC Network"
currency="XDC"
url_address="https://xdc.network/address/"
url_tx="https://xdc.network/txs/"
;;
*)
net_name="Network name not defined :("
currency=""
url_address=""
url_tx=""
esac
echo "$net_name|$currency|$url_address|$url_tx"
}
_loading() {
local duration=0.5 bar_length=24
for ((i = 0; i <= bar_length; i++)); do
local progress=$(for ((j = 0; j < i; j++)); do printf "\033[44m \033[0m "; done)
local empty=$(for ((j = i; j < bar_length; j++)); do printf " "; done)
printf "\r%s%s" "$progress" "$empty"
sleep $(bc <<< "$duration / $bar_length")
done
echo
}
############
### IPFS ###
############
up_file(){ # UPLOAD A BINARY FILE TO IPFS
local filename filePath step=1
echo "Please enter the following parameters to upload the file to IPFS:"
echo -e "filename filePath\n"
while true; do
case $step in
1)
_check_input "Filename: " filename -1 "true" 'true' "Filename is required." ""
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "File Path: " filePath 1 "true" 'true' "File Path is required." ""
_step_back && continue
[ -f "$filePath" ] || { echo "Error: File doesn't exist at the specified path."; continue; }
step=3
;;
3)
echo -e "\nYou've entered the following parameters:"
echo "Filename: $filename"
echo -e "File Path: $filePath\n"
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local response=$(curl --silent --location --request POST \
'https://ipfsapi-v2.vottun.tech/ipfs/v2/file/upload' "${auth[@]}" \
--header 'Content-Type: multipart/form-data' \
--form 'filename="'"$filename"'"' \
--form 'file=@"'"$filePath"'"')
_loading
echo -e "\nServer response:\n$response"
}
up_folder(){ # UPLOAD A FOLDER OR ZIP WITH MULTIPLE FILES TO IPFS
local filePath tempZip
echo -e "Please enter the file path to upload the folder or zip to IPFS:\n"
while true; do
_check_input "File Path: " filePath -1 "true" 'true' "File Path is required." ""
[[ $? -eq 99 ]] && continue
if [ -d "$filePath" ]; then
tempZip="${filePath%/}.zip"
echo "Zipping into $tempZip..."
zip -r "$tempZip" "$filePath" || { echo "Error: Failed to create zip file."; return 1; }
filePath="$tempZip"
elif [ ! -f "$filePath" ]; then
echo "Error: File or directory doesn't exist."; continue
fi
echo -e "\nYou've entered the following parameter:\nFile Path: $filePath\n"
_confirmation && break || [[ $? -eq 99 ]] || return 1
done
local response=$(curl --silent --location --request POST \
'https://ipfsapi-v2.vottun.tech/ipfs/v2/upload/zip' "${auth[@]}" \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"'"$filePath"'"')
_loading
echo -e "\nServer response:\n$response"
[[ -n "$tempZip" && -f "$tempZip" ]] && rm -f "$tempZip"
}
up_metadata(){ # UPLOAD A JSON FILE TO IPFS
local name image description edition attributes=() data_names=() data_values=() step=1
echo "Please enter the following parameters to upload the metadata to IPFS:"
echo -e "name image description (edition) (attributes) (data)\n"
while true; do
case $step in
1)
_check_input "Name: " name -1 "true" 'true' "Name is required." ""
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "Image: " image 1 "true" '[[ ${#input} -ge 46 ]]' \
"Image is required." "Image URL must be longer."
_step_back && continue
step=3
;;
3)
_check_input "Description: " description 2 "true" 'true' "Description is required." ""
_step_back && continue
step=4
;;
4)
_check_input "Edition (optional): " edition 3 "false" 'true' "" ""
_step_back && continue
step=5
;;
5)
attributes=()
local attr_count=1
while true; do
read -e -p "Add attributes? (Y/N): " add_attributes
[[ "$add_attributes" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && step=4 && break
[[ -z "$add_attributes" ]] && step=6 && break
[[ "$add_attributes" =~ ^[Yy]$ ]] && {
while true; do
read -e -p "Trait type for attribute $attr_count: " trait_type
[[ -z "$trait_type" ]] && echo "Trait type is required!" && continue
[[ "$trait_type" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && {
(( attr_count > 1 )) && attributes=("${attributes[@]:0:${#attributes[@]}-1}") && ((attr_count--)) && continue
break
}
while true; do
read -e -p "Value for trait '$trait_type': " value
[[ -z "$value" ]] && echo "Value is required for the trait!" && continue
[[ "$value" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && {
(( attr_count > 1 )) && attributes=("${attributes[@]:0:${#attributes[@]}-1}") && ((attr_count--)) && continue 2
}
[[ "$value" =~ ^[0-9]+$ ]] && attributes+=("{\"trait_type\": \"$trait_type\", \"value\": $value}") || attributes+=("{\"trait_type\": \"$trait_type\", \"value\": \"$value\"}")
((attr_count++))
break
done
while true; do
read -e -p "Add another attribute? (Y/N): " add_more
[[ "$add_more" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && {
(( attr_count > 1 )) && attributes=("${attributes[@]:0:${#attributes[@]}-1}") && ((attr_count--)) && continue 2
break 2
}
[[ -z "$add_more" || "$add_more" =~ ^[Nn]$ ]] && step=6 && break 3
[[ "$add_more" =~ ^[Yy]$ ]] && break
echo "Invalid input. Please enter 'Y' or 'N'."
done
done
}
[[ "$add_attributes" =~ ^[Nn]$ ]] && step=6 && break
echo "Invalid input. Please enter 'Y' or 'N'."
done
;;
6)
data_names=() data_values=()
local data_count=1
while true; do
read -e -p "Add custom data? (Y/N): " add_data
[[ "$add_data" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && step=5 && break
[[ -z "$add_data" ]] && step=7 && break
[[ "$add_data" =~ ^[Yy]$ ]] && {
while true; do
read -e -p "Data name $data_count: " dataName
[[ -z "$dataName" ]] && echo "Data name is required!" && continue
[[ "$dataName" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && {
(( data_count > 1 )) && {
data_names=("${data_names[@]:0:${#data_names[@]}-1}")
data_values=("${data_values[@]:0:${#data_values[@]}-1}")
((data_count--))
continue
}
break
}
while true; do
read -e -p "Value for '$dataName': " value
[[ -z "$value" ]] && echo "Value is required for the data name!" && continue
[[ "$value" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && {
(( data_count > 1 )) && {
data_names=("${data_names[@]:0:${#data_names[@]}-1}")
data_values=("${data_values[@]:0:${#data_values[@]}-1}")
((data_count--))
}
continue 2
}
data_names+=("$dataName")
data_values+=("$value")
((data_count++))
break
done
while true; do
read -e -p "Add another custom data field? (Y/N): " add_more
[[ "$add_more" =~ ^(<<|\.\.|!undo|!back|!del)$ ]] && {
(( data_count > 1 )) && {
data_names=("${data_names[@]:0:${#data_names[@]}-1}")
data_values=("${data_values[@]:0:${#data_values[@]}-1}")
((data_count--))
continue 2
}
echo && break 2
}
[[ -z "$add_more" || "$add_more" =~ ^[Nn]$ ]] && step=7 && break 3
[[ "$add_more" =~ ^[Yy]$ ]] && break
echo "Invalid input. Please enter 'Y' or 'N'."
done
done
}
[[ "$add_data" =~ ^[Nn]$ ]] && step=7 && break
echo "Invalid input. Please enter 'Y' or 'N'."
done
;;
7)
echo -e "\nYou've entered the following parameters:"
echo "Name: $name"
echo "Image: $image"
echo "Description: $description"
[ -n "$edition" ] && echo "Edition: $edition"
[[ ${#attributes[@]} -gt 0 ]] && echo "Attributes: ${attributes[*]}"
if [[ ${#data_names[@]} -gt 0 ]]; then
local data_display="{"
for ((i=0; i<${#data_names[@]}; i++)); do
if [[ "${data_values[i]}" =~ ^[0-9]+$ ]]; then
data_display+="\"${data_names[i]}\": ${data_values[i]}"
else
data_display+="\"${data_names[i]}\": \"${data_values[i]}\""
fi
[[ $i -lt $(( ${#data_names[@]} - 1 )) ]] && data_display+=", "
done
data_display+="}"
echo "Data: $data_display"
fi
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local attributes_json=$(printf '%s\n' "${attributes[@]}" | jq -s '.')
local data_json=$(jq -n '{data: {}}')
for ((i=0; i<${#data_names[@]}; i++)); do
if [[ "${data_values[i]}" =~ ^[0-9]+$ ]]; then
data_json=$(echo "$data_json" | jq --arg key "${data_names[i]}" --argjson val "${data_values[i]}" '.data[$key] = $val')
else
data_json=$(echo "$data_json" | jq --arg key "${data_names[i]}" --arg val "${data_values[i]}" '.data[$key] = $val')
fi
done
local data=$(jq -n \
--arg name "$name" \
--arg image "$image" \
--arg description "$description" \
--arg edition "$edition" \
--argjson attributes "$attributes_json" \
--argjson data "$data_json" \
'{
name: $name,
image: $image,
description: $description
} +
(if $edition != "" then {edition: $edition} else {} end) +
(if $attributes != [] then {attributes: $attributes} else {} end) +
$data')
local response=$(curl --silent --location --request POST 'https://ipfsapi-v2.vottun.tech/ipfs/v2/file/metadata' \
"${auth[@]}" $ct_json --data-raw "$data")
_loading
echo -e "\nServer response:\n$response"
}
##############
### ERC-20 ###
##############
deploy20() { # DEPLOY AN ERC-20 SMART CONTRACT
local name symbol alias initialSupply network gasLimit step=1
echo "Please enter the following parameters to deploy the ERC-20 contract:"
echo -e "name symbol alias initialSupply network (gasLimit)\n"
while true; do
case $step in
1)
_check_input "Name: " name -1 "true" 'true' "Name is required." ""
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "Symbol: " symbol 1 "true" 'true' "Symbol is required." ""
_step_back && continue
step=3
;;
3)
_check_input "Alias: " alias 2 "true" 'true' "Alias is required." ""
_step_back && continue
step=4
;;
4)
_check_input "Initial Supply: " initialSupply 3 "true" '[[ "$input" =~ ^[0-9]*\.?[0-9]+$ ]]' \
"Initial Supply is required." "Initial Supply must be a valid integer or decimal."
_step_back && continue
initialSupply_wei=$(echo "$initialSupply * 10^18 / 1" | bc)
step=5
;;
5)
_check_input "Network: " network 4 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Network is required." "Network must be an integer number."
_step_back && continue
step=6
;;
6)
_check_input "Gas Limit (optional): " gasLimit 5 "false" '[[ "$input" =~ ^[0-9]+$ ]]' \
"" "Gas Limit must be an integer number if provided."
_step_back && continue
step=7
;;
7)
IFS='|' read -r net_name currency url_address url_tx <<< "$(_network_details "$network")"
echo -e "\nYou've entered the following parameters:"
echo "Name: $name"
echo "Symbol: $symbol"
echo "Alias: $alias"
echo "Initial Supply: $initialSupply"
echo "Network: $net_name"
[ -n "$gasLimit" ] && echo "Gas Limit: $gasLimit"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--arg name "$name" \
--arg symbol "$symbol" \
--arg alias "$alias" \
--argjson network "$network" \
--arg gasLimit "$gasLimit" \
'{
name: $name,
symbol: $symbol,
alias: $alias,
network: $network
} +
(if $gasLimit != "" then {gasLimit: ($gasLimit | tonumber)} else {} end)')
data=$(echo "$data" | sed "s/^{/{\"initialSupply\":$initialSupply_wei, /")
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/erc/v1/erc20/deploy' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
if [[ -n "$txHash" ]]; then
contractAddress=$(echo "$response" | jq -r '.contractAddress // empty')
echo -e "\nDeploying the ERC-20 contract on $net_name..."
_loading
[[ -n "$url_tx" ]] && echo -e "\nBlock explorer URLs:\n$url_address$contractAddress\n$url_tx$txHash"
fi
}
transfer20(){ # TRANSFER TOKENS TO AN ADDRESS
local contractAddress recipient network amount gasLimit step=1
echo "Please enter the following parameters to make the token transfers:"
echo -e "contractAddress recipient network amount (gasLimit)\n"
while true; do
case $step in
1)
_check_input "Contract Address: " contractAddress -1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Contract Address is required." "Contract Address must start with '0x' and be 42 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "Recipient: " recipient 1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Recipient is required." "Recipient must start with '0x' and be 42 characters long."
_step_back && continue
step=3
;;
3)
_check_input "Network: " network 2 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Network is required." "Network must be an integer number."
_step_back && continue
step=4
;;
4)
_check_input "Amount: " amount 3 "true" '[[ "$input" =~ ^[0-9]*\.?[0-9]+$ ]]' \
"Amount is required." "Amount must be a valid integer or decimal."
_step_back && continue
amount_wei=$(echo "$amount * 10^18 / 1" | bc)
step=5
;;
5)
_check_input "Gas Limit (optional): " gasLimit 4 "false" '[[ "$input" =~ ^[0-9]+$ ]]' \
"" "Gas Limit must be an integer number if provided."
_step_back && continue
step=6
;;
6)
IFS='|' read -r net_name currency url_address url_tx <<< "$(_network_details "$network")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Address: $contractAddress"
echo "Recipient: $recipient"
echo "Network: $net_name"
echo "Amount: $amount"
[ -n "$gasLimit" ] && echo "Gas Limit: $gasLimit"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--arg contractAddress "$contractAddress" \
--arg recipient "$recipient" \
--argjson network "$network" \
--arg gasLimit "$gasLimit" \
'{
contractAddress: $contractAddress,
recipient: $recipient,
network: $network
} +
(if $gasLimit != "" then {gasLimit: $gasLimit | tonumber} else {} end)')
data=$(echo "$data" | sed "s/^{/{\"amount\":$amount_wei, /")
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/erc/v1/erc20/transfer' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
if [[ -n "$txHash" ]]; then
local symbol_query=$(curl --silent --location --request GET 'https://api.vottun.tech/erc/v1/erc20/symbol' \
"${auth[@]}" $ct_json \
--data-raw '{
"contractAddress": "'"$contractAddress"'",
"network": '$network'
}')
symbol=$(echo "$symbol_query" | jq -r '.symbol // empty')
echo -e "\nSending: $amount $symbol\nto: $recipient"
_loading
[[ -n "$url_tx" ]] && echo -e "\nBlock explorer URL:\n$url_tx$txHash"
fi
}
transfer_from(){ # TRANSFER TOKENS FROM A SENDER'S ACCOUNT TO A RECEIVER'S ADDRESS
local contractAddress sender recipient network amount gasLimit step=1
echo "Please enter the following parameters to make the token transfers:"
echo -e "contractAddress sender recipient network amount (gasLimit)\n"
while true; do
case $step in
1)
_check_input "Contract Address: " contractAddress -1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Contract Address is required." "Contract Address must start with '0x' and be 42 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "Sender: " sender 1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Sender is required." "Sender must start with '0x' and be 42 characters long."
_step_back && continue
step=3
;;
3)
_check_input "Recipient: " recipient 2 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Recipient is required." "Recipient must start with '0x' and be 42 characters long."
_step_back && continue
step=4
;;
4)
_check_input "Network: " network 3 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Network is required." "Network must be an integer number."
_step_back && continue
step=5
;;
5)
_check_input "Amount: " amount 4 "true" '[[ "$input" =~ ^[0-9]*\.?[0-9]+$ ]]' \
"Amount is required." "Amount must be a valid integer or decimal."
_step_back && continue
amount_wei=$(echo "$amount * 10^18 / 1" | bc)
step=6
;;
6)
_check_input "Gas Limit (optional): " gasLimit 5 "false" '[[ "$input" =~ ^[0-9]+$ ]]' \
"" "Gas Limit must be an integer number if provided."
_step_back && continue
step=7
;;
7)
IFS='|' read -r net_name currency url_address url_tx <<< "$(_network_details "$network")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Address: $contractAddress"
echo "Sender: $sender"
echo "Recipient: $recipient"
echo "Network: $net_name"
echo "Amount: $amount"
[ -n "$gasLimit" ] && echo "Gas Limit: $gasLimit"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data=$(jq -n \
--arg contractAddress "$contractAddress" \
--arg recipient "$recipient" \
--arg sender "$sender" \
--argjson network "$network" \
--arg gasLimit "$gasLimit" \
'{
contractAddress: $contractAddress,
recipient: $recipient,
sender: $sender,
network: $network
} +
(if $gasLimit != "" then {gasLimit: $gasLimit | tonumber} else {} end)')
data=$(echo "$data" | sed "s/^{/{\"amount\":$amount_wei, /")
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/erc/v1/erc20/transferFrom' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
if [[ -n "$txHash" ]]; then
local symbol_query=$(curl --silent --location --request GET 'https://api.vottun.tech/erc/v1/erc20/symbol' \
"${auth[@]}" $ct_json \
--data-raw '{
"contractAddress": "'"$contractAddress"'",
"network": '$network'
}')
symbol=$(echo "$symbol_query" | jq -r '.symbol // empty')
echo -e "\nSending: $amount $symbol\nfrom: $sender\nto: $recipient"
_loading
[[ -n "$url_tx" ]] && echo -e "\nBlock explorer URL:\n$url_tx$txHash"
fi
}
incr_allowance() { # GRANT A SPENDER ACCOUNT THE RIGHT TO MANAGE A SPECIFIED AMOUNT OF TOKENS
local contractAddress spender network addedValue gasLimit step=1
echo "Please enter the following parameters to grant the right to manage an amount of tokens:"
echo -e "contractAddress spender network addedValue (gasLimit)\n"
while true; do
case $step in
1)
_check_input "Contract Address: " contractAddress -1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Contract Address is required." "Contract Address must start with '0x' and be 42 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)
_check_input "Spender: " spender 1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Spender is required." "Spender must start with '0x' and be 42 characters long."
_step_back && continue
step=3
;;
3)
_check_input "Network: " network 2 "true" '[[ "$input" =~ ^[0-9]+$ ]]' \
"Network is required." "Network must be an integer number."
_step_back && continue
step=4
;;
4)
_check_input "Added Value: " addedValue 3 "true" '[[ "$input" =~ ^[0-9]*\.?[0-9]+$ ]]' \
"Added Value is required." "Added Value must be a valid integer or decimal."
_step_back && continue
addedValue_wei=$(echo "$addedValue * 10^18 / 1" | bc)
step=5
;;
5)
_check_input "Gas Limit (optional): " gasLimit 4 "false" '[[ "$input" =~ ^[0-9]+$ ]]' \
"" "Gas Limit must be an integer number if provided."
_step_back && continue
step=6
;;
6)
IFS='|' read -r net_name currency url_address url_tx <<< "$(_network_details "$network")"
echo -e "\nYou've entered the following parameters:"
echo "Contract Address: $contractAddress"
echo "Spender: $spender"
echo "Network: $net_name"
echo "Added Value: $addedValue"
[ -n "$gasLimit" ] && echo "Gas Limit: $gasLimit"
echo
_confirmation && step=0 || { _step_back || return 1; }
[[ $step -eq 0 ]] && break
;;
esac
done
local data
data=$(jq -n \
--arg contractAddress "$contractAddress" \
--arg spender "$spender" \
--argjson network "$network" \
--arg gasLimit "$gasLimit" \
'{
contractAddress: $contractAddress,
spender: $spender,
network: $network
} +
(if $gasLimit != "" then {gasLimit: $gasLimit | tonumber} else {} end)')
data=$(echo "$data" | sed "s/^{/{\"addedValue\":$addedValue_wei, /")
local response=$(curl --silent --location --request POST 'https://api.vottun.tech/erc/v1/erc20/increaseAllowance' \
"${auth[@]}" $ct_json --data-raw "$data")
echo -e "Server response:\n$response"
txHash=$(echo "$response" | jq -r '.txHash // empty')
if [[ -n "$txHash" ]]; then
local symbol_query=$(curl --silent --location --request GET 'https://api.vottun.tech/erc/v1/erc20/symbol' \
"${auth[@]}" $ct_json \
--data-raw '{
"contractAddress": "'"$contractAddress"'",
"network": '$network'
}')
symbol=$(echo "$symbol_query" | jq -r '.symbol // empty')
echo -e "\nIncreasing allowance to: $addedValue $symbol\nfor: $spender"
_loading
[[ -n "$url_tx" ]] && echo -e "\nBlock explorer URL:\n$url_tx$txHash"
fi
}
decr_allowance(){ # REVOKE A SPENDER ACCOUNT THE RIGHT TO MANAGE A SPECIFIED AMOUNT OF TOKENS
local contractAddress spender network substractedValue gasLimit step=1
echo "Please enter the following parameters to revoke the right to manage an amount of tokens:"
echo -e "contractAddress spender network substractedValue (gasLimit)\n"
while true; do
case $step in
1)
_check_input "Contract Address: " contractAddress -1 "true" '[[ "$input" =~ ^0x[0-9a-fA-F]{40}$ ]]' \
"Contract Address is required." "Contract Address must start with '0x' and be 42 characters long."
[[ $? -eq 99 ]] && continue
step=2
;;
2)