@asset-projects/token-balance
v0.3.5
Published
A library for retrieving the amount of ERC20 tokens held by a specific address.
Downloads
41
Maintainers
Readme
@asset-projects/token-balance
A library for retrieving the amount of ERC20 tokens held by a specific address.
Install on your project
- Installing
# npm
npm i @asset-projects/token-balance
# yarn
yarn add @asset-projects/token-balance
- Implementation
import { ethers } from 'ethers';
import { erc20Tokens } from '@asset-projects/token-balance';
/** Prepare a provider */
const provider = new ethers.providers.JsonRpcProvider(url);
// or
const provider = new ethers.providers.InfuraProvider('homestead', {
projectId: process.env.INFURA_PROJECT_ID,
projectSecret: process.env.INFURA_PROJECT_SECRET,
});
/** Main */
const tokens = await erc20Tokens(provider, address);
console.log({ tokens });
/**
* {
* tokens: [
* {
* chainId: 1,
* type: 'ERC20',
* address: '0x6b175474e89094c44da98b954eedeac495271d0f',
* name: 'Dai Stablecoin',
* symbol: 'Dai',
* decimals: 18,
* logoURI: 'https://raw.githubusercontent.com/asset-projects/token-list/main/public/dai.png'
* balance: '100.100000000000000000',
* }
* ]
* }
*/