0

I want to fetch a token's program account but I don't know the program id. I only have the token mint address. Is it possible to get it? Thanks in advance.

Here is an example. It fetches the program account from Raydium with a specific token mint address.

const accounts = await solanaConnection.getProgramAccounts(
    RAYDIUM_LIQUIDITY_PROGRAM_ID_V4,
    {
      commitment: "confirmed",
      filters: [
        {
          dataSize: LIQUIDITY_STATE_LAYOUT_V4.span,
        },
        {
          memcmp: {
            offset: LIQUIDITY_STATE_LAYOUT_V4.offsetOf('baseMint'),
            bytes: specificTokenMint,
          },
        },
      ],
    }
  );
2
  • do you mean the program that owns a token, i.e. SPL Token or SPL Token Extensions program?
    – Jimii
    Commented Aug 24 at 8:42
  • @Jimii Yes. Check the example code i just added for getting a token's program account which is in Raydium.
    – s.khan
    Commented Aug 24 at 9:19

1 Answer 1

2

If you want to know the program id that owns an account, you can just fetch the account and check the owner field:

const account = await solanaConnection.getAccountInfo(specificTokenMint);
console.log(account.owner);
6
  • Hey, thanks for your reply. Unfortunately, it is not the program id that is returned. I get something like this: ACCOUNT owner: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb. And when I run getProgramAccounts by using it as Program ID, I dont get anything.
    – s.khan
    Commented Aug 31 at 16:43
  • Basically, I'm trying to build an app, that will buy/sell any tokens regardless of which program's liquidity pool it is in. I could do it with Raydium only, and at first I thought if I use any Pump.fun's token there, it will work but sadly it doesnt find the program account that way. And Jupiter's API is pretty slow and fails sometimes. So dont want to go with that route.
    – s.khan
    Commented Aug 31 at 16:51
  • 1
    TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb is the program id for SPL token-2022. And since there are so many accounts that program and SPL token, getProgramAccounts is typically disabled by RPC servers
    – Jon C
    Commented Sep 2 at 12:39
  • But it wouldn't be disabled for Solana native mainnet rpc servers, right? And what do you suggest regarding what I want to achieve?
    – s.khan
    Commented Sep 3 at 18:48
  • 1
    Almost all RPCs will disable the call, especially the public servers, unless you get a custom setup. To be honest, I don't understand what you're trying to achieve, unfortunately. It might be useful to create another question that provides more background with what you want to do, and exactly what you've done to try to achieve it.
    – Jon C
    Commented Sep 4 at 20:11

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.