-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKUBCS201frontend.html
More file actions
548 lines (496 loc) · 16.5 KB
/
KUBCS201frontend.html
File metadata and controls
548 lines (496 loc) · 16.5 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
<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"
integrity="sha256-nWBTbvxhJgjslRyuAKJHK+XcZPlCnmIAAMixz6EefVk=" crossorigin="anonymous"></script>
<script type="text/javascript">
var contractAddress = '0x2862788B5CE0b980A8D14A41Df86eBE09450a5DD';
var tokenDecimals = 18;
var abi = [
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "string",
"name": "_symbol",
"type": "string"
},
{
"internalType": "uint256",
"name": "_tokenSupply",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getName",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getSymbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getTotalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_wallet",
"type": "address"
}
],
"name": "getWalletName",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
}
],
"name": "setMyWalletName",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
var network = "";
var userAccount = '';
var warning = "";
</script>
<script type="text/javascript">
window.addEventListener('load', function () {
// Modern dapp browsers...
if (window.ethereum) {
web3 = new Web3(ethereum);
window.ethereum.on('chainChanged', (_chainId) => startApp());
try {
// Request account access if needed
ethereum.enable().then(result => {
// Now you can start your app & access web3 freely:
startApp()
})
}
catch (err) {
console.log(err);
}
}
// Legacy dapp browsers, checking if Web3 has been injected by the browser (Mist/MetaMask)
else if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
web3 = new Web3(web3.currentProvider);
// Now you can start your app & access web3 freely:
startApp();
} else {
console.log('No web3? You should consider trying MetaMask!')
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
web3 = new Web3(new Web3.providers.HttpProvider("https://kovan.infura.io/"));
// Now you can start your app & access web3 freely:
startApp();
}
})
// Get current network
function startApp() {
web3.eth.net.getId().then(netId => {
// web3.version.getNetwork((err, netId) => {
console.log('netId: ' + netId)
switch (netId) {
case 1:
network = 'Mainnet';
warning = 'please switch your network to Rinkeby';
break
case 2:
network = 'Deprecated Morden';
warning = 'please switch your network to Rinkeby';
break
case 3:
network = 'Ropsten';
warning = 'please switch your network to Rinkeby';
break
case 4:
network = 'Rinkeby';
warning = '';
break
case 42:
network = 'Kovan';
warning = 'please switch your network to Rinkeby';
break
default:
network = 'Unknown';
warning = 'please switch your network to Rinkeby';
}
$("#eth_network").text(network);
$("#warning").text(warning);
web3.eth.getAccounts().then(accounts => {
userAccount = accounts[0];
$("#eth_address").text(userAccount);
$("#fromAddress").val(userAccount);
reloadInfo();
})
})
}
function reloadInfo() {
// Wallet
try {
getName();
setContractAddress();
getWalletName();
balanceOf();
getBalance();
getSymbol();
let contract = new web3.eth.Contract(abi, contractAddress)
console.log('contract', contract)
contract.methods.symbol().call().then(symbol => {
console.log('symbol', symbol)
$("#token_name").html(symbol)
})
// Get balance
contract.methods.balanceOf(userAccount).call().then(balance => {
console.log('balance', balance.toString())
// Get decimals
contract.methods.decimals().call().then(decimals => {
console.log('decimals', decimals.toString())
tokenDecimals = decimals
$("#token_decimals").html('( decimals: ' + tokenDecimals + ' )')
balance = balance / (10 ** decimals)
console.log(balance.toString())
$("#token_balance").html(balance)
})
})
$("#token_address").html(contractAddress)
}
catch (err) {
console.log(err);
}
}
// Get block info
function getBlock() {
web3.eth.getBlock(48, function (error, result) {
if (!error) {
console.log(JSON.stringify(result));
$("#balance").html(JSON.stringify(result));
} else {
console.error(error);
}
})
}
function setContractAddress() {
$("#contract_address").html(contractAddress)
}
//Get Contract name
function getName() {
let contract = new web3.eth.Contract(abi, contractAddress)
contract.methods.getName().call().then(name => {
console.log(name.toString());
$("#token_name").html(name)
})
}
function getSymbol() {
let contract = new web3.eth.Contract(abi, contractAddress)
contract.methods.getSymbol().call().then(symbol => {
console.log(symbol.toString());
$("#symbol").html(symbol)
})
}
// Get balance of KUBCS
function balanceOf() {
let contract = new web3.eth.Contract(abi, contractAddress)
contract.methods.balanceOf(userAccount).call().then(result => {
console.log(result.toString());
$("#token_balance").html(result)
})
}
// Get account balance ethers
function getBalance() {
web3.eth.getBalance(userAccount).then(result => {
$("#balance").html(web3.utils.fromWei(result));
}); // getbalance account
}
function getWalletName() {
let contract = new web3.eth.Contract(abi, contractAddress)
contract.methods.getWalletName(userAccount).call().then(result => {
console.log(result.toString());
$("#wallet_name").html(result)
})
}
function setMyWalletName() {
let named = $("#walletName").val()
let sender = userAccount
let option = {
from: sender,
}
let contract = new web3.eth.Contract(abi, contractAddress)
contract.methods.setMyWalletName(named).send(option)
.on('error', (error) => {
console.error(error)
$("#status_value_2").text('Failed').css("color", "red");
})
// Transaction already saved to mempool
.on('transactionHash', (transactionHash) => {
// Show tx hash
console.log(transactionHash)
let link = "https://" + network.toLowerCase() + ".etherscan.io/tx/" + transactionHash
$("#tx_set_name_link").attr("href", link)
$("#tx_set_name_link").text(link)
// Clear status
$("#status_value_2").text('pending . . .');
})
// Transaction got confirmed
.on('confirmation', (confirmationNumber) => {
$("#status_value_2").text('Success').css("color", "green");
reloadInfo();
callback(ok);
})
}
</script>
<!-- Ether transfer -->
<script type="text/javascript">
function tokenTransfer() {
let toAddress = $("#toAddress").val()
let amountInText = $("#amount").val()
console.log('toAddress: ' + toAddress)
console.log('amountInText: ' + amountInText)
let sender = userAccount;
let amount = web3.utils.toBN(amountInText)
let option = {
from: sender,
// params: 'send token'
}
let contract = new web3.eth.Contract(abi, contractAddress)
console.log('contract', contract)
contract.methods.transfer(toAddress, amount.toString()).send(option)
// web3.eth.sendTransaction(
// {
// from: sender,
// to: toAddress,
// value: amount
// }
// )
.on('error', (error) => {
console.error(error)
$("#status_value").text('Failed').css("color", "red");
})
// Transaction already saved to mempool
.on('transactionHash', (transactionHash) => {
// Show tx hash
console.log(transactionHash)
let link = "https://" + network.toLowerCase() + ".etherscan.io/tx/" + transactionHash
$("#tx_link").attr("href", link)
$("#tx_link").text(link)
// Clear status
$("#status_value").text('pending . . .');
})
// Transaction got confirmed
.on('confirmation', (confirmationNumber, receipt) => {
console.log('confirmationNumber', confirmationNumber)
console.log(receipt);
$("#status_value").text('Success').css("color", "green");
reloadInfo();
callback(ok);
})
}
function openContractOnEtherScan() {
let url = 'https://' + network + '.etherscan.io/token/' + contractAddress
window.open(url, '_blank');
}
function openUserAddressOnEtherScan() {
let url = 'https://' + network + '.etherscan.io/address/' + userAccount
window.open(url, '_blank');
}
</script>
</head>
<body>
<div class="container pt-5 px-0">
<h1 class="px-3">
<span>Network:</span>
<span id="eth_network"></span>
<span id="warning" class="bg-danger text-white fs-3"></span>
</h1>
<div class="row justify-content-between">
<div class="col px-3">
<div class="text-bg-info p-3">
<table class="wallet">
<h1>Wallet</p>
<tbody class="table text-bg-info">
<tr>
<td>account:</td>
<td class="table-value"><span id="eth_address"></span></td>
</tr>
<tr>
<td>wallet name:</td>
<td class="table-value"><span id="wallet_name">noname</span></td>
</tr>
<tr>
<td>balance:</td>
<td class="table-value"><span id="balance"></span></td>
</tr>
<tr>
<td>Token Name:</td>
<td class="table-value"><span id="token_name"></span></td>
</tr>
<tr>
<td>Symbol:</td>
<td class="table-value"><span id="symbol"></span></td>
</tr>
<tr>
<td>token balance:</td>
<td class="table-value"><span id="token_balance"></span></td>
</tr>
<tr>
<td>contract address:</td>
<td><span class="table-value" id="contract_address"></span></td>
</tr>
</tbody>
</table>
</div>
<div class="text-bg-info p-3 mt-3">
<h1 class="title">Set wallet name</h1>
<label>Change to:</label>
<input id="walletName" class="input form-control" type="text" placeholder="name" value="">
<button class="btn btn-primary mt-3" onclick="javascript:setMyWalletName()">Submit</button>
<p>
<span>Your pending transaction: </span>
<span>
<a id="tx_set_name_link" target="_blank"></a>
</span>
</p>
<p>
<span>Status: </span>
<span id="status_value_2">-</span>
</p>
</div>
</div>
<div class="col px-0">
<div class="text-bg-info p-3">
<h1 class="title">Transfer</h1>
<div class="field">
<label>From</label>
<input id="fromAddress" class="input form-control" disabled="true" type="text" placeholder="from address" value="">
</div>
<div class="field">
<label>To</label>
<input id="toAddress" class="input form-control" type="text" placeholder="to address" value="">
</div>
<div class="field mb-3">
<label>Amount</label>
<input id="amount" class="input form-control" type="text" placeholder="amount to transfer" value="">
</div>
<div>
<button class="btn btn-primary" onclick="javascript:tokenTransfer()">Submit</button>
</div>
<div class="mt-2">
<div id="transaction">
<p>
<span>Your pending transaction: </span>
<span>
<a id="tx_link" target="_blank"></a>
</span>
</p>
</div>
<p>
<span>Status: </span>
<span id="status_value">-</span>
</p>
</div>
</div>
</div>
</div>
<footer style="display: flex; justify-content: center;">
<a href="https://web.facebook.com/KUBCS" target="_blank" class="m-4"><img src="https://cdn-icons-png.flaticon.com/512/733/733547.png" width="60" height="60"></a>
<a href="https://twitter.com/KUBCS2022" target="_blank" class="m-4"><img src=" https://cdn-icons-png.flaticon.com/512/124/124021.png" width="60" height="60"></a>
<a href="https://discord.gg/RKUDdDSJ8v" target="_blank" class="m-4"><img src="https://cdn-icons-png.flaticon.com/512/2111/2111370.png" width="66" height="66"></a>
</footer>
</div>
</body>
</html>