github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/assets/ext/ethereum.js/example/event.html (about) 1 <!doctype> 2 <html> 3 <head> 4 <script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script> 5 <script type="text/javascript" src="../dist/ethereum.js"></script> 6 <script type="text/javascript"> 7 var web3 = require('web3'); 8 web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); 9 10 var desc = [{ 11 "type":"event", 12 "inputs": [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}], 13 "name":"Event" 14 }, { 15 "type":"event", 16 "inputs": [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}], 17 "name":"Event2" 18 }, { 19 "type":"function", 20 "inputs": [{"name":"a","type":"uint256"}], 21 "name":"foo", 22 "outputs": [] 23 }]; 24 25 var address = '0x01'; 26 27 var contract = web3.eth.contract(address, desc); 28 29 function test1() { 30 // "{"topic":["0x83c9849c","0xc4d76332"],"address":"0x01"}" 31 web3.eth.watch(contract).changed(function (res) { 32 33 }); 34 }; 35 36 function test2() { 37 // "{"topic":["0x83c9849c"],"address":"0x01"}" 38 web3.eth.watch(contract.Event).changed(function (res) { 39 40 }); 41 }; 42 43 function test3() { 44 // "{"topic":["0x83c9849c"],"address":"0x01"}" 45 contract.Event().changed(function (res) { 46 47 }); 48 }; 49 50 function test4() { 51 // "{"topic":["0x83c9849c","0000000000000000000000000000000000000000000000000000000000000045"],"address":"0x01"}" 52 contract.Event({a: 69}).changed(function (res) { 53 54 }); 55 }; 56 57 function test5() { 58 // "{"topic":["0x83c9849c",["0000000000000000000000000000000000000000000000000000000000000045","000000000000000000000000000000000000000000000000000000000000002a"]],"address":"0x01"}" 59 contract.Event({a: [69, 42]}).changed(function (res) { 60 61 }); 62 }; 63 64 function test6() { 65 // "{"topic":["0x83c9849c","000000000000000000000000000000000000000000000000000000000000001e"],"max":100,"address":"0x01"}" 66 contract.Event({a: 30}, {max: 100}).changed(function (res) { 67 68 }); 69 }; 70 71 function test7() { 72 // "{"topic":["0x83c9849c","000000000000000000000000000000000000000000000000000000000000001e"],"address":"0x01"}" 73 web3.eth.watch(contract.Event, {a: 30}).changed(function (res) { 74 75 }); 76 }; 77 78 function test8() { 79 // "{"topic":["0x83c9849c","000000000000000000000000000000000000000000000000000000000000001e"],"max":100,"address":"0x01"}" 80 web3.eth.watch(contract.Event, {a: 30}, {max: 100}).changed(function (res) { 81 82 }); 83 }; 84 85 // not valid 86 // function testX() { 87 // web3.eth.watch([contract.Event, contract.Event2]).changed(function (res) { 88 // }); 89 // }; 90 91 </script> 92 </head> 93 94 <body> 95 <div> 96 <button type="button" onClick="test1();">test1</button> 97 </div> 98 <div> 99 <button type="button" onClick="test2();">test2</button> 100 </div> 101 <div> 102 <button type="button" onClick="test3();">test3</button> 103 </div> 104 <div> 105 <button type="button" onClick="test4();">test4</button> 106 </div> 107 <div> 108 <button type="button" onClick="test5();">test5</button> 109 </div> 110 <div> 111 <button type="button" onClick="test6();">test6</button> 112 </div> 113 <div> 114 <button type="button" onClick="test7();">test7</button> 115 </div> 116 <div> 117 <button type="button" onClick="test8();">test8</button> 118 </div> 119 </body> 120 </html>