solana-token-api
v1.0.2
Published
[](https://www.npmjs.com/package/solana-token-api) [](https://www.npmjs.com/package/solana-token-api) [ to fetch accurate token names, symbols, and logos.
- 🚀 Built for Solana Developers: Perfect for wallets, portfolio trackers, dashboards, or any application needing quick access to Solana token data.
- ⚙️ Lightweight & Focused: Does one job and does it exceptionally well.
💾 Installation
# Using npm
npm install solana-token-api @solana/web3.js
# Using yarn
yarn add solana-token-api @solana/web3.js(Note: @solana/web3.js is a peer dependency, as you'll need it to establish a Connection to the Solana network.)
🚀 Quick Start: Get Token Data in Seconds!
It truly couldn't be simpler. See for yourself:
const { getAddressTokens } = require('solana-token-api');
const { Connection, PublicKey } = require('@solana/web3.js');
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const walletAddress = 'YOUR_SOLANA_WALLET_ADDRESS_HERE'; // Replace with actual address
async function fetchTokenData() {
try {
const tokens = await getAddressTokens(connection, walletAddress);
console.log('Fetched Tokens:', tokens);
} catch (error) {
console.error('Error fetching token data:', error);
}
}
fetchTokenData();📚 API Reference
getAddressTokens(connection, address)
The one and only function you need to use! Fetches all SPL tokens held by a given Solana wallet address, enriching them with metadata and pricing information.
Parameters:
connection: An instance of@solana/web3.jsConnection.address:string
Returns:
mint:string- The mint address of the token.amount:number- The quantity of the token held by the wallet (parsed UI amount).name:string- The full name of the token (e.g., "USD Coin"). Defaults to "UNKNOWN" if not found.symbol:string- The symbol of the token (e.g., "USDC"). Defaults to "UNKNOWN" if not found.logo:string- A URL to the token's logo image. Defaults to "UNKNOWN" if not found.price:number- The current price of one token in USD. Defaults to "0" if pricing data is unavailable.valueUSD:string- The total value of the tokens held in USD, formatted to two decimal places (e.g., "150.75").
🙌 Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page or submit a pull request.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
