如何获取对以前在 Solana 中创建的令牌的引用(客户端,JS)

How to get a reference to a former created Token in Solana (client side, JS)

我可以创建一个令牌并将其铸造到 spl 帐户地址中。 但是当我重新启动我的程序时,我如何获得对该令牌的引用,以便我再次铸造?

const web3 = require("@solana/web3.js");
const splToken = require('@solana/spl-token');
const { PublicKey, Keypair, Transaction, SystemProgram, LAMPORTS_PER_SOL, sendAndConfirmTransaction, clusterApiUrl } = require("@solana/web3.js");

let secretKey = Uint8Array.from([233, 65, 11, rest of my secret]);
let fromWindowsWallet = Keypair.fromSecretKey(secretKey);

let connection = new web3.Connection(clusterApiUrl('devnet'));

(async () => {
    //create my new token mint
     let SWAB = await splToken.Token.createMint(
         connection,
         fromWindowsWallet,
         fromWindowsWallet.publicKey,
         fromWindowsWallet.publicKey,
         2,
         splToken.TOKEN_PROGRAM_ID,
     );
    console.log(SWAB.publicKey) // -> PublicKey {
                      _bn: <BN: 2643549b60882496a15407c2f1a6139dd2c4128879480b1d56fdd464550db22b>
  }
// ... continue with that Token SWAB
}

所以当我重新启动我的程序时,我怎样才能再次获得对令牌 SWAB 的引用?我试过了:

let pubKey = new PublicKey("<BN: 6ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9>");
let SWAB = new splToken.Token(
        connection,
        pubKey,
        splToken.TOKEN_PROGRAM_ID,
        fromWindowsWallet
    )

但这会抛出:错误:非 base58 字符

创建令牌后,我可以通过以下方式获取公钥:

console.log(SWAB.publicKey.toBase58())  // 3aN3KP6kQdBvTHTeK785Uuykddram97B844RoJc19VNS

然后我可以像这样获得对令牌的引用并继续铸造:

let pubKey = new PublicKey('3aN3KP6kQdBvTHTeK785Uuykddram97B844RoJc19VNS');
let SWAB = new splToken.Token(
        connection,
        pubKey,
        splToken.TOKEN_PROGRAM_ID,
        fromWindowsWallet
    )

connectionfromWindowsWallet 在我的问题的代码中定义)