I'm trying to figure out how to send an NFT and display it on a website. Ideally the NFT can be dropped on the account linked to the website and therefore "belongs" to the website at least for a while, this is important for my project because I need to be able to burn the nft or send it back to the user. Actually im using @project-serum/anchor and @solana/web3.js but I can't even get a transfer between the user's wallet and another wallet.
I've spent all day trying to figure out how to do it but I can't get a result. Ideally I would have a button that opens the wallet and shows the different NFT that can be deposited, the user chooses one that is sent to the wallet linked to the site.
I thank you in advance
Try this code:
// This transaction is sending the tokens
var transaction = new web3.Transaction().add(
splToken.Token.createTransferInstruction(
splToken.TOKEN_PROGRAM_ID,
fromTokenAccount.address,
toTokenAccount.address,
fromWallet.publicKey,
[],
1000000, // This is transferring 1 token, not 1000000 tokens
),
);
var signature = await web3.sendAndConfirmTransaction(
connection,
transaction,
[fromWallet],
{commitment: 'confirmed'},
);
console.log("SIGNATURE: ", signature);
let tokenBalance = await toTokenAccount.amount;
console.log("token balance: ", tokenBalance);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.