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