How to transfer NFTs minted with Metaplex candy machine between wallets

I’m trying to understand how to transfer NFTs after minting them using the Metaplex candy machine. When an NFT is minted, does it automatically create the associated token account?

I want to move the NFT to another owner using JavaScript. I’m using the getOrCreateAssociatedTokenAccount function, but it’s asking for a keypair as a parameter. The problem is, I only have the wallet address and not the keypair. What should I do?

Here’s my current code:

// Wallet address of the NFT holder - I need the keypair here
const currentOwnerWallet = owner_wallet;
// Buyer’s public wallet address
const buyerWallet = buyer_wallet;
// Mint address of the NFT
let nftMintAddress = mint_address;
// Setting up the connection
const connection = use_connection;

// Create token account for the buyer
const buyerTokenAccount = await getOrCreateAssociatedTokenAccount(
    connection,
    currentOwnerWallet,
    nftMintAddress,
    buyerWallet
);

// This is where I am running into issues - I need the keypair but only have an address
const ownerTokenAccount = await getOrCreateAssociatedTokenAccount(
    connection,
    currentOwnerWallet,
    nftMintAddress,
    currentOwnerWallet.publicKey
);

const transactionSignature = await transfer(
    connection,
    currentOwnerWallet,
    ownerTokenAccount.address,
    buyerTokenAccount.address,
    currentOwnerWallet.publicKey,
    0
);
console.log(`Transfer successfully completed with signature: ${transactionSignature}`);

How can I retrieve the keypair from just the wallet address?

The issue you’re facing stems from a fundamental misunderstanding of how wallet ownership works. You cannot derive a keypair from a public address - that would completely break the security model of blockchain systems. What you need to implement is a proper transaction flow where the current owner signs the transfer transaction. Instead of trying to access their keypair directly, you should create the transaction and have the owner sign it through their wallet interface. Most wallets like Phantom or Solflare provide JavaScript APIs for this. For Metaplex NFTs, yes they do create associated token accounts automatically during minting. Your approach should be to build the transfer transaction, serialize it, then send it to the owner’s wallet for signing. The owner maintains control of their private keys while still being able to execute the transfer you’ve prepared.

oh wait, i think i see what’s happening here! are you maybe trying to build some kind of marketplace or automated transfer system? because if thats the case, you’re definitely on the wrong track with trying to get the keypair from an address.

what you probably want to look into is either wallet adapters (like @solana/wallet-adapter) or maybe even program derived addresses if you’re building something more complex. but honestly, im curious - what’s the bigger picture here? are you building a trading platform or just trying to move your own nfts around?

if its your own nfts, you should already have access to your own keypair/seed phrase. if you’re building something for other people to use, then you definetly need to implement proper wallet integration where users connect their wallets and sign transactions themselves.

also just wondering - have you considered using solana’s web3.js PublicKey.findProgramAddress() for any of this? depending on what you’re actually trying to accomplish, there might be some interesting approaches with PDAs that could help.

what exactly are you building? that would help figure out the best approach!

you cant get the keypair just from the wallet address, that’s how security works. the current owner has to sign the transaction. they either need to share their keypair (which is risky) or sign the transaction themselves.