-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
132 lines (107 loc) · 3.33 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ethereum-Dapp</title>
</head>
<body>
<div class="text-center" style="margin-top:20%">
<label>Enter Your amount:</label>
<input type="text" id="amount"><br>
<span class="ml-1">This is your current amount: </span><span id="balance" class="btn btn-success"></span><br><br>
<button id="deposit" class="btn btn-primary">Deposit</button>
<button id="withdraw" class="btn btn-danger">Withdraw</button>
</div>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"></script>
<script>
var contract;
$(document).ready(function(){
web3 = new Web3(web3.currentProvider);
var address = "0x6AbF36bfeEe4201adfD8d21b5AFe9542700d3512";
var abi = [
{
"constant": true,
"inputs": [],
"name": "getBalance",
"outputs": [
{
"name": "",
"type": "int256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "amt",
"type": "int256"
}
],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "amt",
"type": "int256"
}
],
"name": "deposit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
];
contract = new web3.eth.Contract(abi,address);
contract.methods.getBalance().call().then(function(bal){
$('#balance').html(bal);
})
})
$('#deposit').click(function(){
var amt = 0;
amt = parseInt($('#amount').val());
web3.eth.getAccounts().then(function(accounts){
return contract.methods.deposit(amt).send({from: accounts[0]});
}).then(function(tx){
console.log(tx);
}).catch(function(tx){
console.log(tx);
});
});
$('#withdraw').click(function(){
var amt = 0;
amt = parseInt($('#amount').val());
web3.eth.getAccounts().then(function(accounts){
var acc = accounts[0];
return contract.methods.withdraw(amt).send({from: acc});
}).then(function(tx){
console.log(tx);
}).catch(function(tx){
console.log(tx);
})
})
</script>
</body>
</html>