We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use @solana/spl-token-registry to retrieve the token symbol. And @solana/web3.js + @solana/spl-token to retrieve the decimals
@solana/spl-token-registry
@solana/web3.js
@solana/spl-token
Example
const { Connection, clusterApiUrl, PublicKey } = require('@solana/web3.js'); const { getMint } = require('@solana/spl-token'); const { TokenListProvider } = require('@solana/spl-token-registry'); // Connect to Solana mainnet const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed'); // Mint address of the token const mintAddress = new PublicKey('YourMintAddressHere'); // Replace with the actual mint address async function getTokenDetails(mintAddress) { // Get mint information const mintInfo = await getMint(connection, mintAddress); // Extract decimals const decimals = mintInfo.decimals; // Get token symbol const tokens = await new TokenListProvider().resolve(); const tokenList = tokens.filterByChainId(101).getList(); // Chain ID 101 is for Solana Mainnet Beta const token = tokenList.find((t) => t.address === mintAddress.toString()); const symbol = token ? token.symbol : null; return { symbol, decimals }; } getTokenDetails(mintAddress).then(({ symbol, decimals }) => { console.log('Token Symbol:', symbol); console.log('Token Decimals:', decimals); });
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Requested functionality area
Details
Use
@solana/spl-token-registry
to retrieve the token symbol. And@solana/web3.js
+@solana/spl-token
to retrieve the decimalsExample
The text was updated successfully, but these errors were encountered: