每个代币账户都包含有关代币的信息,例如所有者、铸币厂、金额(余额)。
import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
import { getAccount } from "@solana/spl-token";
(async () => {
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const tokenAccountPubkey = new PublicKey(
"2XYiFjmU1pCXmC2QfEAghk6S7UADseupkNQdnRBXszD5",
);
let tokenAccount = await getAccount(connection, tokenAccountPubkey);
console.log(tokenAccount);
/*
{
address: PublicKey {
_bn: <BN: 16aef79dfadb39ffedb3b6f77688b8c162b18bb9cba2ffefe152303629ae3030>
},
mint: PublicKey {
_bn: <BN: 7351e5e067cc7cfefef42e78915d3c513edbb8adeeab4d9092e814fe68c39fec>
},
owner: PublicKey {
_bn: <BN: df30e6ca0981c1a677eed6f7cb46b2aa442ca9b7a10a10e494badea4b9b6944f>
},
amount: 0n,
delegate: null,
delegatedAmount: 0n,
isInitialized: true,
isFrozen: false,
isNative: false,
rentExemptReserve: null,
closeAuthority: null
}
*/
})();
https://solana.com/zh/developers/cookbook/tokens/get-token-account
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://www.bcskill.com/index.php/archives/2312.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!
楼主残忍的关闭了评论