| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  | <!doctype> | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <head> | 
					
						
							| 
									
										
										
										
											2015-01-20 09:22:32 +01:00
										 |  |  | <script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script> | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  | <script type="text/javascript" src="../dist/ethereum.js"></script> | 
					
						
							|  |  |  | <script type="text/javascript"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var web3 = require('web3'); | 
					
						
							| 
									
										
										
										
											2015-01-22 13:39:16 +01:00
										 |  |  |     web3.setProvider(new web3.providers.QtSyncProvider()); | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // solidity source code | 
					
						
							|  |  |  |     var source = "" +  | 
					
						
							|  |  |  |     "contract test {\n" + | 
					
						
							| 
									
										
										
										
											2015-01-21 18:58:13 +01:00
										 |  |  |     "   /// @notice Will multiply `a` by 7. \n" + | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  |     "   function multiply(uint a) returns(uint d) {\n" + | 
					
						
							|  |  |  |     "       return a * 7;\n" + | 
					
						
							|  |  |  |     "   }\n" + | 
					
						
							|  |  |  |     "}\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // contract description, this will be autogenerated somehow | 
					
						
							|  |  |  |     var desc =  [{ | 
					
						
							| 
									
										
										
										
											2015-01-21 18:58:13 +01:00
										 |  |  |         "name": "multiply(uint256)", | 
					
						
							| 
									
										
										
										
											2015-01-29 12:35:21 +01:00
										 |  |  |         "type": "function", | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  |         "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 | 
					
						
							| 
									
										
										
										
											2015-01-22 13:39:16 +01:00
										 |  |  |         var address = web3.eth.transact({code: web3.eth.solidity(source)}); | 
					
						
							|  |  |  |         contract = web3.eth.contract(address, desc); | 
					
						
							|  |  |  |         document.getElementById('call').style.visibility = 'visible'; | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function callExampleContract() { | 
					
						
							|  |  |  |         // this should be generated by ethereum | 
					
						
							|  |  |  |         var param = parseInt(document.getElementById('value').value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 13:39:16 +01:00
										 |  |  |         // transaction does not return any result, cause it's not synchronous and we don't know, | 
					
						
							|  |  |  |         // when it will be processed | 
					
						
							| 
									
										
										
										
											2015-01-22 15:38:48 +01:00
										 |  |  |         contract.transact().multiply(param); | 
					
						
							| 
									
										
										
										
											2015-01-22 13:39:16 +01:00
										 |  |  |         document.getElementById('result').innerText = 'transaction made'; | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </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;'> | 
					
						
							| 
									
										
										
										
											2015-01-14 09:28:52 +01:00
										 |  |  |         <input type="number" id="value"></input> | 
					
						
							|  |  |  | 		<button type="button" onClick="callExampleContract()">Call Contract</button> | 
					
						
							| 
									
										
										
										
											2015-01-13 15:59:42 +01:00
										 |  |  |     </div> | 
					
						
							|  |  |  |     <div id="result"></div> | 
					
						
							|  |  |  | </body> | 
					
						
							|  |  |  | </html> | 
					
						
							|  |  |  | 
 |