Skip to content

Instantly share code, notes, and snippets.

@Aviksaikat
Last active July 17, 2024 07:33
Show Gist options
  • Save Aviksaikat/9c2a35d1e844610adb8499c8aba79ab6 to your computer and use it in GitHub Desktop.
Save Aviksaikat/9c2a35d1e844610adb8499c8aba79ab6 to your computer and use it in GitHub Desktop.
Get decimals of a token from SOLANA chain from a given address
from spl.token._layouts import MINT_LAYOUT
from solana.rpc.api import Client, Pubkey
http_client = Client("https://api.mainnet-beta.solana.com")
# USDC token address
addr = Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
info = http_client.get_account_info(addr)
decimals = MINT_LAYOUT.parse(info.value.data).decimals
print(decimals)
# Output: 6
@AndreyNikitsich
Copy link

EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v - This is a USDC contract, I was a little confused at the beginning. But thank you very much, it helped me with my task!

@Aviksaikat
Copy link
Author

Thanks for pointing out. I have corrected it.

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