https://github.com/starcoinorg/stc-token-tracker
https://github.com/starcoinorg/stc-token-tracker
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/starcoinorg/stc-token-tracker
- Owner: starcoinorg
- License: isc
- Created: 2021-05-08T08:27:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-28T02:43:59.000Z (over 4 years ago)
- Last Synced: 2025-05-29T20:18:54.352Z (5 months ago)
- Language: JavaScript
- Size: 75.2 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# stc-token-tracker
A JS module for tracking Ethereum tokens and their values over time.
## Installation
`yarn install '@starcoin/stc-token-tracker'`
## Usage
```javascript
const TokenTracker = require('@starcoin/stc-token-tracker')var tokenTracker = new TokenTracker({
userAddress: addresses[0], // whose balance to track
provider, // a web3-style provider
pollingInterval: 4000, // block polling interval (optional)// Tell it about the tokens to track:
tokens: [
{
address: tokenAddress,
}
],
})// You can use this method to check the state of the tokens
var balances = tokenTracker.serialize()// You can also subscribe to updates
tokenTracker.on('update', function (balances) {
console.log(`Your balance of ${balances[0].symbol} is ${balances[0].string}`)
})// You can add additional tokens after initialization:
tokenTracker.add({ address: otherTokenAddress })// Make sure to clean up, or it will hold a reference:
tokenTracker.stop()
```## Running tests
```bash
yarn test
```