Let’s say I have 3 accounts: A (owned by my program), B (owned by system program), and C (owned by system program).
B and C are from wallets. C is signed. B is not.
I want to transfer some amount from A to B in my program. Since this debits A, I can simply do:
**B.try_borrow_mut_lamports()? += some_amount; **A.lamports.borrow_mut() -= some_amount;
Now I want to transfer a different amount from C to A in my program. Since this debits C which is owned by the system program, I’ll have to use
system_instruction::transfer. Otherwise, I’d get the error:
invoke( &system_instruction::transfer( &C_pubkey, &A_pubkey, new_amount ), &[ C.clone(), A.clone() ] )?;
However, when I do both transfers, I’ll get the error:
UnbalancedInstruction. But any one transfer works on its own.
How do I get around this issue? I’m not sure why it is unbalanced. If anything, the two transfers are not really related to each other.