I am trying to build an NFT marketplace where the NFT will be transferred to an escrow wallet a PDA with seeds and the SOL will be transferred from the buyer to a PDA with seeds = "bid" and address of the mint, Now upon successful completion of the NFT being deposited to the escrow wallet users will bid on the NFT and if there is a previous bidder then the amount will be transferred back to the previous bidder and the new bidder's bid will be transferred to the "bid" PDA Now I have successfully transferred the NFT from the escrow wallet to the buyer's wallet by using cpi to sign the transaction on behalf of my program but i also want to transfer the SOL from the PDA to the seller's wallet..i tried using https://solanacookbook.com/references/programs.html#how-to-transfer-sol-in-a-program to transfer the SOL stored in "bid" PDA(This PDA is owned by my program) to the previous bidder but nothing is happening i.e no SOL transfer is taking place from my bid account to the previous bidder though the program is returning success
let amount_of_lamports: u64 = 1000000;
let from_account = ctx.accounts.bid_state.to_account_info();
let to_account = ctx.accounts.user_bidding_past.to_account_info();
msg!("from_account is {}", ctx.accounts.bid_state.key() );
msg!("to_account is {}", ctx.accounts.user_bidding_past.key );
**from_account.try_borrow_mut_lamports()? -= amount_of_lamports;
**to_account.try_borrow_mut_lamports()? += amount_of_lamports;
I am passing the user_bidding_past and bid_state as accounts in my function place_new_bids . bid_state is just a struct defining the bids.
#[account]
#[derive(Default)]
pub struct Bid {
// A primary key that allows us to derive other important accounts
idx: u64,
//amount that the user will bid with.
pub amount : u64,
// Alice
pub user_sending: Pubkey,
// the user bidding on the item.
pub user_bidding: Pubkey,
//the market wallet
pub market_wallet: Pubkey,
// The Mint of the token that bidder wants to bid on
pub mint_of_token_being_sent: Pubkey,
// The escrow wallet
pub escrow_wallet: Pubkey,
// An enumm that is to represent some kind of state machine
pub stage: u8,
}
Is there something that I am missing about the transfer being done in this way? because the cookbook mentions that Your Solana Program can transfer lamports from one account to another without 'invoking' the System program. The fundamental rule is that your program can transfer lamports from any account owned by your program to any account at all. And if I am on the wrong path can someone please guide me on the correct path to achieve what I am trying to do..thanks for your help in advance
**UPDATE 1**
I removed all the different parameters of the seeds from the "bid" account and only left the "bid" keyword as shown in the answer given but now I am getting the following error : Phantom - RPC Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: invalid program argument don't know what is the problem.
from
andto
accounts are being passed in as the same address. It would help to see the rest of your program & your test.