diff options
Diffstat (limited to 'cmd/mist/assets/examples')
-rw-r--r-- | cmd/mist/assets/examples/abi.html | 55 | ||||
-rw-r--r-- | cmd/mist/assets/examples/balance.html | 40 | ||||
-rw-r--r-- | cmd/mist/assets/examples/coin.html | 142 | ||||
-rw-r--r-- | cmd/mist/assets/examples/coin.js | 64 | ||||
-rw-r--r-- | cmd/mist/assets/examples/info.html | 77 | ||||
-rw-r--r-- | cmd/mist/assets/examples/whisper.html | 70 |
6 files changed, 448 insertions, 0 deletions
diff --git a/cmd/mist/assets/examples/abi.html b/cmd/mist/assets/examples/abi.html new file mode 100644 index 000000000..8170e88b0 --- /dev/null +++ b/cmd/mist/assets/examples/abi.html @@ -0,0 +1,55 @@ +<!doctype> +<html> +<head> +<title>Hello world</title> +<script src="../ext/bignumber.min.js"></script> +<script src="../ext/ethereum.js/dist/ethereum.js"></script> +<script> + var web3 = require('web3'); + web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); + var eth = web3.eth; + var desc = [{ + "name": "multiply(uint256)", + "inputs": [{ + "name": "a", + "type": "uint256" + }], + "outputs": [{ + "name": "d", + "type": "uint256" + }] + }]; + var address = web3.eth.transact({ + data: "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056", + gasPrice: "1000000000000000", + gas: "10000", + }); + var contract = web3.eth.contract(address, desc); + + function calculate() { + var param = parseInt(document.getElementById('value').value); + + var res = contract.call().multiply(param); + document.getElementById('result').innerText = res.toString(10); + } +</script> +</head> +<body> +<h3>Contract content</h3> +<textarea style="height:100px; width: 300px;" disabled="disabled"> +contract test { + function multiply(uint a) returns(uint d) { + return a * 7; + } +} +</textarea> +<code><pre> +603880600c6000396000f3006001600060e060020a600035048063c6888fa1140 +05b6021600435602b565b8060005260206000f35b600081600702905091905056</pre></code> + +<hr> +<div>7 x <input type="number" id="value" onkeyup='calculate()'></input> = +<span id="result"></spa> + +</body> +</html> diff --git a/cmd/mist/assets/examples/balance.html b/cmd/mist/assets/examples/balance.html new file mode 100644 index 000000000..bc483a879 --- /dev/null +++ b/cmd/mist/assets/examples/balance.html @@ -0,0 +1,40 @@ +<!doctype> +<html> + +<head> +<script src="../ext/bignumber.min.js"></script> +<script src="../ext/ethereum.js/dist/ethereum.js"></script> +<script type="text/javascript"> + + var web3 = require('web3'); + web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); + + function watchBalance() { + var coinbase = web3.eth.coinbase; + var originalBalance = 0; + + var balance = web3.eth.balanceAt(coinbase); + var originalBalance = web3.toDecimal(balance); + document.getElementById('original').innerText = 'original balance: ' + originalBalance + ' watching...'; + + web3.eth.watch({altered: coinbase}).changed(function() { + balance = web3.eth.balanceAt(coinbase) + var currentBalance = web3.toDecimal(balance); + document.getElementById("current").innerText = 'current: ' + currentBalance; + document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance); + }); + } + +</script> +</head> +<body> + <h1>coinbase balance</h1> + <button type="button" onClick="watchBalance();">watch balance</button> + <div></div> + <div id="original"></div> + <div id="current"></div> + <div id="diff"></div> +</body> +</html> + + diff --git a/cmd/mist/assets/examples/coin.html b/cmd/mist/assets/examples/coin.html new file mode 100644 index 000000000..546c6f13f --- /dev/null +++ b/cmd/mist/assets/examples/coin.html @@ -0,0 +1,142 @@ +<!doctype> +<html> +<title>JevCoin</title> +<head> +<script type="text/javascript" src="../ext/bignumber.min.js"></script> +<script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script> +</head> +<body> + +<h1>JevCoin <code id="contract_addr"></code></h1> +<div> + <strong>Balance</strong> + <span id="balance"></strong> +</div> + +<div> + <span class="amount">Amount:</span> + <input type="text" id="address" style="width:200px"> + <input type="text" id="amount" style="width:200px"> + <button onclick="transact()">Send</button> +</div> + +<hr> + +<table width="100%" id="table"> + <tr><td style="width:40%;">Address</td><td>Balance</td></tr> + <tbody id="table_body"></tbody> +</table> + +</body> + +<script type="text/javascript"> + var web3 = require('web3'); + var eth = web3.eth; + + web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8545')); + var desc = [{ + "name": "balance(address)", + "type": "function", + "inputs": [{ + "name": "who", + "type": "address" + }], + "constant": true, + "outputs": [{ + "name": "value", + "type": "uint256" + }] + }, { + "name": "send(address,uint256)", + "type": "function", + "inputs": [{ + "name": "to", + "type": "address" + }, { + "name": "value", + "type": "uint256" + }], + "outputs": [] + }, { + "name":"received", + "type":"event", + "inputs": [ + {"name":"from","type":"address","indexed":true}, + {"name":"amount","type":"uint256","indexed":true}, + ], + }]; + + var address = localStorage.getItem("address"); + // deploy if not exist + if (address == null) { + var code = "0x60056013565b61012b806100346000396000f35b6103e8600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a681461002b578063d0679d3414610039578063e3d670d71461004d57005b610033610126565b60006000f35b610047600435602435610062565b60006000f35b610058600435610104565b8060005260206000f35b80600033600160a060020a0316600052602052604060002054101561008657610100565b80600033600160a060020a0316600052602052604060002090815403908190555080600083600160a060020a0316600052602052604060002090815401908190555033600160a060020a0316600052806020527ff11e547d796cc64acdf758e7cee90439494fd886a19159454aa61e473fdbafef60406000a15b5050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156"; + address = web3.eth.transact({data: code}); + localStorage.setItem("address", address); + } + document.querySelector("#contract_addr").innerHTML = address.toUpperCase(); + + var contract = web3.eth.contract(address, desc); + contract.received({from: eth.coinbase}).changed(function() { + refresh(); + }); + eth.watch('chain').changed(function() { + refresh(); + }); + + function refresh() { + document.querySelector("#balance").innerHTML = contract.balance(eth.coinbase); + + var table = document.querySelector("#table_body"); + table.innerHTML = ""; // clear + + var storage = eth.storageAt(address); + table.innerHTML = ""; + for( var item in storage ) { + table.innerHTML += "<tr><td>"+item.toUpperCase()+"</td><td>"+web3.toDecimal(storage[item])+"</td></tr>"; + } + } + + function transact() { + var to = document.querySelector("#address").value; + if( to.length == 0 ) { + to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3"; + } else { + to = "0x"+to; + } + + var value = parseInt( document.querySelector("#amount").value ); + + contract.send( to, value ); + } + + refresh(); +</script> + +</html> + +<!-- +contract JevCoin { + function JevCoin() + { + balances[msg.sender] = 1000000; + } + + event changed(address indexed from, address indexed to); + function send(address to, uint value) + { + if( balances[msg.sender] < value ) return; + + balances[msg.sender] -= value; + balances[to] += value; + + changed(msg.sender, to); + } + + function balance(address who) constant returns(uint t) + { + t = balances[who]; + } + + mapping(address => uint256) balances; + } +-!> diff --git a/cmd/mist/assets/examples/coin.js b/cmd/mist/assets/examples/coin.js new file mode 100644 index 000000000..d69af5dcb --- /dev/null +++ b/cmd/mist/assets/examples/coin.js @@ -0,0 +1,64 @@ +var contract = web3.eth.contractFromAbi([ + { + "constant":false, + "inputs":[ + {"name":"_h","type":"hash256"} + ], + "name":"confirm", + "outputs":[], + "type":"function" + },{ + "constant":false, + "inputs":[ + {"name":_to,"type":"address"}, + {"name":"_value","type":"uint256"}, + {"name":"_data","type":"bytes"} + ], + "name":"execute", + "outputs":[ + {"name":"_r","type":"hash256"} + ], + "type":"function" + },{ + "constant":false, + "inputs":[ + {"name":"_to","type":"address"} + ],"name":"kill", + "outputs":[], + "type":"function" + },{ + "constant":false, + "inputs":[ + {"name":"_from","type":"address"}, + {"name":"_to","type":"address"} + ], + "name":"changeOwner", + "outputs":[], + "type":"function" + },{ + "inputs":[ + {"indexed":false,"name":"value","type":"uint256"} + ], + "name":"CashIn", + "type":"event" + },{ + "inputs":[ + {"indexed":true,"name":"out","type":"string32"}, + {"indexed":false,"name":"owner","type":"address"}, + {"indexed":false,"name":"value","type":"uint256"}, + {"indexed":false,"name":"to","type":"address"} + ], + "name":"SingleTransact", + "type":"event" + },{ + "inputs":[ + {"indexed":true,"name":"out","type":"string32"}, + {"indexed":false,"name":"owner","type":"address"}, + {"indexed":false,"name":"operation","type":"hash256"}, + {"indexed":false,"name":"value","type":"uint256"}, + {"indexed":false,"name":"to","type":"address"} + ], + "name":"MultiTransact", + "type":"event" + } +]); diff --git a/cmd/mist/assets/examples/info.html b/cmd/mist/assets/examples/info.html new file mode 100644 index 000000000..daad8c706 --- /dev/null +++ b/cmd/mist/assets/examples/info.html @@ -0,0 +1,77 @@ + +<!doctype> +<html> + +<head> +<script type="text/javascript" src="../ext/bignumber.min.js"></script> +<script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script> +</head> +<body> + <h1>Info</h1> + + <table width="100%"> + <tr> + <td>Block number</td> + <td id="number"></td> + </tr> + + <tr> + <td>Peer count</td> + <td id="peer_count"></td> + </tr> + + <tr> + <td>Default block</td> + <td id="default_block"></td> + </tr> + + <tr> + <td>Accounts</td> + <td id="accounts"></td> + </tr> + + <tr> + <td>Balance</td> + <td id="balance"></td> + + <tr> + <td>Gas price</td> + <td id="gas_price"></td> + </tr> + + <tr> + <td>Mining</td> + <td id="mining"></td> + </tr> + + <tr> + <td>Listening</td> + <td id="listening"></td> + </tr> + + <tr> + <td>Coinbase</td> + <td id="coinbase"></td> + </tr> + </table> +</body> + +<script type="text/javascript"> + var web3 = require('web3'); + var eth = web3.eth; + + web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); + + document.querySelector("#number").innerHTML = eth.number; + document.querySelector("#coinbase").innerHTML = eth.coinbase + document.querySelector("#peer_count").innerHTML = eth.peerCount; + document.querySelector("#default_block").innerHTML = eth.defaultBlock; + document.querySelector("#accounts").innerHTML = eth.accounts; + document.querySelector("#balance").innerHTML = web3.toEth(eth.balanceAt(eth.accounts[0])); + document.querySelector("#gas_price").innerHTML = eth.gasPrice; + document.querySelector("#mining").innerHTML = eth.mining; + document.querySelector("#listening").innerHTML = eth.listening; +</script> + +</html> + diff --git a/cmd/mist/assets/examples/whisper.html b/cmd/mist/assets/examples/whisper.html new file mode 100644 index 000000000..ad568f783 --- /dev/null +++ b/cmd/mist/assets/examples/whisper.html @@ -0,0 +1,70 @@ +<!doctype> +<html> +<title>Whisper test</title> +<head> +<script type="text/javascript" src="../ext/bignumber.min.js"></script> +<script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script> +</head> +<body> + +<h1>Whisper test</h1> + +<button onclick="test()">Send</button> +<button onclick="test2()">Private send</button> + +<table width="100%" id="table"> + <tr> + <td>Count</td> + <td id="count"></td> + </tr> + + <tr> + <td>ID</td> + <td id="id"></td> + </tr> + + <tr> + <td>Has identity</td> + <td id="known"></td> + </tr> +</table> +</body> + +<script type="text/javascript"> + var web3 = require('web3'); + web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); + + var shh = web3.shh; + + var id = shh.newIdentity(); + document.querySelector("#id").innerHTML = id; + document.querySelector("#known").innerHTML = shh.haveIdentity(id); + + var watch = shh.watch({topics: ["test"]}) + watch.arrived(function(message) { + document.querySelector("#table").innerHTML += "<tr><td colspan='2'>"+JSON.stringify(message)+"</td></tr>"; + }); + + var selfWatch = shh.watch({to: id, topics: ["test"]}) + selfWatch.arrived(function(message) { + document.querySelector("#table").innerHTML += "<tr><td>To me</td><td>"+JSON.stringify(message)+"</td></tr>"; + }); + + function test() { + shh.post({topics: ["test"], payload: web3.fromAscii("test it")}); + count(); + } + + function test2() { + shh.post({to: id, topics: ["test"], payload: web3.fromAscii("Private")}); + count(); + } + + function count() { + document.querySelector("#count").innerHTML = watch.messages().length; + } +</script> + +</html> + + |