aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/mist/assets/ext/ethereum.js/example
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-09 19:45:09 +0800
committerobscuren <geffobscura@gmail.com>2015-01-09 19:45:09 +0800
commit012a1c25331385aceb94af2a9829a2c6811d31b7 (patch)
tree3559aab7bdca4a269167a49802a061f156bfeea5 /cmd/mist/assets/ext/ethereum.js/example
parent585f259b63db323c87643a235fcbb9dc46d3125f (diff)
downloaddexon-012a1c25331385aceb94af2a9829a2c6811d31b7.tar.gz
dexon-012a1c25331385aceb94af2a9829a2c6811d31b7.tar.zst
dexon-012a1c25331385aceb94af2a9829a2c6811d31b7.zip
Updated ethereum.js
Diffstat (limited to 'cmd/mist/assets/ext/ethereum.js/example')
-rw-r--r--cmd/mist/assets/ext/ethereum.js/example/balance.html41
-rw-r--r--cmd/mist/assets/ext/ethereum.js/example/contract.html75
-rw-r--r--cmd/mist/assets/ext/ethereum.js/example/node-app.js16
3 files changed, 132 insertions, 0 deletions
diff --git a/cmd/mist/assets/ext/ethereum.js/example/balance.html b/cmd/mist/assets/ext/ethereum.js/example/balance.html
new file mode 100644
index 000000000..d0bf094ef
--- /dev/null
+++ b/cmd/mist/assets/ext/ethereum.js/example/balance.html
@@ -0,0 +1,41 @@
+<!doctype>
+<html>
+
+<head>
+<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
+<script type="text/javascript" src="../dist/ethereum.js"></script>
+<script type="text/javascript">
+
+ var web3 = require('web3');
+ web3.setProvider(new web3.providers.AutoProvider());
+
+ function watchBalance() {
+ var coinbase = web3.eth.coinbase;
+ var originalBalance = 0;
+
+ web3.eth.balanceAt(coinbase).then(function (balance) {
+ originalBalance = web3.toDecimal(balance);
+ document.getElementById('original').innerText = 'original balance: ' + originalBalance + ' watching...';
+ });
+
+ web3.eth.watch({altered: coinbase}).changed(function() {
+ web3.eth.balanceAt(coinbase).then(function (balance) {
+ 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/ext/ethereum.js/example/contract.html b/cmd/mist/assets/ext/ethereum.js/example/contract.html
new file mode 100644
index 000000000..403d8c9d1
--- /dev/null
+++ b/cmd/mist/assets/ext/ethereum.js/example/contract.html
@@ -0,0 +1,75 @@
+<!doctype>
+<html>
+
+<head>
+<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
+<script type="text/javascript" src="../dist/ethereum.js"></script>
+<script type="text/javascript">
+
+ var web3 = require('web3');
+ web3.setProvider(new web3.providers.AutoProvider());
+
+ // solidity source code
+ var source = "" +
+ "contract test {\n" +
+ " function multiply(uint a) returns(uint d) {\n" +
+ " return a * 7;\n" +
+ " }\n" +
+ "}\n";
+
+ // contract description, this will be autogenerated somehow
+ var desc = [{
+ "name": "multiply",
+ "inputs": [
+ {
+ "name": "a",
+ "type": "uint256"
+ }
+ ],
+ "outputs": [
+ {
+ "name": "d",
+ "type": "uint256"
+ }
+ ]
+ }];
+
+ var contract;
+
+ function createExampleContract() {
+ // hide create button
+ document.getElementById('create').style.visibility = 'hidden';
+ document.getElementById('source').innerText = source;
+
+ // create contract
+ web3.eth.transact({code: web3.eth.solidity(source)}).then(function (address) {
+ contract = web3.contract(address, desc);
+ document.getElementById('call').style.visibility = 'visible';
+ });
+ }
+
+ function callExampleContract() {
+ // this should be generated by ethereum
+ var param = parseInt(document.getElementById('value').value);
+
+ // call the contract
+ contract.multiply(param).call().then(function(res) {
+ document.getElementById('result').innerText = res[0];
+ });
+ }
+
+</script>
+</head>
+<body>
+ <h1>contract</h1>
+ <div id="source"></div>
+ <div id='create'>
+ <button type="button" onClick="createExampleContract();">create example contract</button>
+ </div>
+ <div id='call' style='visibility: hidden;'>
+ <input type="number" id="value" onkeyup='callExampleContract()'></input>
+ </div>
+ <div id="result"></div>
+</body>
+</html>
+
diff --git a/cmd/mist/assets/ext/ethereum.js/example/node-app.js b/cmd/mist/assets/ext/ethereum.js/example/node-app.js
new file mode 100644
index 000000000..f63fa9115
--- /dev/null
+++ b/cmd/mist/assets/ext/ethereum.js/example/node-app.js
@@ -0,0 +1,16 @@
+#!/usr/bin/env node
+
+require('es6-promise').polyfill();
+
+var web3 = require("../index.js");
+
+web3.setProvider(new web3.providers.HttpRpcProvider('http://localhost:8080'));
+
+web3.eth.coinbase.then(function(result){
+ console.log(result);
+ return web3.eth.balanceAt(result);
+}).then(function(balance){
+ console.log(web3.toDecimal(balance));
+}).catch(function(err){
+ console.log(err);
+}); \ No newline at end of file