-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
463 lines (414 loc) · 19.3 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CornHub Intl.</title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #4CAF50;
--hover-color: #45a049;
--corn-yellow: #F4D03F;
}
body {
background-color: #f5f5f5;
font-family: 'Roboto', sans-serif;
line-height: 1.6;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
.modern-button {
background-color: var(--primary-color);
border: none;
color: white;
padding: 12px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.modern-button:hover {
background-color: var(--hover-color);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
transform: translateY(-2px);
}
.modern-button.connected {
background-color: var(--corn-yellow);
color: #333;
}
.balance-table {
margin: 20px auto;
border-collapse: collapse;
width: 80%;
max-width: 400px;
}
.balance-table th, .balance-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
.balance-table th {
background-color: var(--primary-color);
color: white;
}
.gallery-embed {
width: 100%;
height: 600px;
border: none;
margin-top: 20px;
}
.button-grid {
display: grid;
gap: 10px;
max-width: 600px;
margin: 0 auto;
}
.button-row {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.modern-button {
margin: 5px;
flex: none;
width: 150px;
}
</style>
</head>
<body>
<center>
<a href="https://misctyler.github.io/CornHub/">
<img src="images/teste-f-branco-1.png" alt="CornHub Banner" style="width:100%;max-width:500px;height:auto;">
</a>
<br>
<img src="images/moeda-bronze.png" alt="Bronze Kernel" style="width:50px;height:50px;">
<img src="images/moeda.png" alt="Silver Kernel" style="width:50px;height:50px;">
<img src="images/moeda-gold.png" alt="Gold Kernel" style="width:50px;height:50px;">
<img src="images/moeda-vip.png" alt="VIP Kernel" style="width:50px;height:50px;">
<br>
<p id="network-status">
<img src="images/polygon-matic-logo.png" alt="polygon" style="width:25px;height:auto;vertical-align:middle;">
*** Please Only Connect using Polygon (matic) network ***
<img src="images/polygon-matic-logo.png" alt="polygon" style="width:25px;height:auto;vertical-align:middle;">
</p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.5.2/web3.min.js" integrity="sha512-qfNEgqdLEd+OkOZSZxb9kPOvOz62NNoPd0A5W5G8LMwfdtKn3+5D/tx5zvgu+7IaPqkFq60VfJ+Mn1bVJjMx/w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
// Check if MetaMask is installed and is connected
if (typeof window.ethereum !== 'undefined' && window.ethereum.isMetaMask) {
// Function to switch to Polygon network
async function switchToPolygon() {
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x89' }], // chainId must be in hexadecimal numbers
});
} catch (error) {
// This error code indicates that the chain has not been added to MetaMask
if (error.code === 4902) {
try {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x89',
chainName: 'Polygon Mainnet',
nativeCurrency: {
name: 'MATIC',
symbol: 'MATIC',
decimals: 18
},
rpcUrls: ['https://polygon-rpc.com/'],
blockExplorerUrls: ['https://polygonscan.com/']
}],
});
} catch (addError) {
console.error(addError);
}
}
console.error(error);
}
}
// Function to update network status message
function updateNetworkStatus(isPolygon) {
const statusElement = document.getElementById('network-status');
if (isPolygon) {
statusElement.innerHTML = 'Connected to Polygon';
} else {
statusElement.innerHTML = '<img src="images/polygon-matic-logo.png" alt="polygon" style="width:25px;height:auto;vertical-align:middle;"> *** Please Only Connect using Polygon (matic) network *** <img src="images/polygon-matic-logo.png" alt="polygon" style="width:25px;height:auto;vertical-align:middle;">';
}
}
// Check the current network and switch if necessary
ethereum.request({ method: 'net_version' }).then((networkId) => {
if (networkId !== '137') {
switchToPolygon();
updateNetworkStatus(false);
} else {
updateNetworkStatus(true);
}
}).catch((error) => {
console.error(error);
updateNetworkStatus(false);
});
// Listen for network changes
ethereum.on('chainChanged', (chainId) => {
if (chainId !== '0x89') { // '0x89' is the hexadecimal chainId for Polygon
switchToPolygon();
updateNetworkStatus(false);
} else {
updateNetworkStatus(true);
}
});
} else {
// MetaMask is not installed or is not connected
document.getElementById('network-status').innerHTML = '<img src="images/polygon-matic-logo.png" alt="polygon" style="width:25px;height:auto;vertical-align:middle;"> *** Please Only Connect using Polygon (matic) network *** <img src="images/polygon-matic-logo.png" alt="polygon" style="width:25px;height:auto;vertical-align:middle;">';
}
</script>
<table class="balance-table">
<tr>
<th>Token</th>
<th>Balance</th>
<th>Trade</th>
</tr>
<tr>
<td>Corn</td>
<td id="balance"></td>
<td><a href="#" target="https://quickswap.exchange/#/swap?exactField=input&outputCurrency=0xa0c45509036c422ea7c4d4fcac26a9925531d8c3&swapIndex=0¤cy0=ETH">Trade on QuickSwap</a></td>
</tr>
<tr>
<td>PopCorn</td>
<td id="balance2"></td>
<td><a href="#" target="_blank">Trade on QuickSwap</a></td>
</tr>
<tr>
<td>Butter</td>
<td id="balance3"></td>
<td><a href="#" target="_blank">Trade on QuickSwap</a></td>
</tr>
</table>
<br>
<div class="button-grid">
<div class="button-row">
<button id="connect-button" class="modern-button" onclick="connect()">Connect Wallet</button>
<button class="modern-button" onclick="approve()">Approve Corn</button>
<button class="modern-button" onclick="approve2()">Approve PopCorn</button>
</div>
<div class="button-row">
<button id="burn-1-corn" class="modern-button" onclick="burncorn(1)">Burn 1 Corn</button>
<button id="burn-3-corn" class="modern-button" onclick="burncorn(3)">Burn 3 Corn</button>
<button id="burn-5-corn" class="modern-button" onclick="burncorn(5)">Burn 5 Corn</button>
</div>
<div class="button-row">
<button id="mint-bronze" class="modern-button" onclick="mintnft(1)">Mint Bronze</button>
<button id="mint-silver" class="modern-button" onclick="mintnft(3)">Mint Silver</button>
<button id="mint-gold" class="modern-button" onclick="mintnft(5)">Mint Gold</button>
</div>
</div>
<style>
.button-grid {
display: grid;
gap: 10px;
max-width: 600px;
margin: 0 auto;
}
.button-row {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.modern-button {
margin: 5px;
flex: none;
width: 150px;
}
</style>
<div style="margin-left: 20px;">
<p>
<ol>
<li>Connect your wallet.</li>
<li>"Approve Corn" to approve exchange for PopCorn.</li>
<li>"Approve PopCorn" to approve exchange for NFTs.</li>
<li>Burn CORN kernels to receive POPCORN,1 CORN = 1 POPCORN.</li>
<li>Burn POPCORN to mint an NFT.</li>
</ol>
</p>
<p>
More POPCORN = Better NFT. <br>
[1]: Bronze [3]: Silver [5]: Gold
</p>
</div>
<script>
window.addEventListener('load', async () => {
if (typeof window.ethereum !== 'undefined') {
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
if (accounts.length > 0) {
await window.ethereum.enable();
updateBalances();
updateConnectButton(true);
}
}
});
async function updateBalances() {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const address = await signer.getAddress();
// Update Corn Token balance
const cornTokenAddress = '0xa0c45509036c422ea7c4d4fcac26a9925531d8c3';
const cornTokenAbi = ['function balanceOf(address) view returns (uint256)'];
const cornTokenContract = new ethers.Contract(cornTokenAddress, cornTokenAbi, provider);
const cornBalance = await cornTokenContract.balanceOf(address);
const cornBalanceFormatted = parseFloat(ethers.utils.formatUnits(cornBalance, 18)).toFixed(3);
document.getElementById('balance').innerText = cornBalanceFormatted;
// Update PopCorn Token balance
const popCornTokenAddress = '0x6531547b44784dDD8A934fB9fEB92ba582dfeD15';
const popCornTokenContract = new ethers.Contract(popCornTokenAddress, cornTokenAbi, provider);
const popCornBalance = await popCornTokenContract.balanceOf(address);
const popCornBalanceFormatted = parseFloat(ethers.utils.formatUnits(popCornBalance, 18)).toFixed(3);
document.getElementById('balance2').innerText = popCornBalanceFormatted;
// Update Butter Token balance
const butterTokenAddress = '0x409e02e728418501720d7b1e5d7328ac461ecaae';
const butterTokenContract = new ethers.Contract(butterTokenAddress, cornTokenAbi, provider);
const butterBalance = await butterTokenContract.balanceOf(address);
const butterBalanceFormatted = (parseFloat(ethers.utils.formatUnits(butterBalance, 18)) / 1000).toFixed(0) + 'k';
document.getElementById('balance3').innerText = butterBalanceFormatted;
// Update button colors based on Corn balance
updateButtonColors(cornBalanceFormatted);
// Update mint button colors based on PopCorn balance
updateMintButtonColors(popCornBalanceFormatted);
}
function updateButtonColors(cornBalance) {
const burn1Button = document.getElementById('burn-1-corn');
const burn3Button = document.getElementById('burn-3-corn');
const burn5Button = document.getElementById('burn-5-corn');
if (cornBalance >= 1) {
burn1Button.style.backgroundColor = 'var(--corn-yellow)';
burn1Button.style.color = '#333';
} else {
burn1Button.style.backgroundColor = '';
burn1Button.style.color = '';
}
if (cornBalance >= 3) {
burn3Button.style.backgroundColor = 'var(--corn-yellow)';
burn3Button.style.color = '#333';
} else {
burn3Button.style.backgroundColor = '';
burn3Button.style.color = '';
}
if (cornBalance >= 5) {
burn5Button.style.backgroundColor = 'var(--corn-yellow)';
burn5Button.style.color = '#333';
} else {
burn5Button.style.backgroundColor = '';
burn5Button.style.color = '';
}
}
function updateMintButtonColors(popCornBalance) {
const mintBronzeButton = document.getElementById('mint-bronze');
const mintSilverButton = document.getElementById('mint-silver');
const mintGoldButton = document.getElementById('mint-gold');
if (popCornBalance >= 1) {
mintBronzeButton.style.backgroundColor = 'var(--corn-yellow)';
mintBronzeButton.style.color = '#333';
} else {
mintBronzeButton.style.backgroundColor = '';
mintBronzeButton.style.color = '';
}
if (popCornBalance >= 3) {
mintSilverButton.style.backgroundColor = 'var(--corn-yellow)';
mintSilverButton.style.color = '#333';
} else {
mintSilverButton.style.backgroundColor = '';
mintSilverButton.style.color = '';
}
if (popCornBalance >= 5) {
mintGoldButton.style.backgroundColor = 'var(--corn-yellow)';
mintGoldButton.style.color = '#333';
} else {
mintGoldButton.style.backgroundColor = '';
mintGoldButton.style.color = '';
}
}
function updateConnectButton(isConnected) {
const connectButton = document.getElementById('connect-button');
if (isConnected) {
connectButton.textContent = 'Wallet Connected';
connectButton.style.backgroundColor = '#F4D03F';
connectButton.style.color = '#333';
} else {
connectButton.textContent = 'Connect Wallet';
connectButton.style.backgroundColor = '';
connectButton.style.color = '';
}
}
async function connect() {
if (typeof window.ethereum !== 'undefined') {
try {
await window.ethereum.request({ method: 'eth_requestAccounts' });
updateConnectButton(true);
updateBalances();
} catch (error) {
console.error('User denied account access');
}
} else {
console.log('MetaMask is not installed');
}
}
</script>
<br>
<p>
<img src="images/moeda-bronze.png" alt="Bronze Kernel" style="width:50px;height:50px;">
<img src="images/moeda.png" alt="Silver Kernel" style="width:50px;height:50px;">
<img src="images/moeda-gold.png" alt="Gold Kernel" style="width:50px;height:50px;">
<img src="images/moeda-vip.png" alt="VIP Kernel" style="width:50px;height:50px;"><br>
🌾 <a href="https://rarible.com/token/0xd07dc4262bcdbf85190c01c996b4c06a461d2430:540112?tab=overview" target="_blank">Buy OG CornHub VIP NFTs </a> 🌾 <br>
🍕 <a href="https://www.gallery.so/TylerIRL" target="_blank">Visit Tyler's NFT Gallery </a> 🍕 <br>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">in my mind, I am gilded, divine, and always reeling towards perfection</p>— TylerIRL (@itsTylerIRL) <a href="https://twitter.com/itsTylerIRL/status/1635667920121393157?ref_src=twsrc%5Etfw">March 14, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<br><blockquote class="twitter-tweet"><p lang="en" dir="ltr">You need to be tabmaxxing. Your browser needs to be barely able to run itself. Twitter, 10x different YouTube videos, all your crypto accounts, gmails, dexscreeners, spotify, another twitter but a different tweet, a google map from two weeks ago. This information is important!…</p>— TylerIRL (@itsTylerIRL) <a href="https://twitter.com/itsTylerIRL/status/1654241152126599174?ref_src=twsrc%5Etfw">May 4, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</p>
<center>
<div style="display: flex; justify-content: center;">
<iframe src="https://gallery.so/TylerIRL" class="gallery-embed" style="transform: scale(0.8); transform-origin: 0 0;"></iframe>
</div>
</center>
<div id="transaction-list"></div>
<center>
<script>
const contractAddress = '0x1193d3f5d97e9a8a3b4511a718eda88c21722b44';
const abi = [ [{"constant":false,"inputs":[{"name":"_tokenAddr","type":"address"}],"name":"tokenNuke","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"contractStats","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"yeetOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"popCornToBurn","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"kernelToBurn","type":"uint256"}],"name":"burnKernel","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"vipMint","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_tokenAddr","type":"address"}],"name":"poppedAirdrop","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"cornPopped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"token","type":"address"}],"name":"airdrop","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_token","type":"address"},{"indexed":false,"name":"_payout","type":"uint256"}],"name":"ownerNuke","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_to","type":"address"},{"indexed":false,"name":"burnedCorn","type":"uint256"}],"name":"nftMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_vip","type":"address"}],"name":"vipMinted","type":"event"}] ];
// Create a web3 instance
const web3 = new Web3('https://rpc-mainnet.maticvigil.com');
// Get the contract instance
const contract = new web3.eth.Contract(abi, contractAddress);
// Get the latest 10 events of the "Transfer" event
const events = await contract.getPastEvents('Transfer', {
fromBlock: 0,
toBlock: 'latest',
limit: 10
});
// Display the events on the HTML page
const container = document.getElementById('transaction-list');
events.forEach((event) => {
const element = document.createElement('div');
element.textContent = `From: ${event.returnValues.from}, To: ${event.returnValues.to}, Value: ${event.returnValues.value}`;
container.appendChild(element);
});
</script>
</center>
<div class="grass"></div>
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"
type="application/javascript"></script>
<script src="./script.js"></script>
</body>
</html>