Firm Web3
Subset of original Web3 API with additional certainty checks. I.e. wait for some confirmations (new blocks) before triggering the callback.
Usage
// Import the library; // Create new `FirmWeb3` passing existing `web3` instance.let firmWeb3 = globalweb3; // Change certainty level (default MEDIUM=4 blocks)firmWeb3 = firmWeb3; // wait for 12 blocks // send transaction and wait for receiptweb3eth;
or without ES2015
:
// Import the libraryvar firmWeb3 = ; // Create new `FirmWeb3` passing existing `web3` instance.var firmWeb3 = globalweb3; // Change certainty level (default MEDIUM=4 blocks)firmWeb3 = firmWeb3; // wait for 12 blocks // send transaction and wait for receiptweb3eth;
API
Web3
firmWeb3.withCertainty(level)
- returns a new instance with given certaintylevel
(Certainty.{LOW(2 blocks), MEDIUM(4), HIGH(12)}
or just number of blocks),firmWeb3.getTransactionReceipt(hash, callback)
- gets a receipt for givenhash
(will retry up to 24 blocks),firmWeb3.getCode(address, callback)
- gets contract code under givenaddress
(will retry up to 24 blocks),firmWeb3.filter(filterOptions)
- returns a new logs (events) filter,firmWeb3.contract(abiArray)
- returns a new contract factory.
Filter
filter.withCertainty(level)
- returns a new filter with changed certaintylevel
,filter.get(callback)
- gets current "firm" logs (logs coming from blocklatest - confirmationLevel
),filter.watch(callback)
- fires a callback for each new logs specified in filter and happening in blocklatest - confirmationLevel
,filter.stopWatching()
- stops watching and uninstall filter.
Contract
-
contractF.at(address)
- returns contract with current ABI bound to givenaddress
, -
contractF.new([...args,] callback)
- deploys contract with current ABI and calls back withFirmContract
. -
contract.withCertainty(level)
- returns a new contract with different certaintylevel
, -
contract.allEvents([filterOptions] [, callback])
- returns a filter for all events hapening in contract -
contract.[eventName]([filterValues] [, filterOptions] [, callback])
- returns a filter for specific event in contract
Parameters values are the same as specified here: JavaScript API
TODO
- [] Better retries handling (each block instead of timeout)
- [] Information about progress