-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-balance.ts
More file actions
71 lines (60 loc) · 2.18 KB
/
check-balance.ts
File metadata and controls
71 lines (60 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Check wallet USDC balance on Base Sepolia
*/
import { createPublicClient, http, formatUnits } from 'viem';
import { baseSepolia } from 'viem/chains';
// USDC on Base Sepolia
const USDC_ADDRESS = '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
const AGENT_WALLET = '0xa2A7358dDFcf7B1738C08E4E2A910B2D9F018E39';
const SELLER_WALLET = '0xB9b4aEcFd092514fDAC6339edba6705287464409';
const client = createPublicClient({
chain: baseSepolia,
transport: http(),
});
async function checkBalances() {
console.log('Checking wallet balances on Base Sepolia...\n');
// ERC20 balanceOf ABI
const erc20Abi = [{
inputs: [{ name: 'account', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
}] as const;
// Check ETH balance
const agentEth = await client.getBalance({ address: AGENT_WALLET as `0x${string}` });
const sellerEth = await client.getBalance({ address: SELLER_WALLET as `0x${string}` });
console.log(`Agent Wallet: ${AGENT_WALLET}`);
console.log(` ETH: ${formatUnits(agentEth, 18)} ETH`);
// Check USDC balance
try {
const agentUsdc = await client.readContract({
address: USDC_ADDRESS as `0x${string}`,
abi: erc20Abi,
functionName: 'balanceOf',
args: [AGENT_WALLET as `0x${string}`],
});
console.log(` USDC: ${formatUnits(agentUsdc, 6)} USDC`);
if (agentUsdc === 0n) {
console.log('\n⚠️ Agent wallet has 0 USDC!');
console.log(' Get testnet USDC from: https://faucet.circle.com/');
console.log(' Select "Base Sepolia" network');
}
} catch (e) {
console.log(` USDC: Error reading balance - ${e}`);
}
console.log(`\nSeller Wallet: ${SELLER_WALLET}`);
console.log(` ETH: ${formatUnits(sellerEth, 18)} ETH`);
try {
const sellerUsdc = await client.readContract({
address: USDC_ADDRESS as `0x${string}`,
abi: erc20Abi,
functionName: 'balanceOf',
args: [SELLER_WALLET as `0x${string}`],
});
console.log(` USDC: ${formatUnits(sellerUsdc, 6)} USDC`);
} catch (e) {
console.log(` USDC: Error reading balance - ${e}`);
}
}
checkBalances().catch(console.error);