1

I'm using solana-py and trying to get the owner of an associated token account. I have gotten the associated account address like this:

from solana.publickey import PublicKey
from solana.rpc.api import Client
solana_client = Client("https://solana-api.projectserum.com")

hash = "xxxxxxxxxx"
largest_acc = solana_client.get_token_largest_accounts(PublicKey(hash))
associated_acc = largest_acc["result"]["value"][0]["address"]

How do I get the owner's Solana address? Thanks.

2 Answers 2

1

Try largestAccountInfo.value.data.parsed.info.owner sorry it's not in py, but TS example:

const tokenMint = "9ARngHhVaCtH5JFieRdSS5Y8cdZk2TMF4tfGSWFB9iSK";
const largestAccounts = await connection.getTokenLargestAccounts(
  new PublicKey(tokenMint)
);
const largestAccountInfo = await connection.getParsedAccountInfo(
  largestAccounts.value[0].address
);
console.log(largestAccountInfo.value.data.parsed.info.owner);

source

2
  • I tried this before, but in the response I get {'jsonrpc': '2.0', 'result': {'context': {'apiVersion': '1.10.32', 'slot': 146290374}, 'value': {'data':['pvdOR+GRuzgZXU6mpbJjYQY6qcN8DhqimB66AcZFo8vBRbF/lOk+pCmNec7o8ZDnZOln723JvDEMwMAXIAhbowEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 'base64'], 'executable': False, 'lamports': 2039280, 'owner': 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 'rentEpoch': 337}}, 'id': 2} which doesn't contain the owner address in it.
    – Maxisy
    Aug 16, 2022 at 21:44
  • In python I used largest_info = solana_client.get_account_info(assoc_acc)
    – Maxisy
    Aug 16, 2022 at 21:44
0

I wasn't able to get the other answers on this question to work, however, I was able to get the owner with the public solscan api:

request = requests.get(f"https://public-api.solscan.io/token/holders?tokenAddress={hash}&limit=1&offset=0")
request = request.json()
owner = request["data"][0]["owner"]

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.