Created
April 9, 2017 02:44
-
-
Save goodjoon/c6c1389a790a4c6ad5a6b0ee7f775f91 to your computer and use it in GitHub Desktop.
[HYUNDAI] Hyundai Token UI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>My Coin</title> | |
| <script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script> | |
| <script type="text/javascript" src="../bower_components/web3/dist/web3.js"></script> | |
| </head> | |
| <body> | |
| <h2>New Coin (Own Token) Example</h2> | |
| <div> | |
| <h3>Create New Coin</h3> | |
| Initial Supply : <input type="text" id="_initialSupply"/><br/> | |
| Coin Name : <input type="text" id="_coinName"/><br/> | |
| Decimal Units : <input type="text" id="_decimalUnits"/><br/> | |
| Coin Symbol : <input type="text" id="_coinSymbol"/><br/> | |
| <button id="btnCreate">Create</button> | |
| <h4>At</h4> | |
| <input type="text" id="_contractAddress" size="20"/> | |
| <button id="btnAt">At</button> | |
| <h4>Balance Check</h4> | |
| Address : <input type="text" id="_checkAddress" size="50"/><button id="btnCheckBalance">Check</button><br/> | |
| <input type="text" id="balance_" size="30" readonly/><br/> | |
| <h4>Transfer Coin</h4> | |
| Address : <input type="text" id="_toAddress" size="50"/><br/> | |
| Balance : <input type="text" id="_toBalance" size="30"/><br/> | |
| <button type="text" id="btnTransfer">Transfer</button> | |
| </div> | |
| <h3>Log</h3> | |
| <div> | |
| <textarea id="_log" rows="7" cols="80"></textarea> | |
| </div> | |
| <script type="text/javascript"> | |
| function _log(content) { | |
| var logger = $('#_log').append(content).append("\n"); | |
| logger.scrollTop(logger[0].scrollHeight); | |
| } | |
| // web3 Initialization (Set web3 Provider) | |
| var Web3 = require('web3'); | |
| var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); | |
| //var web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.1.11:8545")); | |
| //var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8546")); | |
| // Filter latest block | |
| var latestFilter = web3.eth.filter('latest'); | |
| latestFilter.watch(function(error, result) { | |
| var newBlock = web3.eth.getBlock(result); | |
| var log = "[NEW BLOCK] " + newBlock.number + "\n"; | |
| log += "Txs : " + newBlock.transactions.length + "\n"; | |
| _log(log); | |
| }); | |
| function addHandlers(coin) { | |
| coin.Transfer(function(error, result) { | |
| var log = "##COIN TRANSFER#\n"; | |
| log += "\n from : " + result.args.from; | |
| log += "\n to: " + result.args.to; | |
| log += "\n value : " + result.args.value; | |
| alert(log); | |
| }); | |
| } | |
| var code = ""; | |
| var abi = ; | |
| var Contract = web3.eth.contract(abi); | |
| var coin = null; | |
| $(document).ready(function() { | |
| // Unlock First Account | |
| web3.personal.unlockAccount(web3.eth.accounts[0],'0000'); | |
| console.log("UNLOCKED"); | |
| $('#btnCreate').click(function(){ | |
| coin = Contract.new( | |
| $('#_initialSupply').val(), // 전체 코인 금액 | |
| $('#_coinName').val(), // 코인 이름 | |
| $('#_decimalUnits').val(), // 소숫점 자리수 | |
| $('#_coinSymbol').val(), // 코인 단위로 쓸 Symbol (ETH, ETC, DAO 같은..) | |
| { | |
| data:code, | |
| gas:2000000, | |
| from:web3.eth.accounts[0] | |
| }, function (error, contract) { | |
| if (!error) { | |
| if (!contract.address) { | |
| _log("Creating Contract : " + contract.transactionHash); | |
| } else { | |
| address = contract.address; | |
| _log("Contract Deployed : " + contract.address); | |
| addHandlers(contract); | |
| } | |
| } else | |
| console.error(error); | |
| }); | |
| }); | |
| $('#btnAt').click(function(){ | |
| var address = $('#_contractAddress').val(); | |
| coin = Contract.at(address); | |
| addHandlers(coin); | |
| }); | |
| // Balance 체크 | |
| $('#btnCheckBalance').click(function() { | |
| var address = $('#_checkAddress').val(); | |
| var balance = coin.balanceOf(address).toString(); | |
| // 소숫점 및 Symbol 표현 용 | |
| var dec = coin.decimals(); | |
| balance = balance.slice(0,balance.length - dec) + "." + balance.slice(balance.length - dec); | |
| balance += " " + coin.symbol(); | |
| $('#balance_').val(balance); | |
| }); | |
| // 이체 | |
| $('#btnTransfer').click(function() { | |
| var address = $('#_toAddress').val(); | |
| var balance = $('#_toBalance').val(); | |
| var txHash = coin.transfer.sendTransaction(address, balance, { | |
| from:web3.eth.accounts[0], | |
| gas:1000000 | |
| }); | |
| _log("Transfer Requested : " + txHash); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment