1

我正在关注 solana-web3 文档。

使用splToken.Token.createMint

我能够获得交易 ID 和签名,并能够在资源管理器中查看它们。

如何在铸造时传递我的 NFT 的名称、符号和 iamge URI?我已经尝试过 metaplex 和 token-metadata 标准。但是solana中的资源似乎非常低。

任何人都可以帮助解决这个问题吗?

签名 -2wkwUKo3RradgsT56PQKpV7V1P72WLvuC6ThN5Q78FZBuwV6BbNoSRcgZ17fKwiro5p6rQcYxy4NJoZMJCdTvfgx

Explorer-solana

const web3 = require('@solana/web3.js');
const splToken = require('@solana/spl-token');

(async () => {
  // Connect to cluster
  const connection = new web3.Connection(
    web3.clusterApiUrl('devnet'),
    'confirmed',
  );

  // Generate a new wallet keypair and airdrop SOL
  var fromWallet = web3.Keypair.generate();
  console.log("creating a from wallet ",fromWallet);
  var fromAirdropSignature = await connection.requestAirdrop(
    fromWallet.publicKey,
    web3.LAMPORTS_PER_SOL,
  );
  // Wait for airdrop confirmation
  await connection.confirmTransaction(fromAirdropSignature);

  // Generate a new wallet to receive newly minted token
  const toWallet = web3.Keypair.generate();

  // Create new token mint
  const mint = await splToken.Token.createMint(
    connection,
    fromWallet,
    fromWallet.publicKey,
    null,
    9,
    splToken.TOKEN_PROGRAM_ID,
  );
  console.log("connection details -->",connection);

  // Get the token account of the fromWallet Solana address, if it does not exist, create it
  const fromTokenAccount = await mint.getOrCreateAssociatedAccountInfo(
    fromWallet.publicKey,
  );

  //get the token account of the toWallet Solana address, if it does not exist, create it
  const toTokenAccount = await mint.getOrCreateAssociatedAccountInfo(
    toWallet.publicKey,
  );

  // Minting 1 new token to the "fromTokenAccount" account we just returned/created
  await mint.mintTo(
    fromTokenAccount.address,
    fromWallet.publicKey,
    [],
    1000000000,
  );

  // Add token transfer instructions to transaction
  const transaction = new web3.Transaction().add(
    splToken.Token.createTransferInstruction(
      splToken.TOKEN_PROGRAM_ID,
      fromTokenAccount.address,
      toTokenAccount.address,
      fromWallet.publicKey,
      [],
      1,
    ),
  );

  // Sign transaction, broadcast, and confirm
  const signature = await web3.sendAndConfirmTransaction(
    connection,
    transaction,
    [fromWallet],
    {commitment: 'confirmed'},
  );
  console.log('SOL Explorer SIGNATURE', signature);
  console.log("Transaction ID",transaction);
  console.log("program ID ",splToken.TOKEN_PROGRAM_ID);
  console.log("from account ",fromTokenAccount.address);
})();

4

0 回答 0