const address = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
const baseURL = `<-- ALCHEMY APP HTTP URL -->`;
const raw = JSON.stringify({
"method": "alchemy_getTokenBalances",
"Content-Type": "application/json"
// Make the request and print the formatted response:
fetch(baseURL, requestOptions)
const balances = response['data']['result']
// Remove tokens with zero balance
balances['tokenBalances'].filter(token => {
return token['tokenBalance'] !== '0'
console.log(`Token balances of ${address} \n`)
// Counter for SNo of final output
// Loop through all tokens with non-zero balance
for (token of nonZeroBalances) {
let balance = token['tokenBalance']
const metadataRaw = JSON.stringify({
"method": "alchemy_getTokenMetadata",
'Content-Type': 'application/json'
`${token['contractAddress']}`
const metadataOptions = {
fetch(baseUrl, metadataOptions)
// Compute token balance in human-readable format
balance = balance/Math.pow(10, metadata['decimals']);
balance = balance.toFixed(2);
// Print name, balance, and symbol of token
console.log(`${i++}. ${metadata['name']}: ${balance}
.catch(error => console.log('error', error))
.catch(error => console.log('error', error));