Repository navigation
Expand file tree
/
Copy pathvlayer_script.sh
More file actions
639 lines (569 loc) · 28.4 KB
/
Copy pathvlayer_script.sh
File metadata and controls
639 lines (569 loc) · 28.4 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
#!/bin/bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Global variables for API Key and Private Key files
GLOBAL_TESTNET_KEYS_FILE="$HOME/.vlayer_testnet_keys"
GLOBAL_MAINNET_KEYS_FILE="$HOME/.vlayer_mainnet_keys"
# --- Installation Functions ---
# Install Foundry
install_foundry() {
if command -v forge &> /dev/null; then
echo -e "${GREEN}Foundry already installed.${NC}"
return 0
fi
echo -e "${YELLOW}Installing Foundry...${NC}"
curl -L https://foundry.paradigm.xyz | bash
# Ensure PATH is updated for current session
export PATH="$HOME/.foundry/bin:$PATH"
# Add to .bashrc for persistence
grep -qxF 'export PATH="$HOME/.foundry/bin:$PATH"' ~/.bashrc || echo 'export PATH="$HOME/.foundry/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
if ! command -v foundryup &> /dev/null; then
echo -e "${RED}Foundry installation failed!${NC}"
return 1
fi
foundryup
echo -e "${GREEN}Foundry installed successfully!${NC}"
}
# Install Bun with unzip dependency
install_bun() {
if command -v bun &> /dev/null; then
echo -e "${GREEN}Bun already installed.${NC}"
return 0
fi
echo -e "${YELLOW}Installing unzip (required for Bun)...${NC}"
sudo apt-get install -y unzip || {
echo -e "${RED}Failed to install unzip!${NC}"
return 1
}
echo -e "${YELLOW}Installing Bun...${NC}"
curl -fsSL https://bun.sh/install | bash
# Ensure PATH is updated for current session
export PATH="$HOME/.bun/bin:$PATH"
# Add to .bashrc for persistence
grep -qxF 'export PATH="$HOME/.bun/bin:$PATH"' ~/.bashrc || echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
if ! command -v bun &> /dev/null; then
echo -e "${RED}Failed to install Bun!${NC}"
return 1
fi
echo -e "${GREEN}Bun installed successfully!${NC}"
}
# Install VLayerUP
install_vlayer() {
if command -v vlayer &> /dev/null; then
echo -e "${GREEN}VLayer already installed.${NC}"
return 0
fi
echo -e "${YELLOW}Installing VLayerUP...${NC}"
curl -SL https://install.vlayer.xyz | bash
# Ensure PATH is updated for current session for vlayerup
export PATH="$HOME/.vlayer/bin:$PATH"
# Add to .bashrc for persistence
grep -qxF 'export PATH="$HOME/.vlayer/bin:$PATH"' ~/.bashrc || echo 'export PATH="$HOME/.vlayer/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc # Apply changes immediately
if ! command -v vlayerup &> /dev/null; then
echo -e "${RED}Failed to install VLayerUP! Make sure it's added to PATH. Output from installer may help.${NC}"
return 1
fi
echo -e "${YELLOW}Installing VLayer (nightly channel)...${NC}"
vlayerup --channel nightly
# The above command should install vlayer into ~/.vlayer/bin as well
if ! command -v vlayer &> /dev/null; then
echo -e "${RED}Failed to install VLayer!${NC}"
return 1
fi
echo -e "${GREEN}VLayer installed successfully!${NC}"
}
# Complete setup
complete_setup() {
echo -e "${BLUE}--- Starting Complete Setup ---${NC}"
sudo apt-get update -y
declare -A deps=(
["curl"]="sudo apt-get install -y curl"
["git"]="sudo apt-get install -y git"
["docker"]="sudo apt-get install -y docker.io"
["unzip"]="sudo apt-get install -y unzip" # Ensure unzip is installed explicitly
)
for dep in "${!deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
echo -e "${YELLOW}Installing $dep...${NC}"
eval "${deps[$dep]}" || {
echo -e "${RED}Failed to install $dep!${NC}"
return 1
}
fi
done
install_foundry || return 1
install_bun || return 1
install_vlayer || return 1
echo -e "${GREEN}=== All components installed successfully! ===${NC}"
}
# Verify installations
verify_install() {
echo -e "${BLUE}--- Verification ---${NC}"
declare -A tools=(
["Foundry"]="forge --version"
["Bun"]="bun --version"
["VLayer"]="vlayer --version"
["Docker"]="docker --version"
)
for tool in "${!tools[@]}"; do
echo -ne "$tool: "
if command -v ${tools[$tool]%% *} &> /dev/null; then
echo -e "${GREEN}$(eval ${tools[$tool]})${NC}"
else
echo -e "${RED}Not installed${NC}"
fi
done
}
# --- Global API Key & Private Key Configuration Sub-menu ---
configure_global_keys_menu() {
while true; do
clear
echo -e "${BLUE}=== Konfigurasi Global API Key & Private Key ===${NC}"
echo -e "${YELLOW}Pilih jenis jaringan untuk konfigurasi kunci Anda:${NC}"
echo -e "${GREEN}1. Konfigurasi Kunci untuk TESTNET${NC}"
echo -e "${GREEN}2. Konfigurasi Kunci untuk MAINNET${NC}"
echo -e "${RED}0. Kembali ke Menu Utama${NC}"
echo -ne "${YELLOW}Masukkan pilihan Anda [0-2]:${NC} "
read -r choice
case $choice in
1)
echo -e "${YELLOW}Konfigurasi Kunci untuk TESTNET${NC}"
echo -e "${YELLOW}Dapatkan VLAYER_API_TOKEN Testnet Anda dari https://dashboard.vlayer.xyz.${NC}"
read -rp "Masukkan VLAYER_API_TOKEN Testnet: " VLAYER_API_TOKEN_INPUT
echo -e "${YELLOW}Masukkan private key wallet Testnet Anda (contoh: 0x...).${NC}"
read -rp "Masukkan EXAMPLES_TEST_PRIVATE_KEY Testnet: " PRIVATE_KEY_INPUT
# Store API Key and Private Key in the same testnet file
echo "VLAYER_API_TOKEN=$VLAYER_API_TOKEN_INPUT" > "$GLOBAL_TESTNET_KEYS_FILE"
echo "EXAMPLES_TEST_PRIVATE_KEY=$PRIVATE_KEY_INPUT" >> "$GLOBAL_TESTNET_KEYS_FILE"
chmod 600 "$GLOBAL_TESTNET_KEYS_FILE"
echo -e "${GREEN}API Key dan Private Key Testnet berhasil disimpan!${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
;;
2)
echo -e "${YELLOW}Konfigurasi Kunci untuk MAINNET${NC}"
echo -e "${YELLOW}Dapatkan VLAYER_API_TOKEN Mainnet Anda dari https://dashboard.vlayer.xyz.${NC}"
read -rp "Masukkan VLAYER_API_TOKEN Mainnet: " VLAYER_API_TOKEN_INPUT
echo -e "${YELLOW}Masukkan private key wallet Mainnet Anda (contoh: 0x...).${NC}"
read -rp "Masukkan EXAMPLES_TEST_PRIVATE_KEY Mainnet: " PRIVATE_KEY_INPUT
# Store API Key and Private Key in the same mainnet file
echo "VLAYER_API_TOKEN=$VLAYER_API_TOKEN_INPUT" > "$GLOBAL_MAINNET_KEYS_FILE"
echo "EXAMPLES_TEST_PRIVATE_KEY=$PRIVATE_KEY_INPUT" >> "$GLOBAL_MAINNET_KEYS_FILE"
chmod 600 "$GLOBAL_MAINNET_KEYS_FILE"
echo -e "${GREEN}API Key dan Private Key Mainnet berhasil disimpan!${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
;;
0)
echo -e "${YELLOW}Kembali ke menu utama.${NC}"
return
;;
*)
echo -e "${RED}Pilihan tidak valid!${NC}"
sleep 1
;;
esac
done
}
# --- Functions for Project Setup & Run ---
# Function to handle project creation or selection
setup_project() {
clear
echo -e "${BLUE}=== VLayer Project Setup: Pilih Template ===${NC}"
echo -e "${YELLOW}(Ini akan membuat proyek di /root/vlayer_projects/<nama_template>)${NC}"
echo -e "${GREEN}1. simple: Prove an ERC20 token balance at a specific block number."
echo "2. simple-email-proof: Mint an NFT to the owner of an email address."
echo "3. simple-teleport: Prove a cross-chain ERC20 token balance."
echo "4. simple-time-travel: Prove average ERC20 balance across blocks."
echo "5. simple-web-proof: Mint an NFT to the owner of an X/Twitter handle."
echo "6. kraken-web-proof: Generate server-side web proof of ETH to USD."
echo -e "${RED}0. Kembali ke Menu Utama${NC}"
echo -ne "${YELLOW}Masukkan pilihan Anda [0-6]:${NC} "
read -r template_choice
local chosen_template_name=""
local project_base_dir="/root/vlayer_projects" # Base directory for all new projects
case $template_choice in
1) chosen_template_name="simple" ;;
2) chosen_template_name="simple-email-proof" ;;
3) chosen_template_name="simple-teleport" ;;
4) chosen_template_name="simple-time-travel" ;;
5) chosen_template_name="simple-web-proof" ;;
6) chosen_template_name="kraken-web-proof" ;;
0)
echo -e "${YELLOW}Kembali ke menu utama.${NC}"
return 1
;;
*)
echo -e "${RED}Pilihan tidak valid!${NC}"
sleep 1
return 1
;;
esac
local full_project_path="$project_base_dir/$chosen_template_name"
echo -e "${YELLOW}Memastikan direktori bersih untuk template: ${full_project_path}${NC}"
rm -rf "$full_project_path" # Bersihkan upaya sebelumnya jika ada
mkdir -p "$full_project_path" # Buat direktori yang bersih
cd "$full_project_path" || { echo -e "${RED}Gagal membuat/pindah ke direktori ${full_project_path}!${NC}"; return 1; }
echo -e "${YELLOW}Membuat proyek dari template '$chosen_template_name' di $(pwd)...${NC}"
vlayer init . --template "$chosen_template_name" # Inisialisasi di direktori kosong saat ini
if [ $? -eq 0 ]; then
echo -e "${GREEN}Proyek dari template '$chosen_template_name' berhasil dibuat.${NC}"
CURRENT_PROJECT_DIR=$(pwd) # Set proyek saat ini ke root template
else
echo -e "${RED}Gagal membuat proyek dari template '$chosen_template_name'!${NC}"
return 1
fi
# Common steps after project setup
echo -e "${BLUE}--- Membangun Kontrak dan Menginstal Dependensi ---${NC}"
echo -e "${YELLOW}Menjalankan forge build...${NC}"
forge build || { echo -e "${RED}Forge build gagal!${NC}"; return 1; }
echo -e "${GREEN}Forge build selesai.${NC}"
echo -e "${YELLOW}Pindah ke direktori ./vlayer dan menjalankan bun install...${NC}"
if [ -d "./vlayer" ]; then
cd "./vlayer" || { echo -e "${RED}Gagal pindah ke direktori ./vlayer!${NC}"; return 1; }
bun install || { echo -e "${RED}Bun install gagal di ./vlayer!${NC}"; return 1; }
echo -e "${GREEN}Bun install selesai di ./vlayer.${NC}"
CURRENT_PROJECT_TEMPLATE="$chosen_template_name" # Simpan nama template yang dipilih
else
echo -e "${RED}Direktori './vlayer' tidak ditemukan! Pastikan VLayer diinisialisasi dengan benar.${NC}"
return 1
fi
echo -e "${GREEN}Setup proyek selesai! Siap menjalankan contoh VLayer.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
return 0
}
# --- Function to patch simple-teleport constants.ts ---
patch_simple_teleport_constants() {
local target_chain="$1" # 'base', 'baseSepolia', 'sepolia', etc.
local constants_file="./constants.ts"
if [ ! -f "$constants_file" ]; then
echo -e "${RED}Error: constants.ts tidak ditemukan di direktori saat ini! Tidak dapat melakukan patch.${NC}"
return 1
fi
echo -e "${YELLOW}Mencoba melakukan patch constants.ts untuk $target_chain...${NC}"
local token_holder=""
local erc20_addresses=""
local erc20_chain_ids=""
local erc20_block_numbers=""
local json_rpc_url_for_patch="" # Variable to hold the specific RPC URL for this chain in constants.ts
case "$target_chain" in
"base")
token_holder="0x2724497B94B5E2856E22765A20C283F11E55077F" # Placeholder, cek BaseScan untuk holder asli
erc20_addresses="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" # USDC di Base Mainnet
erc20_chain_ids="8453"
erc20_block_numbers="0" # Akan diganti dengan nomor blok terbaru jika memungkinkan, atau gunakan nomor blok yang dikenal. Untuk kesederhanaan, gunakan 0
json_rpc_url_for_patch="https://base.publicnode.com" # Default public RPC for Base Mainnet
echo -e "${YELLOW}PERINGATAN: Menggunakan nomor blok placeholder (0) untuk Base Mainnet. Disarankan untuk memperbarui ini dengan nomor blok final terbaru dari Basescan.${NC}"
;;
"baseSepolia")
token_holder="0x401662998f480302621c1722C99f24B10582531d" # Placeholder, cek Basescan Sepolia
erc20_addresses="0x036CbD53842c542668c52CbEe02fA8CDD298e79f" # USDC di Base Sepolia
erc20_chain_ids="84532"
erc20_block_numbers="0" # Placeholder, pengguna mungkin perlu memperbarui
json_rpc_url_for_patch="https://sepolia.base.org" # Default public RPC for Base Sepolia
echo -e "${YELLOW}PERINGATAN: Menggunakan nomor blok placeholder (0) untuk Base Sepolia. Disarankan untuk memperbarui ini dengan nomor blok final terbaru dari Basescan Sepolia.${NC}"
;;
"sepolia") # Add Sepolia configuration
token_holder="0xf41C24dA6ae70cb99E050E11197EC88237Ca7724" # Example address (from your error, adjust if needed)
erc20_addresses="0x280e227C7c7DcF4658B9365511A934E950b7F138" # WETH on Sepolia (example, adjust if needed)
erc20_chain_ids="11155111"
erc20_block_numbers="0" # Placeholder, user might need to update
json_rpc_url_for_patch="https://eth-sepolia.g.alchemy.com/v2/NpEA92nK9B2YCDEm2acl45dVOSZvNyBe" # Your provided Alchemy RPC
echo -e "${YELLOW}PERINGATAN: Menggunakan nomor blok placeholder (0) untuk Sepolia. Disarankan untuk memperbarui ini dengan nomor blok final terbaru dari Etherscan Sepolia.${NC}"
echo -e "${GREEN}Menggunakan Alchemy RPC yang Anda berikan untuk Sepolia di constants.ts.${NC}"
;;
*)
echo -e "${RED}Chain target tidak valid untuk patching: $target_chain${NC}"
return 1
;;
esac
# Check if the entry already exists to prevent duplicates
if grep -q "$target_chain: {" "$constants_file"; then
echo -e "${GREEN}Entri untuk '$target_chain' sudah ada di constants.ts. Melewatkan patch.${NC}"
return 0
fi
# The actual patch using sed. This is highly sensitive to file structure.
# We will insert the new entry just before the `getTeleportConfig` function.
# The sed command should insert after the closing brace of the last existing entry (mainnet)
local patch_content="\
${target_chain}: {\
tokenHolder: \"$token_holder\",\
prover: {\
erc20Addresses: \"$erc20_addresses\",\
erc20ChainIds: \"$erc20_chain_ids\",\
erc20BlockNumbers: \"$erc20_block_numbers\",\
},\
jsonRpcUrl: \"$json_rpc_url_for_patch\", // Added RPC URL for direct usage in constants.ts
},"
# Escape slashes in patch_content for sed
patch_content_escaped=$(echo "$patch_content" | sed 's/\//\\\//g')
# Insert after the closing brace of 'mainnet' entry
# This sed command is designed to insert the content after the exact line ' },' that closes the 'mainnet' block.
# It assumes 'mainnet' block exists and is the last one before getTeleportConfig
if grep -q "mainnet: {" "$constants_file"; then
# Check if the last line of the 'mainnet' config is ' },'
if tail -n 1 "$constants_file" | grep -q "^ },"; then
sed -i "/mainnet: {/,/^ },/ { /^ },/a $patch_content_escaped" "$constants_file"
else
# Fallback if the previous sed didn't find the exact match or file structure differs slightly
# Try to insert before getTeleportConfig if 'mainnet' closing brace isn't found reliably
sed -i "/export const getTeleportConfig/i $patch_content_escaped" "$constants_file"
fi
echo -e "${GREEN}Menambahkan konfigurasi '$target_chain' ke constants.ts.${NC}"
return 0
else
echo -e "${RED}Tidak dapat menemukan entri 'mainnet' di constants.ts atau format file tidak terduga. Mungkin perlu patch manual.${NC}"
return 1
fi
}
# Function to run VLayer examples
run_vlayer_example() {
if [ -z "$CURRENT_PROJECT_DIR" ]; then
echo -e "${RED}Tidak ada proyek VLayer yang dipilih atau disiapkan. Harap jalankan '4. Setup Proyek VLayer' terlebih dahulu.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
return 1
fi
local original_dir=$(pwd)
if [ -d "$CURRENT_PROJECT_DIR/vlayer" ]; then
cd "$CURRENT_PROJECT_DIR/vlayer" || { echo -e "${RED}Gagal pindah ke direktori proyek vlayer!${NC}"; read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1; return 1; }
else
echo -e "${RED}Direktori './vlayer' tidak ditemukan di '$CURRENT_PROJECT_DIR'. Pastikan setup proyek berhasil.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
return 1
fi
while true; do
clear
echo -e "${BLUE}=== Jalankan Contoh VLayer ===${NC}"
echo -e "${YELLOW}Direktori saat ini: $(pwd)${NC}"
echo -e "${GREEN}1. Jalankan di Local Devnet (bun run prove:dev)"
echo -e "${GREEN}2. Jalankan di TESTNET (Pilih jaringan Testnet)${NC}"
echo -e "${GREEN}3. Jalankan di MAINNET (Pilih jaringan Mainnet)${NC}"
echo -e "${GREEN}4. Mulai Aplikasi Web Proof (bun run web:dev)${NC}"
echo -e "${RED}0. Kembali ke Menu Utama${NC}"
echo -ne "${YELLOW}Masukkan pilihan Anda [0-4]:${NC} "
read -r run_mode_choice
case $run_mode_choice in
1) # Local Devnet
echo -e "${BLUE}Memulai Local Devnet dengan Docker...${NC}"
echo -e "${YELLOW}Pastikan Docker berjalan!${NC}"
bun run devnet:up
if [ $? -ne 0 ]; then
echo -e "${RED}Gagal memulai devnet! Periksa status Docker dan log.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
continue # Go back to run_vlayer_example menu
fi
echo -e "${GREEN}Devnet sudah aktif. Menjalankan contoh...${NC}"
# No VLAYER_ENV or specific CHAIN/RPC needed for prove:dev
bun run prove:dev
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
break # Exit run_vlayer_example menu
;;
2) # TESTNET
if [ ! -f "$GLOBAL_TESTNET_KEYS_FILE" ]; then
echo -e "${RED}File konfigurasi kunci TESTNET ($GLOBAL_TESTNET_KEYS_FILE) belum ditemukan.${NC}"
echo -e "${YELLOW}Harap gunakan '3. Konfigurasi Global API & Private Key' dan pilih opsi TESTNET terlebih dahulu.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
continue # Go back to run_vlayer_example menu
fi
# Source the file to load VLAYER_API_TOKEN and EXAMPLES_TEST_PRIVATE_KEY
source "$GLOBAL_TESTNET_KEYS_FILE"
local VLAYER_ENV="testnet" # Ensure VLAYER_ENV is defined for SDK
local -a testnet_chains_display_names=(
"Optimism Sepolia"
"Base Sepolia"
"Sepolia (Ethereum)"
)
local -a testnet_chains_values=(
"optimismSepolia|https://sepolia.optimism.io"
"baseSepolia|https://sepolia.base.org"
"sepolia|https://eth-sepolia.g.alchemy.com/v2/NpEA92nK9B2YCDEm2acl45dVOSZvNyBe" # Updated RPC for Sepolia
)
clear
echo -e "${BLUE}=== Pilih Jaringan TESTNET ===${NC}"
local i=1
for name in "${testnet_chains_display_names[@]}"; do
echo -e "${GREEN}${i}. ${name}${NC}"
i=$((i+1))
done
echo -e "${RED}0. Kembali${NC}"
echo -ne "${YELLOW}Masukkan pilihan Anda [0-${#testnet_chains_display_names[@]}]:${NC} "
read -r chain_choice
if [ "$chain_choice" == "0" ]; then
continue # Go back to run_vlayer_example menu
elif (( chain_choice > 0 && chain_choice <= ${#testnet_chains_values[@]} )); then
local selected_chain_info="${testnet_chains_values[chain_choice-1]}"
local CHAIN_NAME=$(echo "$selected_chain_info" | cut -d'|' -f1)
local JSON_RPC_URL=$(echo "$selected_chain_info" | cut -d'|' -f2)
echo -e "${BLUE}Menjalankan contoh untuk ${CHAIN_NAME} (${JSON_RPC_URL})...${NC}"
echo "# VLayer Environment Variables (Temporary for this run)" > ".env.local"
echo "VLAYER_API_TOKEN=$VLAYER_API_TOKEN" >> ".env.local"
echo "EXAMPLES_TEST_PRIVATE_KEY=$EXAMPLES_TEST_PRIVATE_KEY" >> ".env.local"
echo "CHAIN_NAME=$CHAIN_NAME" >> ".env.local"
echo "JSON_RPC_URL=$JSON_RPC_URL" >> ".env.local"
echo "VLAYER_ENV=$VLAYER_ENV" >> ".env.local" # Add VLAYER_ENV
if [ "$CURRENT_PROJECT_TEMPLATE" == "simple-teleport" ]; then
# Offer to patch constants.ts for simple-teleport template
if [ "$CHAIN_NAME" == "baseSepolia" ] || [ "$CHAIN_NAME" == "sepolia" ]; then
echo -ne "${YELLOW}Apakah Anda ingin menambahkan konfigurasi ${CHAIN_NAME} ke constants.ts untuk Teleport? (y/n):${NC} "
read -r patch_confirm
if [[ "$patch_confirm" =~ ^[Yy]$ ]]; then
patch_simple_teleport_constants "$CHAIN_NAME" || {
echo -e "${RED}Patching constants.ts gagal! Mungkin perlu edit manual.${NC}"
}
fi
fi
fi
bun run prove.ts
rm -f ".env.local"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
break # Exit run_vlayer_example menu
else
echo -e "${RED}Pilihan tidak valid!${NC}"
sleep 1
continue # Go back to run_vlayer_example menu
fi
;;
3) # MAINNET
if [ ! -f "$GLOBAL_MAINNET_KEYS_FILE" ]; then
echo -e "${RED}File konfigurasi kunci MAINNET ($GLOBAL_MAINNET_KEYS_FILE) belum ditemukan.${NC}"
echo -e "${YELLOW}Harap gunakan '3. Konfigurasi Global API & Private Key' dan pilih opsi MAINNET terlebih dahulu.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
continue # Go back to run_vlayer_example menu
fi
# Source the file to load VLAYER_API_TOKEN and EXAMPLES_TEST_PRIVATE_KEY
source "$GLOBAL_MAINNET_KEYS_FILE"
local VLAYER_ENV="mainnet" # Ensure VLAYER_ENV is defined for SDK
local -a mainnet_chains_display_names=(
"Ethereum Mainnet"
"Optimism Mainnet"
"Base Mainnet"
)
local -a mainnet_chains_values=(
"ethereum|https://ethereum.publicnode.com"
"optimism|https://mainnet.optimism.io"
"base|https://base.publicnode.com"
)
clear
echo -e "${BLUE}=== Pilih Jaringan MAINNET ===${NC}"
local i=1
for name in "${mainnet_chains_display_names[@]}"; do
echo -e "${GREEN}${i}. ${name}${NC}"
i=$((i+1))
done
echo -e "${RED}0. Kembali${NC}"
echo -ne "${YELLOW}Masukkan pilihan Anda [0-${#mainnet_chains_display_names[@]}]:${NC} "
read -r chain_choice
if [ "$chain_choice" == "0" ]; then
continue # Go back to run_vlayer_example menu
elif (( chain_choice > 0 && chain_choice <= ${#mainnet_chains_values[@]} )); then
local selected_chain_info="${mainnet_chains_values[chain_choice-1]}"
local CHAIN_NAME=$(echo "$selected_chain_info" | cut -d'|' -f1)
local JSON_RPC_URL=$(echo "$selected_chain_info" | cut -d'|' -f2)
echo -e "${BLUE}Menjalankan contoh untuk ${CHAIN_NAME} (${JSON_RPC_URL})...${NC}"
echo "# VLayer Environment Variables (Temporary for this run)" > ".env.local"
echo "VLAYER_API_TOKEN=$VLAYER_API_TOKEN" >> ".env.local"
echo "EXAMPLES_TEST_PRIVATE_KEY=$EXAMPLES_TEST_PRIVATE_KEY" >> ".env.local"
echo "CHAIN_NAME=$CHAIN_NAME" >> ".env.local"
echo "JSON_RPC_URL=$JSON_RPC_URL" >> ".env.local"
echo "VLAYER_ENV=$VLAYER_ENV" >> ".env.local" # Add VLAYER_ENV
if [ "$CURRENT_PROJECT_TEMPLATE" == "simple-teleport" ]; then
# Offer to patch constants.ts for simple-teleport template
if [ "$CHAIN_NAME" == "base" ]; then
echo -ne "${YELLOW}Apakah Anda ingin menambahkan konfigurasi ${CHAIN_NAME} ke constants.ts untuk Teleport? (y/n):${NC} "
read -r patch_confirm
if [[ "$patch_confirm" =~ ^[Yy]$ ]]; then
patch_simple_teleport_constants "$CHAIN_NAME" || {
echo -e "${RED}Patching constants.ts gagal! Mungkin perlu edit manual.${NC}"
}
fi
fi
fi
bun run prove.ts
rm -f ".env.local"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
break # Exit run_vlayer_example menu
else
echo -e "${RED}Pilihan tidak valid!${NC}"
sleep 1
continue # Go back to run_vlayer_example menu
fi
;;
4) # Web Proof
echo -e "${YELLOW}Pastikan Ekstensi Browser VLayer terinstal dari Chrome Web Store.${NC}"
echo -e "${YELLOW}Memulai aplikasi Web Proof... (Akses di http://localhost:5174)${NC}"
bun run web:dev
echo -e "${GREEN}Aplikasi Web Proof sedang berjalan. Tekan CTRL+C untuk menghentikan.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
break # Exit run_vlayer_example menu
;;
0)
echo -e "${YELLOW}Kembali ke menu utama.${NC}"
break # Exit run_vlayer_example menu
;;
*)
echo -e "${RED}Pilihan tidak valid!${NC}"
sleep 1
;;
esac
done
cd "$original_dir" # Kembali ke direktori awal
}
# --- Main Menu (Updated) ---
# Global variable to store current project directory
CURRENT_PROJECT_DIR=""
CURRENT_PROJECT_TEMPLATE="" # Global variable to store the template name
main_menu() {
while true; do
clear
echo -e "${YELLOW} VLayer Automation Script by @ramadh1 ${NC}"
echo -e "--------------------------------------------------------------------------"
echo -e "${GREEN}1. Setup Lengkap (Instal semua dependensi: Foundry, Bun, VLayer, Docker)${NC}"
echo -e "${GREEN}2. Verifikasi Semua Instalasi${NC}"
echo -e "${GREEN}3. Konfigurasi Global API & Private Key (Testnet/Mainnet)${NC}" # Updated name
echo -e "${GREEN}4. Setup Proyek VLayer (Pilih Template & Siapkan)${NC}"
echo -e "${GREEN}5. Jalankan Contoh VLayer (Membutuhkan Setup Proyek & Konfigurasi Kunci)${NC}" # Updated name
echo -e "${RED}0. Keluar${NC}"
echo -e "--------------------------------------------------------------------------"
echo -ne "${YELLOW}Masukkan pilihan Anda [0-5]:${NC} "
read -r choice
case $choice in
1)
if complete_setup; then
echo -e "${GREEN}Setup lengkap berhasil diselesaikan!${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
else
echo -e "${RED}Setup lengkap gagal! Periksa error di atas.${NC}"
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
fi
;;
2)
verify_install
read -rp $'\nTekan tombol apa saja untuk melanjutkan...' -n1
;;
3) # Global keys config sub-menu
configure_global_keys_menu
;;
4)
setup_project
;;
5)
run_vlayer_example
;;
0)
echo -e "${GREEN}Keluar. Selamat coding dengan VLayer!${NC}"
exit 0
;;
*)
echo -e "${RED}Pilihan tidak valid!${NC}"
sleep 1
;;
esac
done
}
# Start
main_menu