-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
117 lines (102 loc) · 3.92 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
<HTML>
<head>
<title>Token Request Generator</title>
<script src="inc/web3.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="inc/bootstrap.min.css">
<script src="inc/jquery.min.js"></script>
<script src="inc/bootstrap.min.js"></script>
<script>
function start() {
if (window.ethereum) {
window.web3 = new Web3(ethereum);
// Request account access if needed
ethereum.enable( function(error) {
console.log("Denied")
return false;
});
// Acccounts now exposed
return true;
// User denied account access...
}
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
// if (typeof web3 !== 'undefined') {
// // Use Mist/MetaMask's provider
// web3js = new Web3(web3.currentProvider);
// return true;
// } else {
// web3 = new Web3();
// web3.setProvider(new web3.providers.HttpProvider('https://api.myetherwallet.com/eth'));
// return true;
// }
// Now you can start your app & access web3 freely:
//startApp()
}
function getBalance(e) {
e && e.preventDefault();
if (!start()) return;
var addr = $("#address").val();
var tokenAddress = "0xeAb43193CF0623073Ca89DB9B712796356FA7414";
var tknAddress = (addr).substring(2);
var contractData = ('0x70a08231000000000000000000000000' + tknAddress);
web3.eth.call({
to: tokenAddress, // Contract address, used call the token balance of the address in question
data: contractData // Combination of contractData and tknAddress, required to call the balance of an address
}, function (err, result) {
if (result) {
//var tokens = web3.utils.toBN(result).toString(); // Convert the result to a usable number string
//console.log('Tokens Owned: ' + web3.utils.fromWei(tokens, 'ether')); // Change the string to be in Ether not Wei, and show it in the console
$("#balance").val(web3.fromWei(result))
$('#etherscan-token-account-link').attr('href', `https://etherscan.io/token/${tokenAddress}?a=${addr}`);
$('#etherscan-token-account-link').show();
console.log(web3.fromWei(result))
}
else {
console.log(err); // Dump errors here
}
});
}
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>Check GOLDX Balance</h1>
<h2>查看您的 GOLDX 余额</h2>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<img src="images/download-metamask-dark.png" class="img-thumbnail" id="mm" alt="Metamask" style="display:none;">
</div>
</div>
<div class="row">
<form id="the-only-form" action="#">
<div class="col-xs-12 col-md-8 col-lg-4">
<div class="form-group">
<label>Address 以太坊地址</label>
<input class="form-control" name="address" id="address" width=50></input>
</div>
</div>
<div class="col-xs-12 col-md-4 col-lg-3">
<label> </label>
<button id="selToken" class="btn btn-primary btn-block" type="button" onclick="getBalance();">Check Balance 查询余额!</button>
</div>
</form>
</div>
<div class="row">
<div class="col-xs-12 col-md-8 col-lg-4 form-group">
<label>GOLDX Balance 黄金代币余额</label>
<input class="form-control" name=token id="balance" readonly></input>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<a href="#" id="etherscan-token-account-link" style="display: none;">Show it on etherscan. 前往 etherscan >></a>
</div>
</div>
</div>
</body>
</html>