How to create a Program Derived Address
A Program Derived Address is simply an account owned by the program, but has
no
private key. Instead it's signature is obtained by a set of seeds and a bump
(a
nonce which makes sure it's 'off curve', i.e. not a valid public key).
"Generating" a Program Address is
different from "creating" it. One can generate a PDA using
Pubkey::find_program_address
. Creating a PDA essentially means to initialize
the address with space and set the state to it. A normal Keypair account can be
created outside of our program and then fed to initialize it's state.
Unfortunately, for PDAs, it has to be created on chain, due to the nature of not
being able to sign on behalf of itself. Hence we use invoke_signed
to pass the
seeds of the PDA, along with the funding account's signature which results in
account creation of a PDA.
One can send the required accounts via client as follows