6

I'm looking to query token metadata by looking up the token address(pubkey or mint). Specifically looking for data around the name, symbol, and decimals. Is there an RPC method for this?

How does SolScan do this?

0

3 Answers 3

7

Updated

SPL-Token's name, symbol, logo, and more can be retrieved today the following way:

  1. Get associated Metaplex Metadata Account to check for Metadata
  2. If no metadata exists, check legacy token-list from @solana/spl-token-registry

This means that first priority should be Metaplex Metadata, then @solana/spl-token-registry

Solflare's Unified Token List does this automatically if you want to use their source code.

from How do I get token name, symbol, and logo?


JSON RPC API

use getAccountInfo and make sure to add jsonParsed

curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getAccountInfo",
    "params": [
      "4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA",
      {
        "encoding": "jsonParsed"
      }
    ]
  }
'

@solana/web3.js

use connection.getParsedAccountInfo

let mint = await connection.getParsedAccountInfo(
    new PublicKey('3MoHgE6bJ2Ak1tEvTt5SVgSN2oXiwt6Gk5s6wbBxdmmN')
)

// all the token data is here
console.log(mint.value.data.parsed)
0
0

In Python you can do the following

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


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

print(decimals)

# Output: 6
0

In this answer I discuss some important details for your question:

how to get AccountInfo from serialized data?

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.