Created
April 8, 2022 01:01
-
-
Save vit0rr/c35db2e99314ed8d7ac2a22ee15b1e1e to your computer and use it in GitHub Desktop.
Transfer a NFT with Solana Web3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Every req.body.{} is from Postman | |
const nftAddress = await new web3.PublicKey(req.body.nftAddress); | |
const getNftATA = await spl.Token.getAssociatedTokenAddress( | |
spl.ASSOCIATED_TOKEN_PROGRAM_ID, | |
spl.TOKEN_PROGRAM_ID, | |
nftAddress, | |
mintAuthority.publicKey | |
); | |
const token = new spl.Token( | |
connection, | |
nftAddress, | |
spl.TOKEN_PROGRAM_ID, | |
mintAuthority | |
); | |
const destination = req.body.destination; | |
const destinationPbKey = new web3.PublicKey(destination); | |
const createNftATA = token.createAssociatedTokenAccount(destinationPbKey); | |
const transferNftIx = await spl.Token.createTransferInstruction( | |
spl.TOKEN_PROGRAM_ID, | |
getNftATA, | |
destinationPbKey, | |
await createNftATA, | |
[], | |
1 | |
); | |
const transferNftTx = new web3.Transaction(); | |
transferNftTx.add(transferNftIx); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, it is useful
But I need to transfer pNFT using umi.
Could you please, take the code for me?