Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hzhu/eth-balances
🪙 A tiny library to get ERC-20 token balances on EVM blockchains using the Multicall smart contract âŸ
https://github.com/hzhu/eth-balances
balances blockchain erc-20 ethereum evm mullticall token
Last synced: 2 months ago
JSON representation
🪙 A tiny library to get ERC-20 token balances on EVM blockchains using the Multicall smart contract âŸ
- Host: GitHub
- URL: https://github.com/hzhu/eth-balances
- Owner: hzhu
- License: mit
- Created: 2023-01-30T00:36:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-01T02:49:16.000Z (over 1 year ago)
- Last Synced: 2024-08-09T03:28:41.526Z (5 months ago)
- Topics: balances, blockchain, erc-20, ethereum, evm, mullticall, token
- Language: TypeScript
- Homepage:
- Size: 1.07 MB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ⟠eth-balances âŸ
[![npm version](https://img.shields.io/npm/v/@hzhu/eth-balances.svg?style=flat-square)](https://www.npmjs.com/package/@hzhu/eth-balances)
[![build and test](https://github.com/hzhu/eth-balances/actions/workflows/test.yml/badge.svg)](https://github.com/hzhu/eth-balances/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/hzhu/eth-balances/branch/main/graph/badge.svg?token=OnNsoc2OrF)](https://codecov.io/gh/hzhu/eth-balances)A tiny library to get [ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/) token balances on EVM blockchains. It uses an aggregate function to fetch ERC20 token balances from multiple smart contracts in a single batch using the [Multicall contract](https://github.com/mds1/multicall).
## Installation
```
npm install @hzhu/eth-balances
```Note: This package requires [Ethers](https://www.npmjs.com/package/ethers) to be installed in order to work.
## Usage
```typescript
import { JsonRpcProvider } from "ethers";
import { getTokenBalances } from "@hzhu/eth-balances";const provider = new JsonRpcProvider(`https://YOUR-ETHEREUM-RPC-URL`);
const addressOrName = "henryzhu.eth";
const contractAddresses = [
"0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72",
"0xE41d2489571d322189246DaFA5ebDe1F4699F498",
];const balances = await getTokenBalances({
provider,
addressOrName,
contractAddresses,
});console.log(balances);
```## Examples
The `/examples` folder in this repository provides development examples for web browser and NodeJS usage.
1. Clone the repository
1. Run `npm install`
1. Run `npm run web:example` for the web browser example
1. Run `npm run node:example` for the NodeJS example### Web example
### NodeJS example
## Contributing
Contributions are welcomed! Please follow the [contributing guidelines](./.github/.CONTRIBUTING.md).