简体   繁体   English

如何使用 phantom JS 创建关联的令牌地址?

[英]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.

相关问题 如何使用web3.js创建一个新帐户或地址? - How can I create a new account or address with web3.js? 如何使用 web3js 验证 Solana 钱包地址? - How can I validate a Solana wallet address with web3js? 如何使用web3 js按地址获取令牌交易列表 - how to get token transaction list by address using web3 js 如何使用 web3js solana 工具关闭关联的令牌帐户 - How to close associated token account using web3js solana tools 如何创建一个erc20代币生成器,其中创建合约的账户地址是唯一erc20合约地址的代币持有者? - How to create a erc20 token generator where the account address creating contract is the token holder of unique erc20 contract address? 如何通过联系地址转移令牌 - How to Transfer Token via Contact Address 如何过滤给定地址的传入交易? - How can I filter incoming transactions for a given address? 如何使用 @solana/web3.js 从 Solana 中的自定义令牌中删除铸币权限? - How do I remove the minting authority from my custom token in Solana using @solana/web3.js? 如何检查所选帐户是否有我的自定义令牌? - How can I check if the selected account has my custom token? 在浏览器或chrome扩展程序中确认交易之前如何获取web3合约地址? - How can I get the web3 contract address before confirming transaction in the browser or chrome extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM