I'm trying to write a Solana program with one instruction, MintOne
, that mints a single token to a provided account.
It seems I need to do something like this:
Conceptually, I am having a hard time with 3. Is it even possible for a program to sign a transaction? The private key is not on chain, so I don’t know how it would work.
Is it possible for a Solana program to be a signer? If not, how is this type of use case usually solved?
Is it possible for a Solana program to be a signer?
Not directly, no.
Any time where you would want a Solana program to sign a transaction, use a Program Derived Address (PDA) instead. PDAs are just like public keys, so they can be mint authorities or anything else that an account address can be. PDAs allow a program to "fake" a signature on a transaction.
For this use case, you can do this:
invoke_signed
or CpiContext::new_with_signer
(if you're using Anchor) with that PDAThis is secure because the Solana allows only that program to "fake" the PDA signature.