Direct NFT minting with phantom wallet on solana blockchain without intermediate keypair generation

I’m working on creating NFTs on the solana network and running into some issues. Every tutorial I find seems to use a temporary keypair that gets generated first to mint the tokens, then they transfer everything to the actual wallet afterwards.

Is it possible to skip this step and mint directly to my phantom wallet instead? The current approach feels unnecessarily complicated.

Here’s what I’ve been working with:

import * as solanaWeb3 from '@solana/web3.js';
import * as tokenProgram from '@solana/spl-token';

const connectWallet = async () => {
  if (window.solana && window.solana.isPhantom) {
    return window.solana;
  }
  throw new Error('Phantom wallet not found');
};

const createToken = async () => {
  const wallet = await connectWallet();
  const userPublicKey = wallet.publicKey;
  
  const network = new solanaWeb3.Connection(
    solanaWeb3.clusterApiUrl('devnet'),
    'confirmed'
  );
  
  // This is the part I want to avoid - creating temporary keypair
  const tempKeypair = solanaWeb3.Keypair.generate();
  
  console.log('User wallet:', userPublicKey.toString());
  console.log('Temp keypair:', tempKeypair.publicKey.toString());
  
  // Airdrop for testing
  const airdropTx = await network.requestAirdrop(
    tempKeypair.publicKey,
    solanaWeb3.LAMPORTS_PER_SOL
  );
  
  await network.confirmTransaction(airdropTx);
  
  // Create new token mint
  const tokenMint = await tokenProgram.Token.createMint(
    network,
    tempKeypair,
    tempKeypair.publicKey,
    null,
    9,
    tokenProgram.TOKEN_PROGRAM_ID
  );
  
  // Create token accounts
  const tempAccount = await tokenMint.getOrCreateAssociatedAccountInfo(
    tempKeypair.publicKey
  );
  
  const userAccount = await tokenMint.getOrCreateAssociatedAccountInfo(
    userPublicKey
  );
  
  // Mint tokens to temp account
  await tokenMint.mintTo(
    tempAccount.address,
    tempKeypair.publicKey,
    [],
    1000000000
  );
  
  // Transfer to user wallet
  const transferTx = new solanaWeb3.Transaction().add(
    tokenProgram.Token.createTransferInstruction(
      tokenProgram.TOKEN_PROGRAM_ID,
      tempAccount.address,
      userAccount.address,
      tempKeypair.publicKey,
      [],
      1000000000
    )
  );
  
  const txSignature = await solanaWeb3.sendAndConfirmTransaction(
    network,
    transferTx,
    [tempKeypair]
  );
  
  console.log('Transaction signature:', txSignature);
  console.log('Token mint address:', tokenMint.publicKey.toString());
};

Can someone help me figure out how to mint directly without this two-step process?

yeah, the temp keypair thing sucks but there’s a good reason. someone has to pay rent for creating the mint account, and phantom can’t auto-sign those transactions. use phantom’s signAllTransactions method instead - you can create the mint with your wallet as authority but you’ll still need to handle the transaction signing right.

Hmm, interesting - I’ve been dealing with similar stuff. Why not try the newer Anchor framework instead of spl-token? I think createMint needs a payer keypair for account creation fees, but there are workarounds.

Have you tried Phantom’s signTransaction method to sign the mint creation directly? Also - one-off NFT or batch minting? The approach changes depending on that.

One thing I noticed: you’re airdropping to the temp keypair, but what if you airdropped straight to your Phantom wallet? Use that as the fee payer for mint creation. Cuts out some steps.

Also, the @metaplex-foundation/js library might help since it’s built for NFT workflows. Tried that yet? Let me know what you find - this temp keypair dance is annoying as hell.

You need the temporary keypair because someone has to be the mint authority and pay the account rent when creating the mint. But here’s a better way - just set your Phantom wallet as both mint and freeze authority right from the start. Instead of generating a random keypair, use your connected wallet’s publicKey as the mint authority in createMint. You’ll still sign through Phantom, but this skips the transfer step since you own the mint from day one. Just swap tempKeypair.publicKey with userPublicKey in your mint authority parameters. Make sure your Phantom wallet has enough SOL for the mint account rent. This keeps everything in your wallet the whole time without that extra transfer at the end.