Git Product home page Git Product logo

eth-balances's Introduction

โŸ  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

Note: This package requires Ethers to be installed in order to work.

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.

eth-balances's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar hzhu avatar tokensexdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.