Created
October 15, 2018 18:00
-
-
Save ylv-io/692570127f4e608946628439df068f3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // both web3 and your contract have be defined | |
| if(web3js && contract) | |
| { | |
| const yourEvent = contract.YourEventName(); | |
| yourEvent.watch(function(error, result) { | |
| if (!error) { | |
| // Callback return | |
| // Object - An event object as follows: | |
| // address: String, 32 Bytes - address from which this log originated. | |
| // args: Object - The arguments coming from the event. | |
| // blockHash: String, 32 Bytes - hash of the block where this log was in. null when its pending. | |
| // blockNumber: Number - the block number where this log was in. null when its pending. | |
| // logIndex: Number - integer of the log index position in the block. | |
| // event: String - The event name. | |
| // removed: bool - indicate if the transaction this event was created from was removed from the blockchain (due to orphaned block) or never get to it (due to rejected transaction). | |
| // transactionIndex: Number - integer of the transactions index position log was created from. | |
| // transactionHash: String, 32 Bytes - hash of the transactions this log was created from. | |
| // event arguments cointained in result.args object | |
| const { eventArg1, eventArg2, eventArg3 } = result.args; | |
| // new data have arrived. it is good idea to udpate data & UI | |
| addNewDataToStateAndUpdateUI(); | |
| } else { | |
| // log error here | |
| console.log(error); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment