5

I am trying to create a front end for minting and transferring tokens to accounts, and the @solana/spl-token library demands a private key for their functions. Is there a way to use solana wallet adapter instead?

2
  • Could you share some code of what you tried?
    – C.OG
    Commented Aug 12, 2022 at 11:53
  • 1
    @C.OG Yeah sorry, I forgot. But the answer by vicyyn is pretty much the code I had. Thanks for the response tho!
    – incog
    Commented Aug 12, 2022 at 12:22

1 Answer 1

5

in your frontend

    const wallet = useAnchorWallet()
    const payer = (wallet as NodeWallet).payer

then

    const mint = await splToken.createMint(program.provider.connection, payer, payer.publicKey, null, 0);

    ata_account = await splToken.createAssociatedTokenAccount(
      program.provider.connection,
      payer,
      mint,
      payer.publicKey,
    );

    await splToken.mintTo(
      program.provider.connection,
      payer,
      mint,
      ata_account,
      payer.publicKey,
      1,
    );

2
  • 1
    Hey, what is the user_nft_account variable you passed in? Is it just the address of the ata_account or the user?
    – incog
    Commented Aug 12, 2022 at 12:25
  • 1
    yeah that should be ata_account. just forgot to change the name
    – vicyyn
    Commented Aug 12, 2022 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.