Buy a NFT

The following sample will show you how to buy a NFT. We will first generate a request for the end user. Once validated, you will get notified.

Prerequisites:

Getting started

Step 1: Import the following modules

Let's continue building on the index.js from the previous example (Environment Set-up) and add the following modules:

const { Client, CategoryNFT } = require("@xact-wallet-sdk/client");
require("dotenv").config();

Step 2: Initializing Buy NFT

When initializing a NFT's buy, a request will be sent to the end user

/* Update the fields with your informations */
const fromAccountId = ''; /* account Id of the buyer */
/* Account ID of the Seller */
const sellerAccountId = '';
const nftIds = ['1@0.0.123456'] /* ID of the NFTs you want to buy */
const tokenId = '' /* tokenId of the NFT */

await client.buyNFT(tokenId, {fromAccountId,sellerAccountId,nftIds});

Step 3: Listen for the NFT's buy

Finally get notified when your NFT has been successfully bought !

Code Check ✅

Your index.js file should look like this:

Last updated