Skip to content

Instantly share code, notes, and snippets.

@vitorsouzaalmeida
Created April 8, 2022 01:01
Show Gist options
  • Save vitorsouzaalmeida/c35db2e99314ed8d7ac2a22ee15b1e1e to your computer and use it in GitHub Desktop.
Save vitorsouzaalmeida/c35db2e99314ed8d7ac2a22ee15b1e1e to your computer and use it in GitHub Desktop.
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