Skip to content

Working sample code to retrieve multiple Ethereum token balances from addresses. The code samples use GraphQL, ethers.js, and web3.js libraries.

License

Notifications You must be signed in to change notification settings

samestshares/ethereum-token-balances

 
 

Repository files navigation

Getting multiple token balances on Ethereum

This repository contains code examples on how you can retreive Ethereum tokens in bulk using:

  • GraphQL
  • Etherplex
  • web3.js BatchRequest

Set up your environment

Install the following Node.js packages:

In the constant.js file, replace the following values to suit your use case:

  • ABI (Application Binary Interface) - contract ABI with only the balanceOf function, remember to add the function calls you're planning to execute to the ABI constant.
  • username — your Ethereum node RPC username.
  • password — your Ethereum node RPC password.
  • rpcEndpoint — your Ethereum node RPC endpoint.
  • bathEndpoint — your Ethereum node RPC endpoint with authentication credentials.
  • walletAddress — the account address you want to query.

See also Chainstack Docs: View node access and credentials.

GraphQL

GraphQL is a runtime natively supported by Go Ethereum client. See also GraphQL on Ethereum.

Run:

node graph

Sample results:

{
  "GameCredits":"1600000000000000000000 GAME",
  "Swarm Fund":"0 SWM",
  "Augur":"250684955559177177971383 REP",
  "Tether":"52057527540802 USDT",
  "DigixDAO":"122062000003 DGD",
  "SingularDTV":"1809462 SNGLS",
  "Veros":"0 VRS",
  "Golem":"83169802320824576633066602 GLM",
  "Circuits of Value":"0 COVAL",
  "chrono tech":"0 TIME",
  "Melon":"0 MLN",
  "WeTrust":"0 TRST",
  "iExec RLC":"1633118384742405 RLC",
  ...
}

Etherplex

Etherplex is a JavaScript library that makes use of the multicall smart contract to aggregate function calls and execute them in batches.

Run:

node etherplex

Sample results:

{
  "GameCredits":"1600000000000000000000 GAME",
  "Swarm Fund":"0 SWM",
  "Augur":"250684955559177177971383 REP",
  "Tether":"52057527540802 USDT",
  "DigixDAO":"122062000003 DGD",
  "SingularDTV":"1809462 SNGLS",
  "Veros":"0 VRS",
  "Golem":"83169802320824576633066602 GLM",
  "Circuits of Value":"0 COVAL",
  "chrono tech":"0 TIME",
  "Melon":"0 MLN",
  "WeTrust":"0 TRST",
  "iExec RLC":"1633118384742405 RLC",
  ...
}

web3.js BatchRequest

web3.js is a JavaScript library that makes use of the generic JSON-RPC methods.

The web3.js BatchRequest method aggregates the list of contract function calls and converts them into an array of JSON-RPC calls before sending it to the Ethereum node in one XMLHttpRequest.

Run:

node batch

Sample results:

{
  "GameCredits":"1600000000000000000000 GAME",
  "Swarm Fund":"0 SWM",
  "Augur":"250684955559177177971383 REP",
  "Tether":"52057527540802 USDT",
  "DigixDAO":"122062000003 DGD",
  "SingularDTV":"1809462 SNGLS",
  "Veros":"0 VRS",
  "Golem":"83169802320824576633066602 GLM",
  "Circuits of Value":"0 COVAL",
  "chrono tech":"0 TIME",
  "Melon":"0 MLN",
  "WeTrust":"0 TRST",
  "iExec RLC":"1633118384742405 RLC",
  ...
}

About

Working sample code to retrieve multiple Ethereum token balances from addresses. The code samples use GraphQL, ethers.js, and web3.js libraries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%