subspace-docs/api.md

64 lines
3.5 KiB
Markdown
Raw Normal View History

2019-09-03 14:40:19 -04:00
# API
2019-09-09 19:49:35 -04:00
## General
2019-09-10 13:33:00 -04:00
### `new Phoenix(web3Provider [, options])`
2019-09-09 19:49:35 -04:00
Phoenix constructor.
**Parameters**
1. `web3Provider` - `Object`: a valid web3 websockets provider.
2. `options` - `Object` (optional): Options used to initialize Phoenix
- `dbFilename` - `String` (optional): Name of the database where the information will be stored (default `'phoenix.db'`)
- `callInterval` - `Number` (optional): - Interval of time in milliseconds to query a contract/address to determine changes in state or balance (default: `undefined`. Obtains data every block).
### `init()`
Initializes Phoenix
**Returns**
`Promise` that once it's resolved, will mean that Phoenix is available to use
### `close()`
Dispose and perform the cleanup necessary to remove the internal subscriptions and interval timers created by Phoenix during its normal execution.
2019-09-03 14:40:19 -04:00
## Data tracking methods
2019-09-09 19:49:35 -04:00
### `trackEvent(contractObject, eventName [, options])`
Track a contract event.
**Parameters**
1. `contractObject` - `web3.eth.Contract`: An already initialized contract object pointing to an address and containing a valid ABI.
2. `eventName` - `String`: The name of the event to subscribe.
3. `options` - `Object` (optional): web3 filter options object to limit the number of events based on a block number range, or indexed filters
- `filter` - `Object` (optional): Lets you filter events by indexed parameters, e.g. `{filter: {myNumber: [12,13]}}` means all events where `"myNumber"` is `12` or `13`.
- `fromBlock` - `Number` (optional): The block number from which to get events on.
- `toBlock` - `Number` (optional): The block number to get events up to (Defaults to `"latest"`)
- `topics` - `Array` (optional): This allows you to manually set the topics for the event filter. If given the filter property and event signature, (`topic[0]`) will not be set automatically.
**Returns**
`RxJS Observable` which will stream the event `returnValues`.
2019-09-03 14:40:19 -04:00
### `trackProperty(contractObject, functionName [, functionArgs] [, callOptions])`
2019-09-09 19:49:35 -04:00
Track a constant function / contract state variable on each block mined, or depending on the `callInterval` option used during Phoenix initialization.
2019-09-03 14:40:19 -04:00
2019-09-09 19:49:35 -04:00
**Parameters**
1. `contractObject` - `web3.eth.Contract`: An already initialized contract object pointing to an address and containing a valid ABI.
2. `functionName` - `String`: Name of the function or variable whose values will be tracked.
3. `functionArgs` - `Array` (optional): Array of arguments that the tracked function receives
4. `callOptions` - `Object` (optional): The options used for calling.
- `from` - `String` (optional): The address the call “transaction” should be made from.
- `gasPrice` - `String` (optional): The gas price in wei to use for this call “transaction”.
- `gas` - `Number` (optional): The maximum gas provided for this call “transaction” (gas limit).
**Returns**
`RxJS Observable` which will stream the function / variable values. Data type will depend on the contract function invoked.
2019-09-03 14:40:19 -04:00
### `trackBalance(address [, tokenAddress])`
2019-09-09 19:49:35 -04:00
Track balance changes for an address on each block mined, or depending on the `callInterval` option used during Phoenix initialization.
**Parameters**
1. `address` - `String`: The address to get the balance of.
2. `tokenAddress` - `String` (optional): If you want to track the balance for an ERC20 contract, here you can specify the token address. Otherwise, Only ETH balances will be returned.
2019-09-03 14:40:19 -04:00
2019-09-09 19:49:35 -04:00
**Returns**
`RxJS Observable` which will stream a string containing the address balance.