英文:
How to create a Solana program to constantly check wallet funds and transfer them to another wallet?
问题
我是一个在Web3领域新手但有实验经验的程序员。我想尝试在Solana上创建我的第一个智能合约。
我有一个Phantom Solana钱包,我想创建一个智能合约,用于检查我的钱包是否收到了任何代币的交易,并将收到的代币相同数量发送到另一个Solana钱包。是否有方法可以实现这个目标?欢迎任何建议
英文:
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
答案1
得分: 1
如果你想让合同运行,你必须创建一个调用你的合同的交易。合同不会自己运行,也不会基于某个时间间隔。
为了实现你所说的,你需要在客户端创建一些工具,定期轮询你的钱包,如果有代币,就用代币ID调用你的合同。
或者,进行一些事件监听,并从链下监听器触发它。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论