forked from sep20tokens/sep20tokens.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
211 lines (191 loc) · 7.05 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
<!DOCTYPE html>
<html>
<head>
<title>SEP20 Tokens</title>
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
<link rel="stylesheet" href="./styles.css">
<script src="assets/web3.min.js"></script>
<script src="assets/abi.js"></script>
<script>
const web3 = new Web3(Web3.givenProvider || 'https://global.uat.cash');
const explorerUrl = 'https://www.smartscan.cash/address/';
function enableEthereum() {
if (typeof window.ethereum === 'undefined') {
alert("Your browser does not have a wallet plugin");
return
} else {
window.ethereum.enable();
}
}
async function getTokenInfo() {
enableEthereum();
const address = document.getElementById('token-address').value;
if (address === "") return;
const contract = new web3.eth.Contract(abi, address);
contract.methods.name().call((err, result) => {
document.getElementById('tokenName').innerHTML = '<li>Name: '+result+'</li>';
});
contract.methods.symbol().call((err, result) => {
document.getElementById('tokenSymbol').innerHTML = '<li>Symbol: <a href="'+explorerUrl+address+'" target="_blank">'+result+'</a></li>';
});
contract.methods.decimals().call((err, result) => {
document.getElementById('tokenDecimals').innerHTML = '<li>Decimals: '+result+'</li>';
});
}
async function smartBCHAdd(mainnet = true) {
enableEthereum();
const chainId = mainnet ? '0x2710' : '0x2711';
const chainName = mainnet ? 'SmartBCH Mainnet' : 'SmartBCH Testnet';
let rpcUrls;
if (mainnet) {
rpcUrls = [
"https://global.uat.cash",
"https://smartbch.greyh.at",
"https://smartbch.fountainhead.cash/mainnet:8545",
"https://rpc.uatvo.com:8545"
];
} else {
rpcUrls = ["https://moeing.tech:9545", "http://35.220.203.194:8545"];
}
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId }],
});
} catch (switchError) {
// This error code indicates that the chain has not been added to MetaMask.
if (switchError.code === 4902) {
try {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId,
chainName,
blockExplorerUrls: ['https://www.smartscan.cash/'],
rpcUrls,
nativeCurrency: {
name: 'BCH',
symbol: 'BCH',
decimals: 18,
},
}],
});
} catch (addError) {
// handle "add" error
}
}
// handle other "switch" errors
}
}
async function tokenAdd(address, symbol, decimals, image) {
enableEthereum();
try {
// wasAdded is a boolean. Like any RPC method, an error may be thrown.
const wasAdded = await ethereum.request(
{
method: 'wallet_watchAsset',
params: {
type: 'ERC20',
options: {
address,
symbol,
decimals,
image
},
},
}
);
if (wasAdded) {
alert('Succeed to add the token at '+tokenAddress);
} else {
alert('Fail to add the token at '+tokenAddress);
}
} catch (error) {
console.log(error);
}
}
document.addEventListener("DOMContentLoaded", async function() {
const mainnet = 10000;
const testnet = 10001;
const mainnetList = ['<tr class="header"><th>Logo</th><th>Symbol</th><th>Address</th><th>Decimals</th><th> </th></tr>'];
const testnetList = ['<tr class="header"><th>Logo</th><th>Symbol</th><th>Address</th><th>Decimals</th><th> </th></tr>'];
let tokensObj = {};
try {
const resp = await fetch("./smartbch.tokenlist.json");
tokensObj = await resp.json();
} catch(e) {
console.log(e);
}
if (tokensObj.timestamp) {
document.getElementById('listTimestamp').innerHTML = '<code>'+tokensObj.timestamp+'</code>';
}
if (tokensObj.version) {
const version = tokensObj.version.major+'.'+tokensObj.version.minor+'.'+tokensObj.version.patch;
document.getElementById('listVersion').innerHTML = '<code>'+version+'</code>';
}
if (tokensObj.tokens && tokensObj.tokens.length > 0) {
tokensObj.tokens.map(t => {
const logoUri = '<img src="'+t.logoURI+'" width="32" height="32" />';
const addToWallet = 'javascript:tokenAdd(\''+t.address+'\',\''+t.symbol+'\','+t.decimals+',\''+t.logoURI+'\')"';
if (t.chainId === mainnet) {
mainnetList.push('<tr><td>'+logoUri+'</td><td><a title="'+t.name+'" class="symbol" href="'+explorerUrl+t.address+'" target="_blank">'+t.symbol+'</a></td>');
mainnetList.push('<td><span title="click to copy" class="copy" onclick="navigator.clipboard.writeText(\''+t.address+'\')"><code>'+t.address+'</code></span></td>');
mainnetList.push('<td class="number">'+t.decimals+'</td>');
mainnetList.push('<td><a title="Add this asset to your wallet" href="'+addToWallet+'">Add</a></td></tr>');
}
if (t.chainId === testnet) {
testnetList.push('<tr><td>'+logoUri+'</td><td><a title="'+t.name+'" class="symbol" href="'+explorerUrl+t.address+'" target="_blank">'+t.symbol+'</a></td>');
testnetList.push('<td><span title="click to copy" class="copy" onclick="navigator.clipboard.writeText(\''+t.address+'\')"><code>'+t.address+'</code></span></td>');
testnetList.push('<td class="number">'+t.decimals+'</td>');
testnetList.push('<td><a title="Add this asset to your wallet" href="'+addToWallet+'">Add</a></td></tr>');
}
});
}
document.getElementById('mainnetTokenTbl').innerHTML = mainnetList.join("");
document.getElementById('testnetTokenTbl').innerHTML = testnetList.join("");
});
</script>
</head>
<body>
<div class="normal">
<h1 style="text-align: center;">SEP20 Tokens</h1>
<p>Here are some known SEP20 tokens on smartBCH. You can view these tokens in the <a href="https://www.smartscan.cash">browser</a>, or add them to your wallet plugin as an asset to watch.</p>
<b>Token List</b>:<br/>
<ul>
<li>Download: <a href="./smartbch.tokenlist.json" target="_blank">JSON file</a></li>
<li>Version: <span id="listVersion"></span></li>
<li>Created: <span id="listTimestamp"></span></li>
</ul>
<p>
<h2 style="text-align: center;">SmartBCH mainnet and testnet blockchains</h2>
To send and receive SEP-20 tokens you need first to add the proper blockchain
to your Metamask wallet.
<ul>
<li>Add <a href="javascript:smartBCHAdd();">SmartBCH mainnet</a> blockchain</li>
<li>Add <a href="javascript:smartBCHAdd(false);">SmartBCH testnet</a> blockchain</li>
</ul>
</p>
<p>
<h2 style="text-align: center;">Get token information by address</h2>
Address (0x....):
<input type="text" maxlength="128" size="64" id="token-address" />
<a href="javascript:getTokenInfo();">Get Info</a>
<ul>
<span id="tokenName"></span>
<span id="tokenSymbol"></span>
<span id="tokenDecimals"></span>
</ul>
</p>
<p>
<h2 style="text-align: center;">Mainnet SEP20 Tokens</h2>
<table id="mainnetTokenTbl"></table>
</p>
<p>
<h2 style="text-align: center;">Testnet (Amber) SEP20 Tokens</h2>
<table id="testnetTokenTbl"></table>
</p>
<p>You can also view some <a href="app.html">known dApps' addresses</a>.</p>
<p><a href="tools.html">List of SmartBCH ready tools</a> is also available.</p>
</div>
</body>
</html>