Skip to content

Instantly share code, notes, and snippets.

@vit0rr
Created April 8, 2022 01:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Transfer a NFT with Solana Web3.js
// 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