EthereumContractEventEmitter - ARitz-Cracker/arc-web3 GitHub Wiki

An EthereumContractEventEmitter works similarly to a regular NodeJS emitter. You shouldn't be creating these yourself, but instead look at the event property of an EthereumContract

Properties:

  • (EthereumContract) contract: The contract that this EthereumContractEventEmitter is bound to.

Methods:

EthereumContractEventEmitter.on(String eventName, [...Any topics,] Function callback);

Will call the specified callback function with an EthereumContractEvent as its first and only argument.

  • If eventName is null, all events will be listened to.
  • If a contract has 2 events with the same name, then you must specify it using its name and types. For example: contract.event.on("Transfer(address,address,uint256)", callback)
  • topics is optional but can be used to refine searches, for example, in the context of using an ERC20 contract,
    • when calling contract.event.on("Transfer", "0x8c070C3c66F62E34bAe561951450f15f3256f67c", callback), the callback will only be called if 0x8c070C3c66F62E34bAe561951450f15f3256f67c was the sender of the ERC20 tokens.
    • Calling contract.event.on("Transfer", null, "0x8c070C3c66F62E34bAe561951450f15f3256f67c", callback) will call the callback only when that address was the one who received the tokens.
  • If callback is asynchronous, then it won't be called again until it resolves. Events will be placed on a queue. Mind you that if your callback never resolves, then you'll lock up the library. Also, make sure your callback doesn't throw! Handle your Errors!
// No example. (Feel free to suggest one!)

EthereumContractEventEmitter.off(String eventName, [...Any topics,] Function callback)

Removes the callback from listening to the specified event.

// No example. (Feel free to suggest one!)

EthereumContractEventEmitter.addListener(String eventName, [...Any topics,] Function callback)

Alias of on


EthereumContractEventEmitter.removeListener(String eventName, [...Any topics,] Function callback)

Alias of off


EthereumContractEventEmitter.blockRange(String eventName, [...Any topics,] Number fromBlock, Number toBlock, Function callback)

Similar to on, except it allows you to specify a range of blocks.

  • If fromBlock is not null, then all events since this block will be fetched and passed to the callback.
  • If toBlock is null, then the event will be listened to until off is called. If not null, then the callback will stop being called after this block was reached. This parameter is ignored if fromBlock is null.
// No example. (Feel free to suggest one!)