https://github.com/metamask/eth-token-tracker
A JS module for tracking Ethereum token balances over block changes
https://github.com/metamask/eth-token-tracker
Last synced: 7 months ago
JSON representation
A JS module for tracking Ethereum token balances over block changes
- Host: GitHub
- URL: https://github.com/metamask/eth-token-tracker
- Owner: MetaMask
- License: isc
- Created: 2017-04-19T21:35:42.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2025-03-28T16:14:25.000Z (10 months ago)
- Last Synced: 2025-06-05T10:50:27.080Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.54 MB
- Stars: 80
- Watchers: 34
- Forks: 43
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Eth Token Tracker
A JS module for tracking Ethereum tokens and their values over time.
## Installation
`yarn add @metamask/eth-token-tracker`
## Usage
```javascript
const TokenTracker = require('@metamask/eth-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 install
yarn test
```