Created
November 2, 2021 22:28
-
-
Save ronanyeah/61b1fbb702a9f8b98f96c00c57221000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const web3 = require("@solana/web3.js"); | |
const { Token, TOKEN_PROGRAM_ID } = require("@solana/spl-token"); | |
const { MINT_ID } = process.env; | |
const connection = new web3.Connection( | |
web3.clusterApiUrl("mainnet-beta"), | |
"confirmed" | |
); | |
const publicKey = new web3.PublicKey(MINT_ID); | |
(async () => { | |
const res = await connection.getTokenLargestAccounts(publicKey); | |
const owner = res.value.find((x) => x.amount === "1"); | |
if (!owner) { | |
return console.log("no match"); | |
} | |
const token = new Token(connection, publicKey, TOKEN_PROGRAM_ID); | |
const info = await token.getAccountInfo(owner.address); | |
return info.owner.toString(); | |
})() | |
.then(console.log) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment