-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (23 loc) · 984 Bytes
/
script.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
`use strict`;
// For older browsers:
typeof window.addEventListener === `undefined` && (window.addEventListener = (e, cb) => window.attachEvent(`on${e}`, cb));
window.addEventListener(`load`, () => {
const $ = (id) => document.getElementById(id);
$(`connect`).addEventListener(`click`, async () => {
if (typeof window.ethereum !== `undefined`) {
try {
const currentAccounts = await window.ethereum.request({ method: `eth_requestAccounts`, });
$(`wallet`).innerText = currentAccounts[0];
} catch (e) {
alert(`Something went wrong with eth_requestAccounts.`);
$(`wallet`).innerText = `Not Connected.`;
}
} else {
alert(`window.ethereum is undefined.`);
$(`wallet`).innerText = `Not Connected.`;
}
});
$(`sign`).addEventListener(`click`, () => {
alert(`Message signing is yet to be implemented.`);
});
});