[英]How can I create an associated token address with phantom JS?
@solana/spl-token
has two methods: @solana/spl-token
有两种方法:
getAssociatedTokenAddress
getOrCreateAssociatedTokenAccount
Context, one only has the public address but access to phantom.上下文,一个只有公共地址但可以访问幻影。
If the associated token already exists, getAssociatedTokenAddress
works well but getOrCreateAssociatedTokenAccount
requires the secret key.如果关联的令牌已经存在,则
getAssociatedTokenAddress
可以正常工作,但getOrCreateAssociatedTokenAccount
需要密钥。
Using Phantom , how can one generate that token address via a signature mechanism?使用Phantom ,如何通过签名机制生成该令牌地址?
Concrete use case: one wants to send USDT to a public that does not have the USDT associated address.具体用例:想要将 USDT 发送给没有 USDT 关联地址的公众。 I would like phantom to somehow sign the action and create that address
我希望幻影以某种方式签署动作并创建该地址
So, if this is all you want to do:所以,如果这就是你想做的全部:
Concrete use case: one wants to send USDT to a public that does not have the USDT associated address.
具体用例:想要将 USDT 发送给没有 USDT 关联地址的公众。 I would like phantom to somehow sign the action and create that address
我希望幻影以某种方式签署动作并创建该地址
You don't need to worry about creating the account directly, since you can just send the token to the wallet, and fund the account creation from the signer.您无需担心直接创建帐户,因为您只需将令牌发送到钱包,并从签名者那里为帐户创建提供资金。 So just a normal
token::transfer
should suffice IIRC.所以只是一个普通的
token::transfer
就足够了 IIRC。
But to answer your first question about how to do some operation that requires a private key using Phantom, the general approach is create a Transaction
in JS, then use the wallet adapter signTransaction
to sign it, and then send/confirm the signed transaction.但是要回答您的第一个问题,即如何使用 Phantom 进行一些需要私钥的操作,一般的方法是在 JS 中创建一个
Transaction
,然后使用钱包适配器signTransaction
进行签名,然后发送/确认已签名的交易。 (Depending on how you send and confirm it, you might have to add in a recent blockhash and payer to the Transaction
as well) (根据您发送和确认的方式,您可能还必须将最近的区块哈希和付款人添加到
Transaction
中)
This is similar to what createAssociatedTokenAccount
does under the hood -- https://github.com/solana-labs/solana-program-library/blob/48fbb5b7/token/js/src/actions/createAssociatedTokenAccount.ts#L30 -- with the added twist of signing via wallet adapter.这类似于
createAssociatedTokenAccount
在幕后所做的 - https://github.com/solana-labs/solana-program-library/blob/48fbb5b7/token/js/src/actions/createAssociatedTokenAccount.ts#L30 -通过钱包适配器签名的额外转折。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.