-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.html
66 lines (51 loc) · 1.66 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
<html>
<center><b><p style="font-size:50px">DeFi Loan with Polygon Example</p></b></center>
Current Value in Lending Pool:
<p>
<form>
<label for="deposit">Deposit Amount:</label><br>
<input type="text" id="deposit" name="deposit"><br>
<input type="submit" value="Submit">
</form>
<form>
<label for="withdrawal">Withdrawal Amount:</label><br>
<input type="text" id="withdrawal" name="withdrawal"><br>
<input type="submit" value="Submit">
</form>
<h1 id="accounts">test</h1>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="https://cdn.rawgit.com/ethereum/web3.js/develop/dist/web3.min.js"></script>
<script type="text/javascript">
window.addEventListener('load', function() {
if (typeof web3 !== 'undefined') {
console.log('Web3 Detected! ' + web3.currentProvider.constructor.name)
window.web3 = new Web3(web3.currentProvider);
} else {
console.log('No Web3 Detected... get Metamask');
}
})
function getBalance() {
var wei, balance
try {
web3.eth.getAccounts(function(err, accounts) {
web3.eth.getBalance(accounts[0], function(error, wei) {
if (!error) {
var balance = web3.fromWei(wei, 'ether');
document.getElementById("output").innerHTML = balance + " ETH";
}
})
});
} catch (err) {
document.getElementById("output").innerHTML = err;
}
}
</script>
</head>
<body>
<button type="button" onClick="getBalance();">Get Balance</button>
<br />
<br />
<div id="output"></div>
</body>
</html>