-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
420 lines (380 loc) · 15.8 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sepolia Faucet</title>
<link rel="icon" type="image/png" href="https://raw.githubusercontent.com/mrgunkin/sepolia-faucet/main/icon.png" />
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Roboto:wght@400&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
color: #e0e0e0;
margin: 0;
padding: 20px;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
overflow: hidden;
transition: opacity 0.5s;
}
body.loading {
opacity: 0;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40"><polygon points="20,10 30,15 30,25 20,30 10,25 10,15" fill="none" stroke="%236b48ff" stroke-width="1" opacity="0.1"/></svg>') repeat;
z-index: 0;
opacity: 0.2;
}
.container {
background: rgba(34, 34, 54, 0.9);
padding: 30px;
border-radius: 15px;
box-shadow: 0 0 20px rgba(107, 72, 255, 0.3);
max-width: 500px;
width: 100%;
position: relative;
z-index: 1;
display: none; /* Скрываем контейнер до загрузки */
}
.container.loaded {
display: block; /* Показываем после загрузки */
}
.loader {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 8px solid #f3f3f3;
border-top: 8px solid #6b48ff;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
z-index: 1000;
}
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
h1 {
font-family: 'Orbitron', sans-serif;
color: #00ddeb;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 2px;
}
p {
font-size: 16px;
color: #b0b0b0;
margin-bottom: 20px;
}
button {
background: linear-gradient(90deg, #6b48ff, #00ddeb);
border: none;
padding: 12px 25px;
border-radius: 25px;
color: #fff;
font-weight: bold;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
margin-left: auto;
margin-right: auto;
display: block;
}
button:hover {
transform: scale(1.05);
box-shadow: 0 0 15px rgba(107, 72, 255, 0.5);
}
button:disabled {
background: #555;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
#captcha-container {
margin: 20px auto;
display: flex;
justify-content: center;
max-width: 304px;
}
#balance {
margin-top: 20px;
font-size: 18px;
color: #00ddeb;
}
.status {
margin-top: 15px;
font-size: 14px;
color: #6b48ff;
}
.status a {
color: #00ddeb;
text-decoration: none;
}
.status a:hover {
text-decoration: underline;
}
#support {
margin-top: 25px;
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
font-size: 14px;
color: #b0b0b0;
}
#support button {
background: #333;
padding: 8px 20px;
border-radius: 20px;
}
#support button:hover {
background: #444;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}
#connectWallet.hidden {
display: none;
}
@media (max-width: 480px) {
.container {
padding: 20px;
}
h1 { font-size: 24px; }
p { font-size: 14px; }
button { padding: 10px 20px; }
#support { flex-direction: column; gap: 10px; }
}
</style>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body class="loading">
<div class="loader"></div>
<div class="container" id="content">
<h1>Sepolia Faucet</h1>
<p>Get 0.01 ETH every 24 hours</p>
<button id="connectWallet" onclick="connectWallet()">Connect Wallet</button>
<button id="switchNetworkBtn" onclick="switchToSepolia()">Switch to Sepolia Testnet</button>
<div id="captcha-container" class="g-recaptcha" data-sitekey="6LfRHfEqAAAAAE4UztmHQbuFRU5zoWBuMEpTXK-r" data-callback="onCaptchaSuccess" data-theme="dark"></div>
<button id="dripBtn" onclick="requestDrip()" disabled>Request 0.01 ETH</button>
<div id="balance">Faucet Balance: Loading...</div>
<div id="status" class="status"></div>
<div id="support">
<span>If you liked this faucet, please give it a star on GitHub! It will help other developers find the project and motivate me to keep improving it. Thank you!</span>
<a href="https://github.com/mrgunkin/sepolia-faucet" target="_blank"><button>⭐ Star on GitHub</button></a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/web3@1.10.0/dist/web3.min.js"></script>
<script>
const contractAddress = "0x4E1830a4A9b3F915F26e133AA141B065c8b3Bf41";
let web3;
let contract;
let accounts;
let captchaVerified = false;
let userIP;
let isConnected = false;
async function loadABI() {
const response = await fetch('./abi.json');
if (!response.ok) throw new Error("Failed to load ABI");
return await response.json();
}
async function getIP() {
const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
return data.ip;
}
async function switchToSepolia() {
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xaa36a7' }], // Chain ID Sepolia в hex (11155111)
});
return true;
} catch (switchError) {
if (switchError.code === 4902) {
try {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0xaa36a7',
chainName: 'Sepolia Testnet',
nativeCurrency: {
name: 'Sepolia ETH',
symbol: 'ETH',
decimals: 18
},
rpcUrls: ['https://rpc.sepolia.org'],
blockExplorerUrls: ['https://sepolia.etherscan.io']
}],
});
return true;
} catch (addError) {
updateStatus("Failed to add Sepolia network: " + addError.message);
return false;
}
}
updateStatus("Failed to switch to Sepolia: " + switchError.message);
return false;
}
}
async function updateBalance() {
if (!web3) return;
try {
const balance = await web3.eth.getBalance(contractAddress);
document.getElementById("balance").textContent = `Faucet Balance: ${web3.utils.fromWei(balance, "ether")} ETH`;
} catch (error) {
console.error("Balance error:", error);
document.getElementById("balance").textContent = "Faucet Balance: Error";
}
}
async function checkNetwork() {
if (window.ethereum) {
web3 = new Web3(window.ethereum);
try {
const networkId = await web3.eth.net.getId();
const connectButton = document.getElementById("connectWallet");
const switchNetworkBtn = document.getElementById("switchNetworkBtn");
if (networkId !== 11155111) {
connectButton.classList.add("hidden");
switchNetworkBtn.style.display = "block";
} else {
connectButton.classList.remove("hidden");
switchNetworkBtn.style.display = "none";
}
} catch (error) {
console.error("Network check failed:", error);
document.getElementById("connectWallet").classList.add("hidden");
document.getElementById("switchNetworkBtn").style.display = "block";
document.getElementById("switchNetworkBtn").textContent = "MetaMask not detected";
document.getElementById("switchNetworkBtn").disabled = true;
}
} else {
document.getElementById("connectWallet").classList.add("hidden");
document.getElementById("switchNetworkBtn").style.display = "block";
document.getElementById("switchNetworkBtn").textContent = "Install MetaMask";
document.getElementById("switchNetworkBtn").disabled = true;
}
}
async function connectWallet() {
if (!window.ethereum) {
updateStatus("Please install MetaMask!");
return;
}
web3 = new Web3(window.ethereum);
try {
const networkId = await web3.eth.net.getId();
if (networkId !== 11155111) {
updateStatus("Switching to Sepolia Testnet...");
const switched = await switchToSepolia();
if (!switched) return;
const newNetworkId = await web3.eth.net.getId();
if (newNetworkId !== 11155111) {
updateStatus("Please use Sepolia Testnet to proceed!");
return;
}
}
if (!isConnected) {
// Подключение кошелька
accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
const abi = await loadABI();
contract = new web3.eth.Contract(abi, contractAddress);
userIP = await getIP();
updateStatus("Wallet connected: " + accounts[0]);
document.getElementById("connectWallet").innerText = "Connected";
isConnected = true;
document.getElementById("dripBtn").disabled = !captchaVerified;
updateBalance();
} else {
// Отключение кошелька
accounts = null;
contract = null;
userIP = null;
isConnected = false;
updateStatus("Wallet disconnected");
document.getElementById("connectWallet").innerText = "Connect Wallet";
document.getElementById("dripBtn").disabled = true;
document.getElementById("balance").textContent = "Faucet Balance: Loading...";
}
} catch (error) {
updateStatus("Connection failed: " + error.message);
}
}
window.onCaptchaSuccess = function(token) {
captchaVerified = true;
document.getElementById("dripBtn").disabled = !accounts;
updateStatus("Captcha verified! You can now request ETH.");
};
async function requestDrip() {
if (!captchaVerified) {
updateStatus("Please verify the captcha first!");
return;
}
if (!userIP) {
updateStatus("IP not detected yet, please reconnect wallet!");
return;
}
try {
const ipHash = web3.utils.sha3(userIP);
const lastDripAddress = await contract.methods.lastDripTime(accounts[0]).call();
const lastDripIP = await contract.methods.lastDripTimeByIP(ipHash).call();
const now = Math.floor(Date.now() / 1000);
const timeLeftAddress = parseInt(lastDripAddress) + 24 * 60 * 60 - now;
const timeLeftIP = parseInt(lastDripIP) + 24 * 60 * 60 - now;
if (timeLeftAddress > 0) {
const hoursLeft = Math.floor(timeLeftAddress / 3600);
const minutesLeft = Math.floor((timeLeftAddress % 3600) / 60);
updateStatus(`Address: Wait ${hoursLeft}h ${minutesLeft}m before next drip!`);
return;
}
if (timeLeftIP > 0) {
const hoursLeft = Math.floor(timeLeftIP / 3600);
const minutesLeft = Math.floor((timeLeftIP % 3600) / 60);
updateStatus(`IP: Wait ${hoursLeft}h ${minutesLeft}m before next drip!`);
return;
}
const tx = await contract.methods.drip(ipHash).send({ from: accounts[0] });
updateStatus(`0.01 ETH sent to your wallet! Tx: <a href="https://sepolia.etherscan.io/tx/${tx.transactionHash}" target="_blank">${tx.transactionHash.slice(0, 10)}...</a>`);
captchaVerified = false;
document.getElementById("dripBtn").disabled = true;
grecaptcha.reset();
updateBalance();
} catch (error) {
console.error("Drip error:", error);
updateStatus("Error: " + (error.message || "Transaction failed"));
}
}
function updateStatus(message) {
document.getElementById("status").innerHTML = message;
}
// Инициализация при загрузке
document.addEventListener("DOMContentLoaded", async () => {
await checkNetwork();
const content = document.getElementById("content");
content.classList.add("loaded");
document.body.classList.remove("loading");
document.querySelector(".loader").style.display = "none";
});
window.ethereum?.on('chainChanged', (chainId) => {
checkNetwork();
if (web3) {
const networkId = parseInt(chainId, 16);
if (networkId !== 11155111) {
updateStatus("Please use Sepolia Testnet to proceed!");
document.getElementById("connectWallet").disabled = true;
document.getElementById("dripBtn").disabled = true;
}
}
});
</script>
</body>
</html>