9

I'm writing a program where I'm fetching the program_address (as below) and now I want to convert the publicKey to AccountInfo and use it to do token transfer CPI.

let (asset, bump_seed) = Pubkey::find_program_address(&[pool.aup[index as usize].to_string().as_ref(), pool.key().as_ref()], &program_id);

2 Answers 2

12

You can't, all the accounts you want to use have to be passed as arguments. You can derive this account on the front end, and validate it with constraints on the protocol side, but you must pass it as an account if you want to read/write its data or use it for a CPI.

2
  • how about AccountInfo::new() Commented Sep 1, 2022 at 0:22
  • @GajeshSNaik It does not work in this case AFAIK
    – ㅤㅤㅤ
    Commented Oct 12 at 9:21
4

Unfortunately, you cannot do so. All 'going-to-use accounts' must be passed from the client (frontend). This is how, solana parallelism works. To process tx in parallel, the Solana runtime must first determine which accounts are for read and which are for write. You can read more about the solana's programming modal here

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.