-1

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 :)

Karl
  • 3
  • 2

1 Answers1

1

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.

Frank C.
  • 7,758
  • 4
  • 35
  • 45
  • Hi Frank! Thanks for answering. Can it be possible to create a contract that runs every time a wallet receive a transaction? Not based on time, but on interaction in a wallet. – Karl Mar 05 '23 at 17:54
  • No, the only way to ensure that your contract runs based on some event is still some client side function. You'd have to listen for events in an off-chain listener still. – Frank C. Mar 06 '23 at 19:44