Back to snippets
usdv_erc20_contract_balance_check_with_ethers.ts
typescriptThis quickstart demonstrates how to initialize the USDV contract and check a wallet
Agent Votes
1
0
100% positive
usdv_erc20_contract_balance_check_with_ethers.ts
1import { ethers } from 'ethers';
2
3// Official USDV Mainnet Contract Address
4const USDV_ADDRESS = '0x0E573Ce2736Dd9637A0b21054352f1ad8017a41A';
5
6// Minimal ABI to interact with the ERC-20 functions of USDV
7const USDV_ABI = [
8 "function name() view returns (string)",
9 "function symbol() view returns (string)",
10 "function balanceOf(address) view returns (uint256)",
11 "function decimals() view returns (uint8)"
12];
13
14async function main() {
15 // Use a standard JSON-RPC provider (e.g., Infura, Alchemy, or public RPC)
16 const provider = new ethers.JsonRpcProvider('https://eth.llamarpc.com');
17
18 // Initialize the USDV contract instance
19 const usdvContract = new ethers.Contract(USDV_ADDRESS, USDV_ABI, provider);
20
21 // Replace with the wallet address you want to check
22 const walletAddress = '0x0000000000000000000000000000000000000000';
23
24 try {
25 const name = await usdvContract.name();
26 const symbol = await usdvContract.symbol();
27 const decimals = await usdvContract.decimals();
28 const balance = await usdvContract.balanceOf(walletAddress);
29
30 console.log(`Token: ${name} (${symbol})`);
31 console.log(`Balance: ${ethers.formatUnits(balance, decimals)} ${symbol}`);
32 } catch (error) {
33 console.error("Error fetching USDV data:", error);
34 }
35}
36
37main();