Get NFT

Does A Wallet Has A Specific NFT

import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { Connection } from "@solana/web3.js";

(async () => {
  let connection = new Connection("https://solana-api.projectserum.com");
  console.log(
    await connection.getProgramAccounts(TOKEN_PROGRAM_ID, {
      filters: [
        {
          dataSize: 165,
        },
        {
          memcmp: {
            offset: 0,
            bytes: "your mint address here",
          },
        },
        {
          memcmp: {
            offset: 32,
            bytes: "your owner address here",
          },
        },
        {
          memcmp: {
            offset: 64,
            bytes: "Ahg1opVcGX", // bs58 for [1,0,0,0,0,0,0,0], it is a byte array for u64 little endian
          },
        },
      ],
      dataSlice: {
        offset: 0,
        length: 0,
      },
    })
  );
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Last Updated: 9/23/2022, 6:56:02 PM
Contributors: Yihau Chen