How to do transfer lamppost from one account to another which has different Program ID?

how we can write Solana smart contract to transfer lampost from one account to another account which have different Program ID.

suppose Program ID assigned to the first account is System Program
and Program Id assigned to the second account is Smart contract program ID.

If you owned that first account, you don’t need to worry about the second account.
If you have authority to debt account, you can send to any accounts except program executable accounts.

Program ID assigned to first program is System program and
Program ID of second program is my smart contract

i want to transfer lamports from first account to second account
so how can i do this

Hi @0jatin and welcome to the forum! :wave

I believe you can use the transfer instruction from the system program to transfer lamports out of the account and into the one that is owned by your program.

if i use system instruction it will hit system program instead of my smart contract.,

i want to deduct some charges/taxes from payer also , so that calculation of tax is done in smart contract , payer is first account , but my smart contract does not have authority to deduct from it , because my smart contract is not owner of first account.

You can invoke the system program’s transfer instruction from inside the code for your smart contract.

Since the payer has signed the transaction to your smart contract, you should be able to pass the account info of the payer into the invoke function. This will authorize you to call the system program’s transfer instruction on behalf of the payer.

So because the payer has signed your transaction to your smart contract, your smart contract can now invoke transactions to other smart contracts, such as the system program, on behalf of the payer.