I have PDA created in JS this way:
let [pda, bump] = await PublicKey.findProgramAddress( [baseAccount.publicKey.toBuffer(), Buffer.from('1', 'utf8')], programIdPublicKey);
baseAccount
is a usual Solana account.
I send a transaction to execute my Solana program from JS this way:
let transaction = new Transaction().add( new TransactionInstruction({ keys: [ { pubkey: new PublicKey('F69KXy28w8o8XDZYDPJ2axUiJKBLoaPtTuBJRBMLAtWg'), // Token Account where stores PDA tokens isSigner: false, isWritable: true, }, { pubkey: mint, // Public key of this Token isSigner: false, isWritable: false, }, { pubkey: new PublicKey('C12wxNFqMoAVGiWfkFWcPmVShJvXb3AuHBfK5kYJufS7'), // Token Account of the baseAccount, where exists such tokens isSigner: false, isWritable: true, }, { pubkey: mintInfo.mintAuthority, // Public key of the authority of the Token isSigner: false, isWritable: false, }, { pubkey: TOKEN_PROGRAM_ID, // SPL Token Program ID isSigner: false, isWritable: false, }, { pubkey: baseAccount.publicKey, isSigner: false, isWritable: false, }, { pubkey: pda, isSigner: false, isWritable: false, }, ], data: data, // Encoded seed and bump of the PDA programId: programIdPublicKey, }));let trxHash = await sendAndConfirmTransaction( connection, transaction, [baseAccount], { commitment: 'finalized' });
In Solana program I have such code:
ProgramInstruction::Withdraw { seed, bump } => { let source_info = next_account_info(account_info_iter)?; // 1. let mint_info = next_account_info(account_info_iter)?; // 2. let destination_info = next_account_info(account_info_iter)?; // 3. let authority_info = next_account_info(account_info_iter)?; // 4. let token_program_info = next_account_info(account_info_iter)?; // 5. let base_account_info = next_account_info(account_info_iter)?; // 6. let pda_account_info = next_account_info(account_info_iter)?; // 7. let source_account = Account::unpack(&source_info.try_borrow_data()?)?; let amount = source_account.amount; let mint = Mint::unpack(&mint_info.try_borrow_data()?)?; let decimals = mint.decimals; invoke_signed(&transfer_checked( token_program_info.key, source_info.key, mint_info.key, destination_info.key, authority_info.key,&[], amount, decimals, ) .unwrap(),&[ source_info.clone(), mint_info.clone(), destination_info.clone(), authority_info.clone(), token_program_info.clone(), pda_account_info.clone(), base_account_info.clone(), ],&[&[base_account_info.key.as_ref(), seed.as_bytes(), &[bump]]], )?;},
Execution of the code return the Error:Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account
Can anyone help me understand what I'm doing wrong?