使用Rust传递SPL令牌
有没有办法将SPL令牌从钱包转移到另一个钱包。 我做了一些研究,发现我必须首先使用创建关联帐户初始化帐户,然后使用令牌转移?
是否有任何代码示例可以传输令牌或库来帮助创建帐户/令牌传输。 ETC
Is there a way to transfer SPL tokens from on wallet to another.
I have done some research and I found that I have to initialize account first using Create Associated Account and then use Token Transfer?
Is there any code examples where I can transfer tokens or a library which helps with creating account/token transfer. etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以直接使用
spl-token
箱来获取令牌程序使用的指令和类型:https://docs.rs/spl-token/latest/spl_token/如果您需要创建关联的token账户,可以使用
spl-linked-token-account
箱:https://docs.rs/spl-linked-token-account/latest/spl_linked_token_account/index.html如果您在链上,则可以创建一条
转账
指令并将其与所需的帐户一起传递,即:这是根据
代币交换
转账代码改编的:https://github.com/solana-labs/solana-program-library/blob/b2fad8a0781bddd90c8e9b768184f55306265cef/token-swap/program/src/processor.rs#L138您需要创建
源
和目标
帐户首先,最好是关联令牌帐户。您可以使用以下方法在链上创建它们:请注意,所有这些帐户必须发送到您的程序才能执行跨程序调用。
You can directly use the
spl-token
crate for instructions and types used by the token program: https://docs.rs/spl-token/latest/spl_token/If you need to create associated token accounts, you can use the
spl-associated-token-account
crate: https://docs.rs/spl-associated-token-account/latest/spl_associated_token_account/index.htmlIf you're on-chain, you can create a
transfer
instruction and pass it in along with the required accounts, ie:This was adapted from the
token-swap
transfer code: https://github.com/solana-labs/solana-program-library/blob/b2fad8a0781bddd90c8e9b768184f55306265cef/token-swap/program/src/processor.rs#L138It's correct that you need to create the
source
anddestination
accounts first, and it's preferred for those to be associated token accounts. You can create them on-chain using:Note that all of these accounts must be sent to your program in order to perform the cross-program invocations.
Afaik 没有库,但令牌传输只能在帐户之间进行,锚点内有一个传输函数,您必须调用该函数并传递来往帐户信息,您可以直接转移到某个地址,因为您也需要接收者的帐户信息你可以从公钥中获得它,但它可以通过托管来完成,这是我编写的一个程序,它将 sol 发送到 PDA,并且接收者从 PDA
托管程序的 Github 链接
Afaik theres no library but token transfer only works from account to account, theres a transfer function inside anchor which you have to invoke and pass the to and from account infos, you can transfer directly to an address beacuse you wud need account info of receiver too which u can get from a publickey but it can be done through escrow, heres a program that i wrote which sends sol to a PDA and the receiver accepts it from PDA
Github link to escrow program