-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (48 loc) · 1.34 KB
/
app.js
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
const web3 = new Web3(window.ethereum);
let account = null;
async function login() {
const accounts = await window.ethereum.request({
method: "eth_requestAccounts",
});
account = accounts[0];
document.getElementById("step-1").style.display = "none";
document.getElementById("step-2").style.display = "block";
alert("Logged as " + account);
}
async function addChain() {
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: "0x89",
chainName: "Polygon Mainnet",
nativeCurrency: {
name: "Matic",
symbol: "Matic",
decimals: 18, //In number form
},
rpcUrls: ["https://polygon-rpc.com"],
blockExplorerUrls: ["https://polygonscan.com/"],
},
],
});
document.getElementById("step-2").style.display = "none";
document.getElementById("step-3").style.display = "block";
}
async function addToken() {
const wasAdded = await window.ethereum.request({
method: "wallet_watchAsset",
params: {
type: "ERC20",
options: {
address: "0x25e54db7c4400d20b6ed2959db5020967486a980",
symbol: "ARK",
decimals: 4,
image: "https://i.imgur.com/DUxZiAV.jpg",
},
},
});
if (wasAdded) {
alert("¡Terminado!");
}
}