0

since everything it's an account, how to categorize this into 3 : nft, lp token, spl token/spl token 2022 ?

assuming i've below code :

const accounts = await connection.getTokenAccountsByOwner(payer, {
        programId: TOKEN_PROGRAM_ID,
});
for (const { pubkey, account } of [...accounts.value]) {
        const rawResult = SPL_ACCOUNT_LAYOUT.decode(account.data);
        
        const { mint, amount } = rawResult;
        const info = await connection.getAccountInfo(mint);
        // how to differentiate this account info ? 
 }

1 Answer 1

3

You can use connection.getParsedAccountInfo(mint), which will give you the JSON of the mint account.

Stackblitz example: https://stackblitz.com/edit/node-6hvxsq?file=index.mjs

const mint = await connection.getParsedAccountInfo(mintPublicKey, 'confirmed');
console.log(address.toString());
console.log(mint.value.data);

This will output something like:

By253LU6m7W6mVapyqBR4uJu23XjdEGBwLYL9WikNYA1
{
  parsed: {
    info: {
      decimals: 9,
      freezeAuthority: 'By253LU6m7W6mVapyqBR4uJu23XjdEGBwLYL9WikNYA1',
      isInitialized: true,
      mintAuthority: 'By253LU6m7W6mVapyqBR4uJu23XjdEGBwLYL9WikNYA1',
      supply: '876233903000000000'
    },
    type: 'mint'
  },
  program: 'spl-token',
  space: 82
}

You can identify an NFT from this data: it will have decimals=0 and supply=1

AFAIK there's no easy way to distinguish an LP token from not though, because they are just SPL tokens with a special meaning to certain programs. There's nothing stored on-chain that distinguishes them. If I had to guess, you might be able to use the mintAuthority if a given platform uses the same authority for all its LP tokens.

1
  • Agreed. Depending on your (op) use case, you can use any number of datapoints to differentiate LP tokens if you know that the ones you're targeting share a trait (such as mint authority). You could also make a second query to get its metadata and make differentiations based on that.
    – Morgandril
    Commented May 9 at 20:54

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.