Reputation: 185
I want to make some calculations and store their result in an account after user sends some money to my PDA. How can I do it? My understanding is that I cannot transfer funds from user inside a smart contract, and I can only transfer from my PDA to user, not vice verse, am I correct? Is it a proper solution, if I store my lamports amount in an account, and then inside my instrucition compare the previous value to the actual value, and from front end I run transfer of SOL and my instruction as 2 instructions of a single transaction?
Upvotes: 0
Views: 692
Reputation: 8088
First: You can send SOL/lamports within your program from a PDA, shown here, or program owned account to any account.
Secondly: You can use CPI within your program to transfer SOL/lamports from a system owned account to your program but you will need the source signer to do so.
So, if your instruction took the signer's account you could transfer SOL from their account to your PDA in one instruction (although you are invoking the transfer within your instruction to get the source SOL).
Upvotes: 2