-
Notifications
You must be signed in to change notification settings - Fork 3
/
token.html
152 lines (132 loc) · 4.79 KB
/
token.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script language="javascript" type="text/javascript" src="./web3/dist/web3.min.js"></script>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="header">
<div class="header-right">
<a href="index.html">CREATE</a>
<a href="settings.html">SETTINGS</a>
<a class="active" href="#token.html">TOKEN</a>
</div>
</div>
<div class="container">
<h1>ERC20 TOKEN</h1>
<div class="column">
<div class="row">
<div class="col-25">
<label>Token Address</label>
</div>
<div class="col-75">
<input type="text" id="tokenAddress" placeholder="Token Address">
</div>
</div>
</div>
<div class="row">
<div class="col-25">
<label>Current User</label>
</div>
<div class="col-75">
<select id="currentUser"></select>
</div>
</div>
</div>
<br />
<div class="container">
<h2>APPROVE</h2>
<div class="column">
<div class="row">
<div class="col-25">
<label>Spender Address</label>
</div>
<div class="col-75">
<input type="text" id="spenderAddress" placeholder="Spender Address">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Token Amount</label>
</div>
<div class="col-75">
<input type="text" id="tokenAmount" placeholder="token Amount">
</div>
</div>
<div class="column">
<button id="approve">Approve</button>
<button id="allowance">Allowance</button>
<button id="balance">Balance</button>
<button id="owner">Owner</button>
</div>
</div>
</div>
<script>
var tokenABI;
var tokenAddress;
var tokenOwner;
var bountyAddress;
var bountyBG;
var token;
var el = function (id) { return document.querySelector(id); };
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
el('#approve').addEventListener('click', async () => {
await token.methods
.approve(el('#spenderAddress').value, el('#tokenAmount').value)
.send({from: el('#currentUser').value, gas: 3000000});
})
el('#allowance').addEventListener('click', async () => {
const allowance = await token.methods
.allowance(el('#currentUser').value, el('#spenderAddress').value)
.call();
console.log(allowance)
})
el('#balance').addEventListener('click', async () => {
const balance = await token.methods
.balanceOf(el('#currentUser').value)
.call();
console.log(balance)
})
el('#owner').addEventListener('click', async () => {
const owner = await token.methods
.getOwner()
.call();
console.log(owner)
})
function fillCurrentUser() {
return new Promise((resolve, reject) => {
web3.eth.getAccounts()
.then((accounts) => {
accounts.forEach(address => {
currentUser.innerHTML += '<option value="' + address + '">'
+ address + '</option>';
})
})
resolve(true);
})
}
function readContract() {
return new Promise((resolve, reject) => {
$.getJSON('./deploy/contracts.json', function(data) {
resolve(data)
})
})
}
async function main() {
const data = await readContract();
bountyAddress = data['bounty address']
tokenABI = data['token abi']
tokenAddress = data['token address']
tokenOwner = data['token owner']
token = new web3.eth.Contract(tokenABI, tokenAddress);
await fillCurrentUser();
$('#tokenAddress').val(tokenAddress);
$('#spenderAddress').val(bountyAddress);
}
main();
</script>
</body>