-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathtoken-wallet.html
231 lines (193 loc) · 18.3 KB
/
token-wallet.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.2.3/milligram.min.css">
</head>
<body class="container" style="padding-top: 3%;">
<h2><a href="index.html">ethjs</a></h2>
<h4>Token Wallet</h4>
<hr />
<div class="row">
<div class="column">
<label>Your Account<label>
<blockquote><p><em id="accountAddress">Loading..</em></p></blockquote>
</div>
<div class="column">
<label>Token Balance</label>
<blockquote><p><em id="tokenBalance">Loading..</em> (<span class="tokenSymbol"></span>)</p></blockquote>
</div>
<div class="column">
<label>Token Name</label>
<blockquote><p><em id="tokenName">Loading..</em></p></blockquote>
</div>
</div>
<hr />
<div class="row">
<div class="column">
<label>Transfer To</label>
<input type="text" id="transferAddress" placeholder="0xcc136826fbd5192c10bba496af42906a7e3b91f8" />
</div>
<div class="column">
<label>Token Amount</label>
<input type="number" id="transferAmount" placeholder="4700" />
</div>
<div class="column">
<br />
<button id="transferTokens">Transfer Tokens</button>
</div>
</div>
<div id="transferResponse" style="padding: 20px; display: none; border: 1px solid #9b4dca">
</div>
<hr />
<div class="row">
<div class="column">
<label>Address</label>
<input type="text" id="balanceAddress" placeholder="0xcc136826fbd5192c10bba496af42906a7e3b91f8" />
</div>
<div class="column">
<br />
<button id="balanceOf">Get Balance</button>
</div>
</div>
<div id="balanceResponse" style="padding: 20px; display: none; border: 1px solid #9b4dca">
</div>
<hr />
<script type="text/javascript" src="ethereumjs-testrpc.js"></script>
<script type="text/javascript" src="ethjs.js"></script>
<script type="text/javascript">
var eth = new Eth(TestRPC.provider());
var el = function(id){ return document.querySelector(id); };
/*
// uncomment to enable MetaMask support:
if (typeof window.web3 !== 'undefined' && typeof window.web3.currentProvider !== 'undefined') {
eth.setProvider(window.web3.currentProvider);
} else {
eth.setProvider(provider); // set to TestRPC if not available
}
*/
eth.accounts().then(function(accounts){
el('#accountAddress').innerHTML = accounts[0];
var HumanStandardTokenBytecode = '6060604052604060405190810160405280600481526020017f48302e310000000000000000000000000000000000000000000000000000000081526020015060039080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200008b57805160ff1916838001178555620000bc565b82800160010185558215620000bc579182015b82811115620000bb5782518255916020019190600101906200009e565b5b509050620000e491905b80821115620000e0576000816000905550600101620000c6565b5090565b505034620000005760405162000fae38038062000fae833981016040528080519060200190919080518201919060200180519060200190919080518201919060200150505b83600560003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550836004819055508260009080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620001ac57805160ff1916838001178555620001dd565b82800160010185558215620001dd579182015b82811115620001dc578251825591602001919060010190620001bf565b5b5090506200020591905b8082111562000201576000816000905550600101620001e7565b5090565b505081600160006101000a81548160ff02191690837f01000000000000000000000000000000000000000000000000000000000000009081020402179055508060029080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200029257805160ff1916838001178555620002c3565b82800160010185558215620002c3579182015b82811115620002c2578251825591602001919060010190620002a5565b5b509050620002eb91905b80821115620002e7576000816000905550600101620002cd565b5090565b50505b505050505b610cac80620003026000396000f3606060405236156100a7576000357c01000000000000000000000000000000000000000000000000000000009004806306fdde03146100ac578063095ea7b31461012757806318160ddd1461016357806323b872dd14610186578063313ce567146101cb57806354fd4d50146101f157806370a082311461026c57806395d89b411461029d578063a9059cbb14610318578063cae9ca5114610354578063dd62ed3e146103d3575b610000565b34610000576100b961040d565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156101195780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b346100005761014b60048080359060200190919080359060200190919050506104ab565b60405180821515815260200191505060405180910390f35b3461000057610170610572565b6040518082815260200191505060405180910390f35b34610000576101b36004808035906020019091908035906020019091908035906020019091905050610578565b60405180821515815260200191505060405180910390f35b34610000576101d8610763565b604051808260ff16815260200191505060405180910390f35b34610000576101fe610776565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f16801561025e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34610000576102876004808035906020019091905050610814565b6040518082815260200191505060405180910390f35b34610000576102aa610848565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f16801561030a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b346100005761033c60048080359060200190919080359060200190919050506108e6565b60405180821515815260200191505060405180910390f35b34610000576103bb600480803590602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610a16565b60405180821515815260200191505060405180910390f35b34610000576103f76004808035906020019091908035906020019091905050610c50565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104a35780601f10610478576101008083540402835291602001916104a3565b820191906000526020600020905b81548152906001019060200180831161048657829003601f168201915b505050505081565b600081600660003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a3600190505b92915050565b60045481565b600081600560008673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610603575081600660008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b801561060f5750600082115b156107525781600560008573ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555081600560008673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600660008673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905061075c5661075b565b6000905061075c565b5b9392505050565b600160009054906101000a900460ff1681565b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561080c5780601f106107e15761010080835404028352916020019161080c565b820191906000526020600020905b8154815290600101906020018083116107ef57829003601f168201915b505050505081565b6000600560008373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b919050565b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108de5780601f106108b3576101008083540402835291602001916108de565b820191906000526020600020905b8154815290600101906020018083116108c157829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156109215750600082115b15610a065781600560003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600560008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610a1056610a0f565b60009050610a10565b5b92915050565b600082600660003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815260200150602e01905060405180910390207c0100000000000000000000000000000000000000000000000000000000900433853086604051857c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018280519060200190808383829060006004602084601f0104600302600f01f150905090810190601f168015610c1c5780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000876161da5a03f1925050501515610c4457610000565b600190505b9392505050565b6000600660008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b9291505056';
var HumanStandardTokenABI = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"_initialAmount","type":"uint256"},{"name":"_tokenName","type":"string"},{"name":"_decimalUnits","type":"uint8"},{"name":"_tokenSymbol","type":"string"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}];
var HumanStandardToken = eth.contract(HumanStandardTokenABI, HumanStandardTokenBytecode, { from: accounts[0], gas: 3000000 });
var tokenInstance = null;
var initialAmount = 49700000;
var tokenName = 'NickTokens';
var decimalUnits = 1000;
var tokenSymbol = 'NT';
function updateBalanceHTML() {
if(!tokenInstance) { return; }
tokenInstance.balanceOf(accounts[0]).then(function(tokenBalance){
el('#tokenBalance').innerHTML = tokenBalance[0].toString(10);
});
}
HumanStandardToken.new(initialAmount, tokenName, decimalUnits, tokenSymbol)
.then(function(txHash){
var checkTransactionInterval = setInterval(function(){
eth.getTransactionReceipt(txHash)
.then(function(receipt){
if (receipt) {
clearInterval(checkTransactionInterval);
tokenInstance = HumanStandardToken.at(receipt.contractAddress);
updateBalanceHTML();
el('#balanceOf').addEventListener('click', function(){
el('#balanceResponse').style.display = 'block';
tokenInstance.balanceOf(el('#balanceAddress').value)
.then(function(tokenBalance){
el('#balanceResponse').innerHTML = 'Token balance is: ' + tokenBalance[0].toNumber(10);
})
.catch(function(balanceError){
el('#balanceResponse').innerHTML = 'Hmm.. there was an error: ' + String(balanceError);
});
});
el('#transferTokens').addEventListener('click', function(){
el('#transferResponse').style.display = 'block';
tokenInstance.transfer(el('#transferAddress').value, el('#transferAmount').value)
.then(function(transferTxHash) {
el('#transferResponse').innerHTML = 'Transfering tokens with transaction hash: ' + String(transferTxHash);
})
.catch(function(transferError) {
el('#transferResponse').innerHTML = 'Hmm.. there was an error: ' + String(transferError);
});
});
tokenInstance.symbol().then(function(tokenSymbol){
el('.tokenSymbol').innerHTML = tokenSymbol[0];
});
tokenInstance.name().then(function(tokenName){
el('#tokenName').innerHTML = tokenName[0];
});
}
})
.catch(function(deploymentError){
el('#response').innerHTML = 'Hmm.. there was an error: ' + String(deploymentError);
});
}, 400);
})
.catch(function(deploymentError){
el('#response').innerHTML = 'Hmm.. there was an error: ' + String(deploymentError);
});
});
</script>
<br /><br />
<label>HumanStandardToken (EC20)</label>
<pre><code>
pragma solidity ^0.4.4;
contract HumanStandardToken {
function transfer(address _to, uint256 _value) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function HumanStandardToken(
uint256 _initialAmount,
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol
) {
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
totalSupply = _initialAmount; // Update total supply
name = _tokenName; // Set the name for display purposes
decimals = _decimalUnits; // Amount of decimals for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
string public name;
uint8 public decimals;
string public symbol;
string public version = 'H0.1';
uint256 public totalSupply;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
</code></pre>
</body>
</html>