通过Metaplex(糖果机)转移NFT
来自Metaplex(Candy Machine)的铸造NFT会自动生成令牌帐户(因为我打算通过JavaScript将其传输给其他所有者)。另外,我正在使用函数getorCreateAssciatedTokenAccount来创建一个令牌帐户,但是我的问题是需要Keypair,我不知道如果我只有一个钱包地址,我不知道在哪里可以找到?这是我的代码:
// wallet address of the owner of NFT but I want to get the keypair here since it is the one that is required for getOrCreateAssociatedTokenAccount
const fromWallet = owner_wallet;
// Public Key of buyer
const toWallet = buyer_wallet;
// NFT mint address
let mint = mint_address;
//connection
const connection = use_connection;
// Get the token account of the toWallet address, and if it does not exist, create it
const toTokenAccount = await getOrCreateAssociatedTokenAccount(connection, fromWallet, mint, toWallet);
// Get the token account of the fromWallet address, and if it does not exist, create it (my problem here is 2nd parameter is looking for keypair but i can only provide a wallet address
const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
fromWallet,
mint,
fromWallet.publicKey
);
const signature = await transfer(
connection,
fromWallet,
fromTokenAccount.address,
toTokenAccount.address,
fromWallet.publicKey,
0
);
console.log(`finished transfer with ${signature}`);
Does the minted NFT from Metaplex(candy machine) automatically generate the Token Account (as I am planning to transfer it to other owner via Javascript). Also, i am using the function getOrCreateAssociatedTokenAccount to create a token account but my problem is it needs keypair and I dont know where to locate if I a only have a wallet address? Here is my code:
// wallet address of the owner of NFT but I want to get the keypair here since it is the one that is required for getOrCreateAssociatedTokenAccount
const fromWallet = owner_wallet;
// Public Key of buyer
const toWallet = buyer_wallet;
// NFT mint address
let mint = mint_address;
//connection
const connection = use_connection;
// Get the token account of the toWallet address, and if it does not exist, create it
const toTokenAccount = await getOrCreateAssociatedTokenAccount(connection, fromWallet, mint, toWallet);
// Get the token account of the fromWallet address, and if it does not exist, create it (my problem here is 2nd parameter is looking for keypair but i can only provide a wallet address
const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
fromWallet,
mint,
fromWallet.publicKey
);
const signature = await transfer(
connection,
fromWallet,
fromTokenAccount.address,
toTokenAccount.address,
fromWallet.publicKey,
0
);
console.log(`finished transfer with ${signature}`);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题与糖果机无关,而与转移NFT有关。在这里看看如何转移令牌: https ://solanacookbook.com/references/basic-transactions.html#how-to-to-send-spl-tokens
This question is not related to candy machine but to transferring NFTs. Have a look here to learn how to transfer tokens: https://solanacookbook.com/references/basic-transactions.html#how-to-send-spl-tokens
我不知道回答是否为时已晚,但是如果有人需要它们,我只是把它放在这里。
我假设您正在从前端使用连接的钱包。因此,您需要做的是:
用
getorCreateAsssciedTokenAccount
函数替换它,您不需要键盘,但是您需要一个连接的钱包。另外,您还必须使用说明来转移Sph-Token。
I don't know if it is too late to answer but I will just put it here in case anyone needs them.
I assume you are using a connected wallet for this from the frontend. So what you need to do is:
Replace this with your
getOrCreateAssociatedTokenAccount
function you won't need a keypair but ya you need a connected wallet.Also you have to use instructions for transfer of SPL-token.