Skip to content
New issue

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

Add support for Solana Tokens #956

Open
4 tasks
ochhii1337 opened this issue Aug 16, 2024 · 0 comments
Open
4 tasks

Add support for Solana Tokens #956

ochhii1337 opened this issue Aug 16, 2024 · 0 comments

Comments

@ochhii1337
Copy link
Contributor

Requested functionality area

  • Wallet
  • Chain
  • Provider
  • Other

Details

Use @solana/spl-token-registry to retrieve the token symbol. And @solana/web3.js + @solana/spl-token to retrieve the decimals

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant