aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-30 22:43:12 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-30 22:45:00 +0800
commit2eedc330bfcb976b8eef2b6aee69e19430de1713 (patch)
tree856ed973d312a865e7cb3af057ce88d54d4c862d
parent600c9dd27dde3269a1682b875f82d3db46cee2c9 (diff)
downloadgo-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.tar
go-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.tar.gz
go-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.tar.bz2
go-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.tar.lz
go-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.tar.xz
go-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.tar.zst
go-tangerine-2eedc330bfcb976b8eef2b6aee69e19430de1713.zip
contract with array example
-rw-r--r--example/contract_with_array.html76
1 files changed, 76 insertions, 0 deletions
diff --git a/example/contract_with_array.html b/example/contract_with_array.html
new file mode 100644
index 000000000..a3dfc8a24
--- /dev/null
+++ b/example/contract_with_array.html
@@ -0,0 +1,76 @@
+<!doctype>
+<html>
+
+<head>
+<script type="text/javascript" src="js/bignumber.js/bignumber.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.HttpSyncProvider());
+
+ // solidity source code
+ var source = "" +
+ "contract test {\n" +
+ " function multiply(uint[] a) returns(uint d) {\n" +
+ " return a[0] + a[1];\n" +
+ " }\n" +
+ "}\n";
+
+ // contract description, this will be autogenerated somehow
+ var desc = [{
+ "name": "multiply(uint256[])",
+ "type": "function",
+ "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
+ var address = web3.eth.transact({code: web3.eth.solidity(source)});
+ contract = web3.eth.contract(address, desc);
+ document.getElementById('call').style.visibility = 'visible';
+ }
+
+ function callExampleContract() {
+ // this should be generated by ethereum
+ var param = parseInt(document.getElementById('value').value);
+ var param2 = parseInt(document.getElementById('value2').value);
+
+ // call the contract
+ var res = contract.call().multiply([param, param2]);
+ document.getElementById('result').innerText = res.toString(10);
+ }
+
+</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>
+ <input type="number" id="value2" onkeyup='callExampleContract()'></input>
+ </div>
+ <div id="result"></div>
+</body>
+</html>
+