I am currently sorting through spl-token transfers using the @solana/web3.js library and I need to know the spl token address that is associated with a certain token account to find out which token is being transacted upon.
1 Answer
From you question it seems that you want to fetch the mint from a token account.
You can do that using the getAccount method from the @solana/spl-token
library
In code
import { getAccount } from "@solana/spl-token";
// .. add missing imports
async function getMintFromATA() {
const tokenAccount = new PublicKey(
"6SNzQwN2hJBDQnM7bBhYvnHhBg9YJ7Rj6cRLkWhE7nKp"
); // ! update me
const tokenAccountData = await getAccount(conn, tokenAccount);
console.log(tokenAccountData);
}
getMintFromATA().then().catch(console.error);
Which would output something similar to this
{
address: PublicKey [PublicKey(6SNzQwN2hJBDQnM7bBhYvnHhBg9YJ7Rj6cRLkWhE7nKp)] {
_bn: <BN: 50cad1a2b2ae09cc9352778d68d6195313c936491f3c068bd9f23701b1a38b17>
},
mint: PublicKey [PublicKey(BpBqiAoNFYVZr8vr3V5CHFX3HkRwnihNcKnzvxAEZ38e)] {
_bn: <BN: a0ab6c85eba712b61487cacec200b24dbb3b2082e55ec048d40a8eb9c791ecb3>
},
owner: PublicKey [PublicKey(4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF)] {
_bn: <BN: 37c34900bf1a372082b2ec0e9633ee30254fe19c6bce3a1eab456fc51030cf5c>
},
amount: 1321102000099994n,
delegate: null,
delegatedAmount: 0n,
isInitialized: true,
isFrozen: false,
isNative: false,
rentExemptReserve: null,
closeAuthority: null,
tlvData: <Buffer >
}
-
Thanks I was able to use the .toBase58() method to extract the mint address. Commented Jun 26 at 1:13