Last active
June 20, 2022 00:26
-
-
Save miguelmota/5283cb02a626b0028bd9563202422f27 to your computer and use it in GitHub Desktop.
JavaScript zksync get eth and token balances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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