Setting metadata attributes like name, symbol, and URI when creating NFTs with splToken.Token.createMint in Solana

I’m working with the Solana web3 SDK and need help adding metadata to my NFT.

I can successfully create tokens using splToken.Token.createMint and the transaction shows up in the explorer with a valid signature. However, I can’t figure out how to attach the basic NFT properties during the minting process.

What I need to add:

  • Token name
  • Symbol
  • Image URI
  • Decimal places

What I’ve tried:
I looked into Metaplex and the token-metadata standard but found limited documentation and examples for Solana development.

My current code:

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

(async () => {
  // Establish connection to devnet
  const rpcConnection = new solanaWeb3.Connection(
    solanaWeb3.clusterApiUrl('devnet'),
    'confirmed',
  );

  // Create wallet and request airdrop
  var creatorWallet = solanaWeb3.Keypair.generate();
  console.log("generated creator wallet ", creatorWallet);
  var airdropTx = await rpcConnection.requestAirdrop(
    creatorWallet.publicKey,
    solanaWeb3.LAMPORTS_PER_SOL,
  );
  
  await rpcConnection.confirmTransaction(airdropTx);

  // Create recipient wallet
  const recipientWallet = solanaWeb3.Keypair.generate();

  // Initialize new token mint
  const tokenMint = await tokenProgram.Token.createMint(
    rpcConnection,
    creatorWallet,
    creatorWallet.publicKey,
    null,
    9,
    tokenProgram.TOKEN_PROGRAM_ID,
  );

  // Setup token accounts
  const creatorTokenAccount = await tokenMint.getOrCreateAssociatedAccountInfo(
    creatorWallet.publicKey,
  );

  const recipientTokenAccount = await tokenMint.getOrCreateAssociatedAccountInfo(
    recipientWallet.publicKey,
  );

  // Mint tokens
  await tokenMint.mintTo(
    creatorTokenAccount.address,
    creatorWallet.publicKey,
    [],
    1000000000,
  );

  // Transfer tokens
  const transferTx = new solanaWeb3.Transaction().add(
    tokenProgram.Token.createTransferInstruction(
      tokenProgram.TOKEN_PROGRAM_ID,
      creatorTokenAccount.address,
      recipientTokenAccount.address,
      creatorWallet.publicKey,
      [],
      1,
    ),
  );

  const txSignature = await solanaWeb3.sendAndConfirmTransaction(
    rpcConnection,
    transferTx,
    [creatorWallet],
    {commitment: 'confirmed'},
  );
  
  console.log('Transaction signature:', txSignature);
})();

Where exactly should I add the metadata creation step? Any working examples would be really helpful.

The problem is splToken.Token.createMint only handles token mechanics - it doesn’t touch NFT metadata. You’ll need Metaplex’s Token Metadata Program after creating your mint. First, install: npm install @metaplex-foundation/mpl-token-metadata. Then add metadata creation right after your createMint call but before minting tokens. Your mint config is wrong for NFTs - use decimals: 0 and supply: 1, not 1000000000. The metadata instruction needs your mint address, update authority (creator wallet), and a metadata object with name, symbol, and URI pointing to your JSON file. Host that JSON externally (IPFS, Arweave, whatever) with your image URI and other properties. The on-chain metadata just references where that JSON lives. Use createCreateMetadataAccountV3Instruction from mpl-token-metadata. It creates an instruction you add to a transaction and send.

Hey! I’ve been down this exact rabbit hole before and it took me way too long to figure out :sweat_smile:

splToken.Token.createMint only creates the basic token structure. NFT metadata gets stored separately using Metaplex’s token metadata program. You need two transactions: one for the mint (which you have) and another for the metadata.

You’re minting 1000000000 tokens - are you sure you want an NFT? NFTs usually have a supply of 1 and 0 decimals. Maybe you’re doing something different?

Metadata creation happens after your mint is created but before (or after) you mint the tokens. You’ll need the @metaplex-foundation/mpl-token-metadata package and call createMetadataAccountV3 or similar.

What kind of NFT project are you building? Have you considered using the newer Metaplex JS SDK instead of the lower-level token metadata calls? It might save you some headaches.

Quick question - when you say “image URI”, do you already have your metadata json file hosted somewhere? That’s usually the URI you’d put in the metadata account, not directly the image link.

Let me know what specific part is giving you trouble and I can dig up some working code examples!

hit this exact issue last week! You’re mixing regular token creation with nft stuff. splToken.createMint won’t handle metadata - that’s metaplex’s job. after you create the mint, add metadata using @metaplex-foundation/mpl-token-metadata. also set decimals to 0 and mint quantity to 1 for proper NFTs. Metadata lives in a separate account that’s linked to your mint address.