LoginSignup
0
0

More than 1 year has passed since last update.

【Solana, TypeScript】NFTのmintアドレスから現在のオーナーアドレスを取得

Last updated at Posted at 2022-03-21

動作確認環境

  • M1 Mac (macOS Monterey 12.3)
  • @solana/web3.js : 1.36.0

コード

connection変数は@solana/wallet-adapterで取得したもの。
getTokenLargestAccountsで対象トークンを多く所有しているアカウントのアドレスがわかる。

sample.ts
import * as web3 from '@solana/web3.js';

const getNftOwner = (mintAddress: string): Promise<string> => {
  return connection
    .getTokenLargestAccounts(new web3.PublicKey(mintAddress))
    .then(res => {
      const tokenAccount = res.value[0].address;
      return connection.getParsedAccountInfo(tokenAccount);
    })
    .then(res => {
      const data = res.value?.data as web3.ParsedAccountData;
      const ownerAddress = data.parsed.info.owner;
      return ownerAddress;
    });
};

// How to use (Owner of "Degen Ape #1506")
const address = 'HgDxaNFdq5HExHm2am6UfvVeiCTWdT6J5UzVu4NQR9MN';
getNftOwner(address).then(res => console.log('owner:', res));

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0