Last active
May 3, 2016 15:04
-
-
Save goodjoon/8c8f7eba9c111f99b8294565f35d83b5 to your computer and use it in GitHub Desktop.
기본 HTML
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>Transfer Sample</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> | |
| <div> | |
| <label for="account_list"><h3>Account & Balance List</h3></label> | |
| <ul id="account_list"> | |
| <li>No Account</li> | |
| </ul> | |
| </div> | |
| <div> | |
| <h3>Transfer</h3> | |
| <label for="transfer_to">To</label> | |
| <input type="text" id="transfer_to" size="50"/> | |
| <label for="wei_amount">Value</label> | |
| <input type="text" id="wei_amount"/> (Ether) | |
| <div> | |
| <button id="btnTransfer">Transfer</button> | |
| </div> | |
| </div><br/><br/> | |
| <div> | |
| <textarea id="log" cols="100" rows="10"></textarea> | |
| </div> | |
| <script type="text/javascript"> | |
| // web3 Initialization (Set web3 Provider) | |
| var Web3 = require('web3'); | |
| var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8541")); | |
| function refreshAccount() { | |
| $('#account_list').empty(); | |
| $(web3.eth.accounts).each(function(index, value) { | |
| $('#account_list').append('<li>'+value+'('+web3.fromWei(web3.eth.getBalance(value),'ether')+' Ether) </li>'); | |
| }); | |
| } | |
| $(document).ready(function() { | |
| // List Accounts | |
| refreshAccount(); | |
| // Unlock First Account | |
| web3.personal.unlockAccount(web3.eth.accounts[0],'1111'); | |
| // Transfer Ether | |
| $('#btnTransfer').click(function(){ | |
| var to = $('#transfer_to').val(); | |
| var value = web3.toWei($('#wei_amount').val(),'ether'); | |
| var txHash = web3.eth.sendTransaction({ | |
| "to":to, | |
| "value":value, | |
| "from":web3.eth.accounts[0] | |
| }); | |
| $('#log').append('Tx Hash : ' + txHash + '\n'); | |
| }); | |
| // Filter Latest Block | |
| var filter = web3.eth.filter('latest'); | |
| filter.watch(function(error, result) { | |
| if (!error) { | |
| var newBlock = web3.eth.getBlock(result,true); | |
| $('#log').append('[+] Block Imported ['+newBlock.number+']\n'); | |
| $('#log').append(' Hash :' + newBlock.hash +'\n'); | |
| $('#log').append(' Tx : ' + newBlock.transactions.length + '\n\n'); | |
| $('#log').scrollTop($('#log')[0].scrollHeight); | |
| refreshAccount(); | |
| } | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment