-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
27 lines (24 loc) · 801 Bytes
/
main.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
let accounts;
window.onload= () => {
if(window.ethereum)
document.getElementById("display").innerText = "Wallet Installed";
else
document.getElementById("display").innerText = "Wallet Installed First";
}
const enablEth = async() => {
accounts = await window.ethereum.request({method : 'eth_requestAccounts'}).catch((err) => {
})
document.getElementById("display").innerText = "Account Address :" + accounts[0];
}
const ethBalance = async () =>{
let balance = await window.ethereum.request({method: 'eth_getBalance',
params:[
accounts[0]
]
}).catch((err) =>{
console.error(err);
});
balance = parseInt(balance)/Math.pow(10,18);//convert to eth
console.log(balance);
document.getElementById("display").innerText = "Account Balance :" +balance;
}