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?
1 Answer
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,
);