When initializing a NFT's buy, a request will be sent to the end user
/* Update the fields with your informations */constfromAccountId=''; /* account Id of the buyer *//* Account ID of the Seller */constsellerAccountId='';constnftIds= ['1@0.0.123456'] /* ID of the NFTs you want to buy */consttokenId=''/* tokenId of the NFT */awaitclient.buyNFT(tokenId, {fromAccountId,sellerAccountId,nftIds});
Step 3: Listen for the NFT's buy
Finally get notified when your NFT has been successfully bought !
/* Subscribe to new NFT bought */client.buyNFTValidation().subscribe(nft => {console.log('NFT successfully bought', nft);});
Code Check ✅
Your index.js file should look like this:
const { Client,CategoryNFT } =require("@xact-wallet-sdk/client");require("dotenv").config();asyncfunctionbuyNFT() {//Grab your api key from your .env fileconstapiKey=process.env.API_KEY;// If we weren't able to grab it, we should throw a new errorif (apiKey ==null) {thrownewError("Environment variables API_KEY must be present"); }/* Create a new instance of Client */constclient=newClient({apiKey});/* Init the connexion */awaitclient.initConnexion();/* Update the fields with your informations */constfromAccountId=''; /* account Id of the buyer *//* Account ID of the Seller */constsellerAccountId='';consttokenId=''/* tokenId of the NFT */constnftIds= ['1@0.0.123456'] /* ID of the NFTs you want to buy */awaitclient.buyNFT(tokenId, {fromAccountId,sellerAccountId,nftIds});/* Listen for Creation's success */client.buyNFTValidation().subscribe(nft => {console.log('NFT successfully bought', nft); });}buyNFT();