Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 117c6c3

Browse files
authored
Use the new SDK format for token balance fetch
Use the new SDK format
1 parent 2d817ca commit 117c6c3

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

token-balances-from-alchemyWeb3.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import { createAlchemyWeb3 } from "@alch/alchemy-web3";
2-
3-
//Replace with your Alchemy API Key:
4-
const apiKey = "demo";
5-
6-
// Initialize an alchemy-web3 instance:
7-
const web3 = createAlchemyWeb3(
8-
`https://eth-mainnet.alchemyapi.io/v2/${apiKey}`,
9-
);
10-
11-
// Replace with the wallet address you want to query:
1+
// Setup: npm install alchemy-sdk
2+
import { Alchemy, Network } from "alchemy-sdk";
3+
4+
const config = {
5+
apiKey: "<-- ALCHEMY APP API KEY -->",
6+
network: Network.ETH_MAINNET,
7+
};
8+
const alchemy = new Alchemy(config);
9+
10+
//Feel free to switch this wallet address with another address
1211
const ownerAddress = "0x00000000219ab540356cbb839cbe05303d7705fa";
13-
/*
14-
Replace with the token contract address you want to query:
15-
The below address Corresponds to USDT
16-
*/
12+
13+
//The below token contract address corresponds to USDT
1714
const tokenContractAddresses = ["0xdAC17F958D2ee523a2206206994597C13D831ec7"];
1815

19-
/*
20-
** Fetching the token Balance with Alchemy's getTokenBalances API
21-
*/
22-
const data = await web3.alchemy.getTokenBalances( ownerAddress, tokenContractAddresses);
23-
console.log("Response Object for getTokenBalances\n", data)
16+
const data = await alchemy.core.getTokenBalances(
17+
ownerAddress,
18+
tokenContractAddresses
19+
);
20+
21+
console.log("Token balance for Address");
22+
console.log(data);

0 commit comments

Comments
 (0)