• Stars
    star
    192
  • Rank 201,979 (Top 4 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An efficient Ether and token balance scanner library

eth-scan

eth-scan is a library written in TypeScript, to help you fetch Ether or (ERC-20) token balances for multiple addresses in an efficient way. The library uses a smart contract to fetch the balances in a single call to a node. The contract is currently deployed at:

It can use Web3.js, Ethers.js, JSON-RPC (HTTP), or an EIP-1193-compatible provider to get the balances. See Getting Started for more info.

Note: Even though eth_call doesn't use any gas, the block gas limit still applies, and the maximum number of addresses you can fetch in a single call is limited. By default this library batches calls per 1000 addresses.

Getting started

The library is published on npm. To install it, use npm or yarn:

yarn add @mycrypto/eth-scan

or

npm install @mycrypto/eth-scan

Example

import { getEtherBalances } from '@mycrypto/eth-scan';

getEtherBalances('http://127.0.0.1:8545', [
  '0x9a0decaffb07fb500ff7e5d253b16892dbec006a',
  '0xeb65f72a2f5464157288ac15f1bb56c56e6be375',
  '0x1b96c634f9e9fcfb76932e165984901701352ffd',
  '0x740539b55ee5dc58efffb88fea44a9008f8daa6f',
  '0x95d9e32dc03770699a6a5e5858165b174d500015'
]).then(console.log);

Results in:

{
  '0x9a0decaffb07fb500ff7e5d253b16892dbec006a': BigInt(1000000000000000000),
  '0xeb65f72a2f5464157288ac15f1bb56c56e6be375': BigInt(1000000000000000000),
  '0x1b96c634f9e9fcfb76932e165984901701352ffd': BigInt(1000000000000000000),
  '0x740539b55ee5dc58efffb88fea44a9008f8daa6f': BigInt(1000000000000000000),
  '0x95d9e32dc03770699a6a5e5858165b174d500015': BigInt(1000000000000000000)
}

API

getEtherBalances(provider, addresses, options)

Get Ether balances for addresses.

  • provider <Provider> - A Web3 instance, Ethers.js provider, JSONRPC endpoint, or EIP-1193 compatible provider

  • addresses <string[]> - An array of addresses as hexadecimal string.

  • options <EthScanOptions> (optional) - The options to use.

  • Returns: <Promise<BalanceMap>> - A promise with an object with the addresses and the balances.

getTokenBalances(provider, addresses, token, options)

Get ERC-20 token balances from token for addresses. This does not check if the address specified is a token and will throw an error if it isn't.

  • provider <Provider> - A Web3 instance, Ethers.js provider, JSONRPC endpoint, or EIP-1193 compatible provider

  • addresses <string[]> - An array of addresses as hexadecimal string.

  • token <string> - The address of the ERC-20 token.

  • options <EthScanOptions> (optional) - The options to use.

  • Returns: <Promise<BalanceMap>> - A promise with an object with the addresses and the balances.

getTokensBalance(provider, address, tokens, options)

Get ERC-20 token balances from tokens for address. If one of the token addresses specified is not a token, a balance of 0 will be used.

  • provider <Provider> - A Web3 instance, Ethers.js provider, JSONRPC endpoint, or EIP-1193 compatible provider

  • address <string> - The address to get token balances for.

  • tokens <string[]> - An array of ERC-20 token addresses.

  • options <EthScanOptions> (optional) - The options to use.

  • Returns: <Promise<BalanceMap>> - A promise with an object with the addresses and the balances.

getTokensBalances(provider, addresses, tokens, options)

  • provider <Provider> - A Web3 instance, Ethers.js provider, JSONRPC endpoint, or EIP-1193 compatible provider.

  • addresses <string[]> - An array of addresses as hexadecimal string.

  • tokens <string[]> - An array of ERC-20 token addresses.

  • options <EthScanOptions> (optional) - The options to use.

  • Returns: <Promise<BalanceMap<BalanceMap>>> - A promise with an object with the addresses and the balances.

EthScanOptions

  • contractAddress <string> (optional) - The address of the smart contract to use. Defaults to 0x08A8fDBddc160A7d5b957256b903dCAb1aE512C5.

  • batchSize <number> (optional) - The size of the call batches. Defaults to 1000.

BalanceMap

A BalanceMap is an object with an address as key and a bigint as value.

Providers

Currently, eth-scan has support for four different providers:

  • Ethers.js, by using an existing Ethers.js provider
  • Web3, by using an instance of the Web3 class
  • HTTP, by using a URL of a JSONRPC endpoint as string
  • EIP-1193 compatible provider, like window.ethereum

Compatiblity

eth-scan uses ES6+ functionality, which may not be supported on all platforms. If you need compatibility with older browsers or Node.js versions, you can use something like Babel.

There is an ES compatible version available, which should work with module bundlers like Webpack and Rollup.

More Repositories

1

MyCrypto

MyCrypto is an open-source tool that allows you to manage your Ethereum accounts privately and securely. Developed by and for the community since 2015, we’re focused on building awesome products that put the power in people’s hands.
TypeScript
1,363
star
2

ethereum-blockies-base64

A tiny library for generating blocky identicons as base64 encoded PNGs.
JavaScript
65
star
3

mycrypto.com

Legacy version of MyCrypto.com. Was used in production from 2015-2018. See https://github.com/MyCryptoHQ/mycrypto for up-to-date codebase
JavaScript
63
star
4

gas-estimation

EIP-1559 gas estimation library, using the estimation strategy of MyCrypto.
TypeScript
57
star
5

MoneroVision

MoneroVision is an open-source Monero block explorer that is offered as a part of the MyCrypto network
TypeScript
43
star
6

shepherd

Ensure high-availability for your JSON-RPC calls while improving user-experience
TypeScript
40
star
7

knowledge-base-content

Content for the knowledge base to separate the code / logic from the content
TypeScript
24
star
8

assets

Asset mapping for usage with CoinCap, CoinGecko, CryptoCompare and CryptoCurrency Icons
TypeScript
23
star
9

knowledge-base

Knowledge base for MyCrypto
TypeScript
21
star
10

ui

The shared UI component library used across all MyCrypto products.
TypeScript
17
star
11

parity-ecs

Shell
15
star
12

wallets

Wallet abstractions to be used throughout the MyCrypto product suite.
TypeScript
12
star
13

sentry

A bot that watches a website or GitHub assets for changes and communicates them to Slack.
TypeScript
11
star
14

landing

The landing page of MyCrypto
TypeScript
11
star
15

parse-eth-tokens

Tool used to parse the 'ethereum-lists/tokens' repository to a format that is used by MyCrypto
TypeScript
11
star
16

drawbridge

A command line application that helps deploy and verify projects that build deterministically.
TypeScript
9
star
17

support.mycrypto.com

Answers & help for MyCrypto.com & the Ethereum blockchain. If your answer isn't here, contact MyCrypto support instantly.
JavaScript
9
star
18

quill

TypeScript
7
star
19

wallet-list

TypeScript
7
star
20

tx-categorize

Go
6
star
21

about.mycrypto.com

The production content is on `MyCryptoHQ/landing` - this repo is old.
SCSS
6
star
22

unlock-scan

An efficient Unlock Protocol scanner
TypeScript
5
star
23

download.mycrypto.com

CSS
4
star
24

ts-package-boilerplate

A boilerplate for building packages with typescript source
TypeScript
4
star
25

winter.mycrypto.com

#MyCryptoWinter
HTML
4
star
26

DeFiReserveMapper

Used for mapping DeFi pool tokens to their related reserves for caching in use by beta.mycrypto.com
Go
3
star
27

eth-rpc-types

TypeScript
3
star
28

Overflow

TypeScript
3
star
29

MyCrypto-Boilerplate

JavaScript
3
star
30

MoonpaySigner

A Golang Moonpay.io signer
HCL
2
star
31

security.mycrypto.com

CSS
2
star
32

hw-app-xmr

An XMR ledger communication library
TypeScript
2
star
33

blog

TypeScript
2
star
34

escape.mycrypto.com

HTML
2
star
35

ganache-toolbox

Ganache Toolbox is a simple CLI to fund a Ganache test account with relevant tokens to execute tests on MyCrypto.
TypeScript
1
star
36

eth-tokenize

A library that provides decentralised methods of fetching token lists
TypeScript
1
star
37

download

TypeScript
1
star
38

go-gas-express

An Ethereum Gas Station API (in Golang)
Go
1
star
39

nano-result

A mini result handing library inspired by Rusts' Result enum
TypeScript
1
star
40

path-alias-resolver

TypeScript
1
star
41

membership-dashboard

MyCrypto Membership Dashboard
TypeScript
1
star
42

MyCrypto-Production

1
star
43

buy.mycrypto.com

CSS
1
star
44

MyCrypto-Beta

1
star