-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
81 lines (76 loc) · 2.77 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
<!DOCTYPE html>
<html lang="en-CA">
<head>
<title>$EDI Token Onboarding</title>
<meta charset="UTF-8" />
<head>
<link rel="shortcut icon" href="https://raw.githubusercontent.com/freight-trust/branding/master/logo_electric/Freight%20Trust%20%26%20Clearing%20Logo%40half.png" />
</head>
</head>
<body>
<h1>$EDI Token</h1>
<button id="onboard">Loading...</button>
<script src="https://cdn.jsdelivr.net/npm/@metamask/onboarding@1.0.0/dist/metamask-onboarding.bundle.js"></script>
<script>
window.addEventListener('DOMContentLoaded', () => {
const onboarding = new MetaMaskOnboarding();
const onboardButton = document.getElementById('onboard');
let accounts;
const updateButton = () => {
if (!MetaMaskOnboarding.isMetaMaskInstalled()) {
onboardButton.innerText = 'Click here to install MetaMask!';
onboardButton.onclick = () => {
onboardButton.innerText = 'Onboarding in progress';
onboardButton.disabled = true;
onboarding.startOnboarding();
};
} else if (accounts && accounts.length > 0) {
onboardButton.innerText = 'Connected';
onboardButton.disabled = true;
onboarding.stopOnboarding();
} else {
onboardButton.innerText = 'Connect';
onboardButton.onclick = async () => {
await window.ethereum.request({
method: 'eth_requestAccounts',
});
};
}
};
updateButton();
if (MetaMaskOnboarding.isMetaMaskInstalled()) {
window.ethereum.on('accountsChanged', (newAccounts) => {
accounts = newAccounts;
updateButton();
});
}
const tokenAddress = '0x49230c43f3343a509af16196a0f6be4d49175c48';
const tokenSymbol = 'EDI';
const tokenDecimals = 18;
const tokenImage = 'https://raw.githubusercontent.com/freight-trust/branding/master/logo_electric/Freight%20Trust%20%26%20Clearing%20Logo%40half.png';
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', // Initially only supports ERC20, but eventually more!
options: {
address: tokenAddress, // The address that the token is at.
symbol: tokenSymbol, // A ticker symbol or shorthand, up to 5 chars.
decimals: tokenDecimals, // The number of decimals in the token
image: tokenImage, // A string url of the token logo
},
},
});
if (wasAdded) {
console.log('Thanks for your interest!');
} else {
console.log('Your loss!');
}
} catch (error) {
console.log(error);
}
});
</script>
</body>
</html>