michaelhly / solana-py

Solana Python SDK

Home Page:https://michaelhly.github.io/solana-py

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get token decimals from a given Public key

Aviksaikat opened this issue · comments

I'm the js SDK for SPL token there is a method called getMint which retrieves information about a mint. Which can be further used to extract decimals, supply, metadata etc. How can do this using sonala-py?

Edit: I hacked a way to do this but it's quite complicated

from spl.token._layouts import MINT_LAYOUT
from solana.rpc.api import Client, Pubkey


http_client = Client("https://api.mainnet-beta.solana.com")
addr = Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
info = http_client.get_account_info(addr)
decimals = MINT_LAYOUT.parse(info.value.data).decimals

print(decimals)