solanasolana-web3jssolana-transaction-instruction

How to create a Solana program to constantly check wallet funds and transfer them to another wallet?


I'm new in web3 but experimented programmer. I want to try to make my first smart contract in Solana.

I have a Phantom Solana wallet, and I want to create a smart contract that checks if my wallet have received any transaction of any token, and send the same amount of tokens received to another solana wallet. Is there any way to do it? Any suggestions are welcome :)


Solution

  • If you want your contract to run you have to create a transaction that calls your contract. Contracts don't run on their own or based on some time interval.

    In order for you to achieve what you are talking about you'd have to create some tooling on the client side that polls you wallet at some interval and if it has tokens, then invoke your contract with the token IDs.

    Or, do some event listening and trigger it from the offchain listener.