@hzhu/eth-balances
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

⟠ eth-balances ⟠

npm version build and test codecov

A tiny library to get 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.

Installation

npm install @hzhu/eth-balances

Usage

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
  2. Run npm install
  3. Run npm run web:example for the web browser example
  4. Run npm run node:example for the NodeJS example

Web example

get balances web demo

NodeJS example

get balances node.js demo

Contributing

Contributions are welcomed! Please follow the contributing guidelines.

Dependencies (1)

Dev Dependencies (6)

Package Sidebar

Install

npm i @hzhu/eth-balances

Weekly Downloads

13

Version

0.1.0

License

MIT

Unpacked Size

239 kB

Total Files

9

Last publish

Collaborators

  • henryzhu