How to define name,symbol,uri,decimals for My NFT while using splToken.Token.createMint solana-web3 SDK?

Viewed 462

I am following solana-web3 docs.

using splToken.Token.createMint

I am able to get Transaction ID and signature and able to view the same in explorer.

How to pass name,symbol and iamge URI of my NFT while minting ? I have tried metaplex and token-metadata standard. but resources seems to be very low in solana.

can any one help this out ?

signature - 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);
})();

0 Answers
Related