0

I'm new to Solana. I've created a swapping method to swap Solana tokens, and it has successfully swapped tokens. However, I'm stuck on one problem: I need the decimals of the token to swap Solana tokens. Does anybody know how to get Solana token decimals using any library or something similar? I've used Jupiter API and Moralis API, but I didn't get the correct decimals. Or perhaps I've made some mistakes. So, if anybody knows how to get it, please message me.

1 Answer 1

1

use getParsedAccountInfo rpc method to fetch token details of a particular mint address

const result = await connection.getParsedAccountInfo(new PublicKey(mint), {
          commitment: 'confirmed',
        })

then

const {decimals} = result?.value?.data?.parsed?.info || {};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.