Skip to content

Instantly share code, notes, and snippets.

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

Thanks, it is useful
But I need to transfer pNFT using umi.
Could you please, take the code for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment