如何创建一个Solana程序,不断检查钱包资金并将其转账到另一个钱包?

huangapple go评论42阅读模式
英文:

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

问题

我是一个在Web3领域新手但有实验经验的程序员。我想尝试在Solana上创建我的第一个智能合约。

我有一个Phantom Solana钱包,我想创建一个智能合约,用于检查我的钱包是否收到了任何代币的交易,并将收到的代币相同数量发送到另一个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 如何创建一个Solana程序,不断检查钱包资金并将其转账到另一个钱包?

答案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.

huangapple
  • 本文由 发表于 2023年3月3日 22:24:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定