2

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.

4 Answers 4

2

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
    Commented Aug 16, 2022 at 21:44
  • In python I used largest_info = solana_client.get_account_info(assoc_acc)
    – Maxisy
    Commented 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"]
0

Just using "getAccountInfo" will provide you with owner which is token program. But if you need public address of the owner associated with this token account. you can use this payload.

payload = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "getAccountInfo",
        "params": [
            address, {
        "encoding": "jsonParsed"
      }
        ]
    }

"jsonParsed" is the key here. in the result of this first owner address is what your are looking for.

0

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"] is api good ? i found it need token to send request, is that token is long live ?

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.