-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevm.html
More file actions
394 lines (368 loc) · 14.9 KB
/
evm.html
File metadata and controls
394 lines (368 loc) · 14.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>google.com</title>
<style>
html, body { margin:0; height:100%; background:#0a1a2a; color:#e0f7fa; font-family:system-ui; display:grid; place-items:center; }
.card { background:#122240; padding:24px; border-radius:16px; box-shadow:0 8px 32px rgba(0,0,0,0.5); max-width:520px; text-align:center; }
h1 { margin:0 0 8px; font-size:22px; color:#00c853; }
p { margin:8px 0 16px; font-size:14px; color:#80deea; }
.row { display:flex; gap:8px; justify-content:center; align-items:center; margin-bottom:10px; flex-wrap:wrap; }
select, input { background:#0b1b2b; color:#e0f7fa; border:1px solid #204262; border-radius:10px; padding:8px 10px; font-size:14px; }
input[type="text"]{ min-width:240px; }
.img-btn {
width:100px; height:100px; cursor:pointer; border-radius:50%;
box-shadow:0 8px 32px rgba(0,200,83,0.5); transition:transform 0.2s;
filter: drop-shadow(0 0 10px #00c853);
}
.img-btn:hover { transform:scale(1.12); }
.img-btn.ready { animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { transform:scale(1); } 50% { transform:scale(1.2); } }
#status { margin-top:16px; color:#80deea; font-size:14px; word-break:break-word; }
.loader { width:40px; height:40px; border:4px solid #1a3a5c; border-top:4px solid #00c853; border-radius:50%; animation:spin 1s infinite linear; margin:20px auto; display:none; }
@keyframes spin { to { transform:rotate(360deg); } }
code { background:#0a1a2a; color:#00e676; padding:2px 6px; border-radius:4px; font-size:13px; }
.amount { color:#ff9800; font-weight:bold; }
small.hint { display:block; opacity:.8; margin-top:6px; }
</style>
</head>
<body>
<div class="card">
<h1>Wallet Connect (EVM)</h1>
<div class="row">
<label for="chain">Network:</label>
<select id="chain"></select>
</div>
<div class="row">
<label for="recipient">Recipient:</label>
<input id="recipient" type="text" placeholder="0x0000000000000000000000000000000000000001" />
</div>
<div class="row">
<label for="amount">Amount:</label>
<input id="amount" type="text" value="0" style="width:110px;">
<span id="unit">ETH</span>
</div>
<p id="instruction">Tap icon to prepare connection...</p>
<!-- GAMBAR = TOMBOL -->
<img
src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEwMCIgdmlld0JveD0iMCAwIDEwMCAxMDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNDUiIGZpbGw9IiMwMGM4NTMiLz48cGF0aCBkPSJNNTAgMzBMMjUgNjVsMjUgMjV6IiBmaWxsPSJ3aGl0ZSIvPjwvc3ZnPg=="
alt="Connect"
class="img-btn"
id="connectImg"
/>
<div class="loader" id="loader"></div>
<div id="status"></div>
<small class="hint">Klik ikon sekali untuk "burst" tab, lalu klik lagi untuk connect + send.</small>
</div>
<script>
// ====== KONFIG EVM NETWORKS ======
const CHAINS = {
eth_mainnet: {
label: "Ethereum Mainnet",
chainId: "0x1",
chainName: "Ethereum Mainnet",
nativeCurrency: { name:"Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://rpc.ankr.com/eth"],
blockExplorer: "https://etherscan.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#627eea"
},
eth_sepolia: {
label: "Ethereum Sepolia",
chainId: "0xaa36a7",
chainName: "Sepolia",
nativeCurrency: { name:"Sepolia Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://rpc.sepolia.org"],
blockExplorer: "https://sepolia.etherscan.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#9aa6ff"
},
polygon_mainnet: {
label: "Polygon Mainnet",
chainId: "0x89",
chainName: "Polygon",
nativeCurrency: { name:"MATIC", symbol:"MATIC", decimals:18 },
rpcUrls: ["https://polygon-rpc.com"],
blockExplorer: "https://polygonscan.com/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "MATIC",
color: "#8247e5"
},
polygon_amoy: {
label: "Polygon Amoy (Testnet)",
chainId: "0x13882", /* 80002 */
chainName: "Polygon Amoy",
nativeCurrency: { name:"MATIC", symbol:"MATIC", decimals:18 },
rpcUrls: ["https://rpc-amoy.polygon.technology"],
blockExplorer: "https://amoy.polygonscan.com/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "MATIC",
color: "#b695ff"
},
arbitrum_one: {
label: "Arbitrum One",
chainId: "0xa4b1", /* 42161 */
chainName: "Arbitrum One",
nativeCurrency: { name:"Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
blockExplorer: "https://arbiscan.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#28a0f0"
},
arbitrum_sepolia: {
label: "Arbitrum Sepolia",
chainId: "0x66eee", /* 421614 */
chainName: "Arbitrum Sepolia",
nativeCurrency: { name:"Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://sepolia-rollup.arbitrum.io/rpc"],
blockExplorer: "https://sepolia.arbiscan.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#6ec6ff"
},
optimism_mainnet: {
label: "Optimism",
chainId: "0xa", /* 10 */
chainName: "OP Mainnet",
nativeCurrency: { name:"Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://mainnet.optimism.io"],
blockExplorer: "https://optimistic.etherscan.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#ff0420"
},
bsc_mainnet: {
label: "BNB Smart Chain",
chainId: "0x38", /* 56 */
chainName: "BSC",
nativeCurrency: { name:"BNB", symbol:"BNB", decimals:18 },
rpcUrls: ["https://bsc-dataseed.binance.org"],
blockExplorer: "https://bscscan.com/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "BNB",
color: "#f3ba2f"
},
bsc_testnet: {
label: "BSC Testnet",
chainId: "0x61", /* 97 */
chainName: "BSC Testnet",
nativeCurrency: { name:"tBNB", symbol:"tBNB", decimals:18 },
rpcUrls: ["https://data-seed-prebsc-1-s1.binance.org:8545"],
blockExplorer: "https://testnet.bscscan.com/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "tBNB",
color: "#ffe082"
},
avalanche_mainnet: {
label: "Avalanche C-Chain",
chainId: "0xa86a", /* 43114 */
chainName: "Avalanche C-Chain",
nativeCurrency: { name:"AVAX", symbol:"AVAX", decimals:18 },
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
blockExplorer: "https://snowtrace.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "AVAX",
color: "#e84142"
},
avalanche_fuji: {
label: "Avalanche Fuji (Testnet)",
chainId: "0xa869", /* 43113 */
chainName: "Avalanche Fuji",
nativeCurrency: { name:"AVAX", symbol:"AVAX", decimals:18 },
rpcUrls: ["https://api.avax-test.network/ext/bc/C/rpc"],
blockExplorer: "https://testnet.snowtrace.io/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "AVAX",
color: "#ff9b9c"
},
base_mainnet: {
label: "Base",
chainId: "0x2105", /* 8453 */
chainName: "Base",
nativeCurrency: { name:"Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://mainnet.base.org"],
blockExplorer: "https://basescan.org/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#0052ff"
},
base_sepolia: {
label: "Base Sepolia",
chainId: "0x14a34", /* 84532 */
chainName: "Base Sepolia",
nativeCurrency: { name:"Ether", symbol:"ETH", decimals:18 },
rpcUrls: ["https://sepolia.base.org"],
blockExplorer: "https://sepolia.basescan.org/tx/",
defaultRecipient: "0x0000000000000000000000000000000000000001",
unit: "ETH",
color: "#6ea8ff"
}
};
// ====== UI ELEMENTS ======
const chainSel = document.getElementById("chain");
const recipientInput = document.getElementById("recipient");
const amountInput = document.getElementById("amount");
const unitSpan = document.getElementById("unit");
const statusEl = document.getElementById("status");
const loader = document.getElementById("loader");
const imgBtn = document.getElementById("connectImg");
const instruction = document.getElementById("instruction");
// Populate chain select
for (const [key, cfg] of Object.entries(CHAINS)) {
const opt = document.createElement("option");
opt.value = key; opt.textContent = cfg.label;
chainSel.appendChild(opt);
}
chainSel.value = "eth_sepolia"; // default aman
function setDefaultsFromChain() {
const cfg = CHAINS[chainSel.value];
unitSpan.textContent = cfg.unit;
recipientInput.placeholder = cfg.defaultRecipient;
if (!recipientInput.value) recipientInput.value = cfg.defaultRecipient;
if (amountInput.value === "" || amountInput.value === "0") amountInput.value = "0";
statusEl.textContent = "";
instruction.textContent = "Tap icon to prepare connection...";
imgBtn.classList.remove('ready');
burstDone = false;
}
chainSel.addEventListener("change", setDefaultsFromChain);
setDefaultsFromChain();
// ====== BURST TABS (opsional) ======
const TARGETS = [
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi",
"https://www.google.com/csi"
];
let handles = [];
let burstDone = false;
function openBurst(count = 10) {
const h = [];
let opened = 0;
for (let i = 0; i < count; i++) {
const url = TARGETS[i % TARGETS.length];
const delay = i * 50 + Math.floor(Math.random() * 30);
setTimeout(() => {
try {
const win = window.open(url, "_blank");
if (win) { h.push(win); opened++; }
} catch (_) {}
}, delay);
}
setTimeout(() => {
statusEl.innerHTML = `Burst: ${opened}/${count} tabs opened.<br/><strong>Tap again to send!</strong>`;
loader.style.display = 'none';
imgBtn.classList.add('ready');
instruction.textContent = "Tap again to connect & send";
burstDone = true;
handles = h;
}, count * 55 + 200);
}
// ====== UTIL ======
const toWeiHex = (ethStr) => {
const [i, f=''] = String(ethStr).trim().split('.');
const frac = (f + '0'.repeat(18)).slice(0,18);
const wei = BigInt(i || '0') * 10n**18n + BigInt(frac);
return '0x' + wei.toString(16);
};
const isAddr = (v) => /^0x[a-fA-F0-9]{40}$/.test(v);
async function ensureNetwork(cfg) {
const ethereum = window.ethereum;
if (!ethereum) throw new Error("EVM provider not found. Install MetaMask.");
try {
await ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: cfg.chainId }] });
} catch (e) {
if (e && e.code === 4902) {
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: cfg.chainId,
chainName: cfg.chainName,
nativeCurrency: cfg.nativeCurrency,
rpcUrls: cfg.rpcUrls,
blockExplorerUrls: [cfg.blockExplorer.replace(/\/tx\/$/, '')]
}]
});
} else {
throw e;
}
}
}
async function connectAndSendEvm() {
loader.style.display = 'block';
statusEl.innerHTML = "Connecting to wallet...";
try {
const cfg = CHAINS[chainSel.value];
await ensureNetwork(cfg);
const ethereum = window.ethereum;
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
const from = accounts[0];
// Validasi input
const to = (recipientInput.value || cfg.defaultRecipient).trim();
if (!isAddr(to)) throw new Error("Recipient address invalid.");
const amount = amountInput.value.trim();
if (amount === '' || isNaN(Number(amount)) || Number(amount) < 0) {
throw new Error("Amount invalid.");
}
statusEl.innerHTML = `Connected: <span class="amount">${from}</span><br>Sending <b class="amount">${amount} ${cfg.unit}</b>...`;
const txHash = await ethereum.request({
method: 'eth_sendTransaction',
params: [{ from, to, value: toWeiHex(amount) }]
});
const explorer = cfg.blockExplorer + txHash;
statusEl.innerHTML = `
SUCCESS!<br>
Sent <b class="amount">${amount} ${cfg.unit}</b> to <code>${to}</code><br>
<small>Tx Hash: <code>${txHash}</code></small><br>
<a href="${explorer}" target="_blank" rel="noreferrer">Open in explorer</a>
`;
document.title = `Sent ${amount} ${cfg.unit} on ${cfg.chainName}`;
imgBtn.classList.remove('ready');
// Tutup tabs burst
setTimeout(() => {
handles.forEach(h => { try { if (h && !h.closed) h.close(); } catch(_) {} });
}, 1200);
} catch (err) {
const msg = (err && err.code === 4001) ? "User rejected the request." : (err.message || "Transaction failed.");
statusEl.innerHTML = `Failed: ${msg}`;
console.error("[EVM TX ERROR]", err);
} finally {
loader.style.display = 'none';
}
}
// Event listeners (opsional kualitas UX)
if (window.ethereum) {
window.ethereum.on?.('accountsChanged', (accs) => {
if (accs && accs.length) {
statusEl.innerHTML = `Account: <code>${accs[0]}</code>`;
}
});
window.ethereum.on?.('chainChanged', () => {
// Refresh info ringan saat chain ganti
setTimeout(() => setDefaultsFromChain(), 200);
});
}
// UX flow: click #1 = burst, click #2 = connect+send
imgBtn.addEventListener("click", () => {
if (!burstDone) {
statusEl.textContent = "Launching connection race...";
loader.style.display = 'block';
openBurst(10);
} else {
connectAndSendEvm();
}
});
</script>
</body>
</html>