Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active June 20, 2022 00:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/5283cb02a626b0028bd9563202422f27 to your computer and use it in GitHub Desktop.
Save miguelmota/5283cb02a626b0028bd9563202422f27 to your computer and use it in GitHub Desktop.
JavaScript zksync get eth and token balances
const zksync = require('zksync')
const { formatUnits } = require('ethers/lib/utils')
const addresses = [
'0x123....'
]
const decimals = {
USDC: 6,
USDT: 6
}
async function main () {
const syncProvider = await zksync.getDefaultProvider('mainnet')
for (const address of addresses) {
const state = await syncProvider.getState(address)
const balances = state.verified.balances
console.log(address)
for (const token in balances) {
const formattedBalance = formatUnits(balances[token], decimals[token] || 18)
console.log(`\t${token}: ${formattedBalance}`)
}
}
}
main().catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment