diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-11-14 20:11:47 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-11-14 20:11:47 +0800 |
commit | ea8db7a4aecb034c6a967ccd3b17c50f423cb77c (patch) | |
tree | c02fbe94c1205ce270b36b6aa65de33af6178d54 /example | |
parent | 8aaec1d98fdeef1521e65518913498a1a0c18cbe (diff) | |
download | go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.tar go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.tar.gz go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.tar.bz2 go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.tar.lz go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.tar.xz go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.tar.zst go-tangerine-ea8db7a4aecb034c6a967ccd3b17c50f423cb77c.zip |
improved contracts interface
Diffstat (limited to 'example')
-rw-r--r-- | example/contract.html | 75 | ||||
-rw-r--r-- | example/index.html | 2 |
2 files changed, 76 insertions, 1 deletions
diff --git a/example/contract.html b/example/contract.html new file mode 100644 index 000000000..44f0b03a1 --- /dev/null +++ b/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 = 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/example/index.html b/example/index.html index 4847f68c0..d0bf094ef 100644 --- a/example/index.html +++ b/example/index.html @@ -30,7 +30,7 @@ </script> </head> <body> - <h1>balance</h1> + <h1>coinbase balance</h1> <button type="button" onClick="watchBalance();">watch balance</button> <div></div> <div id="original"></div> |