diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-15 08:37:52 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-15 08:37:52 +0800 |
commit | 508f116738517efc8c21233e9d50349ba30e223c (patch) | |
tree | 40789b5bf504f2f9ec8bc8b07ca139fa17d3253a | |
parent | b6c0e53d693a292d18463fa63b0d098a503c01e0 (diff) | |
parent | a4049fb85c8b81313b99d0ab38a7c3024df8f6b2 (diff) | |
download | go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.tar go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.tar.gz go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.tar.bz2 go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.tar.lz go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.tar.xz go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.tar.zst go-tangerine-508f116738517efc8c21233e9d50349ba30e223c.zip |
Merge pull request #798 from LefterisJP/natspec_OnContractCreation
Natspec Popup Authentication on transaction
-rw-r--r-- | example/natspec_contract.html | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/example/natspec_contract.html b/example/natspec_contract.html new file mode 100644 index 000000000..8d12b4a81 --- /dev/null +++ b/example/natspec_contract.html @@ -0,0 +1,77 @@ +<!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" + + " /// @notice Will multiplty `a` by 7. \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).transact().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"></input> + <button type="button" onClick="callExampleContract()">Call Contract</button> + </div> + <div id="result"></div> +</body> +</html> + |