Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/getsafle/asset-controller
This controller detects tokens for a user and returns token balances.
https://github.com/getsafle/asset-controller
controller
Last synced: about 2 months ago
JSON representation
This controller detects tokens for a user and returns token balances.
- Host: GitHub
- URL: https://github.com/getsafle/asset-controller
- Owner: getsafle
- License: mit
- Created: 2021-04-21T08:13:32.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-25T09:29:58.000Z (over 1 year ago)
- Last Synced: 2024-09-22T15:10:40.805Z (4 months ago)
- Topics: controller
- Language: JavaScript
- Homepage:
- Size: 377 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Safle Asset Controller
This SDK is used to detect the tokens and their balances in a given user's public address.
## Installation
To install this SDK,
```sh
npm install --save @getsafle/asset-controller
```## Initialization
Initialize the constructor,
```js
const safleAssetController = require('@getsafle/asset-controller');const assetController = new safleAssetController.AssetController({ rpcURL, chain });
```
> Detect Tokens
This function will detect and return the list of all the tokens in the user's public address.
```js
const tokenBalance = await assetController.detectTokens({ userAddress, tokenType });
```* `userAddress` - User Public Address
* `tokenType` - optional parameter - valid values- erc20/erc721
> Get list of chains on which a token exists
This function will return the list of all the chains which a particular token is supported
```js
const chains = await assetController.getChains(tokenSymbol);
```* `tokenSymbol` - Token Symbol
> Get token balances
This function will return the balances of all the tokens contract addresses passed in the array
```js
const chains = await assetController.getTokenBalances(tokensToDetect, SINGLE_CALL_BALANCES_ADDRESS, userAddress);
```* `tokensToDetect` - array of all the token addresses
* `SINGLE_CALL_BALANCES_ADDRESS` - Contract address of the single call balance checker contract
* `userAddress` - Public address of the user to query the balance of