2016-11-01 16:03:03 +01:00
###############
Callbacks Promises Events
###############
To help web3 integrate into all kind of projects with different standards
we provide multiple ways to act on asynchronous functions.
2016-11-01 16:24:54 +01:00
Most web3.js objects allow a callback as the last parameter, as well as returning promises to chain functions.
2016-11-01 16:03:03 +01:00
Ethereum as a blockchain has different level of finality and therefore we return for some functions,
like `` web3.eth.sendTransaction `` or contract methods a "promiEvent". This is a promise combined with an event emitter.
2016-11-01 16:24:54 +01:00
This promiEvent works like a normal promise with added `` on `` and `` once `` functions to watch for additional events like "receipt" or "transactionHash"
2016-11-01 16:03:03 +01:00
.. code-block :: javascript
web3.eth.sendTransaction({from: '0x123...', data: '0x432...'})
2016-11-01 16:24:54 +01:00
.once('transactionHash', function(hash){ ... })
.once('receipt', function(receipt){ ... })
2016-11-01 16:03:03 +01:00
.then(function(receipt){
// will be fired once the receipt its mined
});