I am searching a way to fund a account using smart conttact, that work fine if the receiver is already done some transactions. This is failing if there is no transactions done on the account.
How can I fix this issue?
pub fn send_sol(ctx: Context<SendSol>, amount: u64) -> Result<()> {
let pda_account = &ctx.accounts.pda_account;
let owner = &ctx.accounts.owner;
let receiver = &ctx.accounts.receiver;
// Validate that the sender is the owner of the PDA
require_keys_eq!(pda_account.owner, *owner.key, PDAError::Unauthorized);
msg!("Owner Matched");
msg!("PDA Account : {}", pda_account.key());
**pda_account.to_account_info().try_borrow_mut_lamports()? -= amount;
**receiver.to_account_info().try_borrow_mut_lamports()? += amount;
msg!(
"Transferred {} lamports from PDA to {}",
amount,
ctx.accounts.receiver.key()
);
Ok(())
}
Thanks