fix: readme (#41)
This commit is contained in:
parent
d77d25b7d6
commit
6da7c605f8
21
README.md
21
README.md
|
@ -5,12 +5,12 @@ Subspace
|
||||||
Subspace is a framework agnostic JS library that embraces reactive programming with RxJS, by observing asynchronous changes in Smart Contracts, and providing methods to track and subscribe to events, changes to the state of contracts and address balances, and react to these changes and events via callbacks.
|
Subspace is a framework agnostic JS library that embraces reactive programming with RxJS, by observing asynchronous changes in Smart Contracts, and providing methods to track and subscribe to events, changes to the state of contracts and address balances, and react to these changes and events via callbacks.
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
TODO: link here
|
https://status-im.github.io/subspace-docs/
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
Subspace can be used in browser, node and native script environments. You can install it through `npm` or `yarn`:
|
Subspace can be used in browser, node and native script environments. You can install it through `npm` or `yarn`:
|
||||||
```
|
```
|
||||||
npm install --save @statusim/subspace
|
npm install --save @status-im/subspace
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
@ -18,15 +18,15 @@ npm install --save @statusim/subspace
|
||||||
#### Import into a dApp
|
#### Import into a dApp
|
||||||
```js
|
```js
|
||||||
// ESM (might require babel / browserify)
|
// ESM (might require babel / browserify)
|
||||||
import Subspace from '@statusim/subspace';
|
import Subspace from '@status-im/subspace';
|
||||||
|
|
||||||
// CommonJS
|
// CommonJS
|
||||||
const Subspace = require('@statusim/subspace');
|
const Subspace = require('@status-im/subspace');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Initializing the library
|
### Initializing the library
|
||||||
To interact with the EVM, Subspace requires a valid websockets Web3 provider.
|
To interact with the EVM, Subspace requires web3.js and a valid websockets provider.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const subspace = new Subspace(web3.currentProvider);
|
const subspace = new Subspace(web3.currentProvider);
|
||||||
|
@ -36,6 +36,7 @@ await subspace.init();
|
||||||
In addition to the provider, `Subspace` also accepts an `options` object with settings that can change its behavior:
|
In addition to the provider, `Subspace` also accepts an `options` object with settings that can change its behavior:
|
||||||
- `dbFilename` - Name of the database where the information will be stored (default 'subspace.db')
|
- `dbFilename` - Name of the database where the information will be stored (default 'subspace.db')
|
||||||
- `callInterval` - Interval of time in milliseconds to query a contract/address to determine changes in state or balance (default: obtain data every block).
|
- `callInterval` - Interval of time in milliseconds to query a contract/address to determine changes in state or balance (default: obtain data every block).
|
||||||
|
- `refreshLastNBlocks` - Ignores last N blocks (from current block), stored in the local db and refresh them via a web3 subscription. Useful for possible reorgs (default: 12)
|
||||||
|
|
||||||
### API
|
### API
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ subspace.trackEvent(contractObject, eventName, options)
|
||||||
|
|
||||||
|
|
||||||
#### `trackBalance(address [, tokenAddress])`
|
#### `trackBalance(address [, tokenAddress])`
|
||||||
Reacts to changes in the ETH or ERC20 balance of addresses for each mined block or time interval depending on the `callInterval` configured. Balances are returned as a string containing the vaue in wei.
|
You can also track changes in both ETH and ERC20 token balances for each mined block or time interval depending on the callInterval configured. Balances are returned as a string containing the vaue in wei.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Tracking ETH balance
|
// Tracking ETH balance
|
||||||
|
@ -107,10 +108,10 @@ subscription.unsubscribe();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Cleanup
|
#### Cleanup
|
||||||
If Subspace `subspace` is not needed anymore, you need to invoke `clean()` to dispose and perform the cleanup necessary to remove the internal subscriptions and interval timers created by Subspace during its normal execution. Any subscription created via the tracking methods must be unsubscribed manually (in the current version).
|
If Subspace is not needed anymore, you need can invoke close() to dispose and perform the cleanup necessary to remove the internal subscriptions and interval timers created by Subspace during its normal execution, thus avoiding any potential memory leak.
|
||||||
|
|
||||||
```
|
```
|
||||||
subspace.clean();
|
subspace.close();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
@ -118,7 +119,7 @@ Thank you for considering to help out with the source code! We welcome contribut
|
||||||
|
|
||||||
If you'd like to contribute to Subspace, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on #embark-status channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.
|
If you'd like to contribute to Subspace, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on #embark-status channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.
|
||||||
|
|
||||||
To build:
|
### To build:
|
||||||
|
|
||||||
* `yarn`
|
* `yarn`
|
||||||
* `yarn build`
|
* `yarn build`
|
||||||
|
@ -127,7 +128,7 @@ To build:
|
||||||
const Subspace = require('./dist/node.js');
|
const Subspace = require('./dist/node.js');
|
||||||
```
|
```
|
||||||
|
|
||||||
The browser version can be found at `dist/browser.js`
|
The browser version can be found at `dist/browser.js`. You can also check the examples in `test/`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
MIT
|
MIT
|
Loading…
Reference in New Issue