# Sell a NFT

The following sample will show you how to sell a NFT using the Hedera Hashgraph and Filecoin to store the media. We will first generate a request for the end user. Once validated, you will get notified for the NFT's selling success.

{% hint style="info" %}
In order to guarantee the process, the NFT will be transferred on an escrow account. User could withdraw anytime and get NFT back.
{% endhint %}

## Prerequisites: <a href="#pre-requisites" id="pre-requisites"></a>

{% content-ref url="getting-started" %}
[getting-started](https://xact.gitbook.io/xact/sdk/javascript/getting-started)
{% endcontent-ref %}

## Step 1: Import the following modules <a href="#step-1-import-de-following-modules" id="step-1-import-de-following-modules"></a>

Let's continue building on the *index.js* from the previous example ([Environment Set-up](https://xact.gitbook.io/xact/sdk/getting-started#step-1-set-up-your-node-js-environment)) and add the following modules:

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

## Step 2: Initializing

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

```typescript
/* Update the fields with your informations */
const fromAccountId = '' /* Account Id of the Seller */
const hbarAmount = 10 /* Unit Price per NFT in Hbar */
const nftIds = ['1@0.0.123456'] /* Array of nftIds to sell */
/* You can specify a quantity if you prefer to let us choose randomly for you */
/* But nftIds field cannot be set with quantity */
const tokenId = ''; /* token Id of the NFT */
const isCollection = ''; /* Sell the nftIds under one QR Code */
/* Optional NOT YET AVAILABLE - The NFT could only be sell to accountId present on that list */
const accountIds = ['', ''];
/* Optional - Add a middle men in order to collect fees */
const middleMen = {
    middleManAccountId,
    middleManTypeOfFees: MiddleManFeesType.HBAR,
    middleManFees: 10
};

/* If you're selling by nftIds replace quantity by ndtIds */
await client.sellNFT({fromAccountId, nftIds, hbarAmount, tokenId, accountIds, isCollection, middleMen});
```

## Step 3: Listen for the NFT's sell <a href="#step-3-listen-for-the-token-transfer" id="step-3-listen-for-the-token-transfer"></a>

Finally get notified when your NFT has been successfully set in sale !

```javascript
/* Subscribe to new sale NFT Validation */
client.sellNFTValidation().subscribe(nft => {
    console.log('NFT successfully set in sale', nft);
});
```

## Code Check ✅ <a href="#code-check" id="code-check"></a>

Your *index.js* file should look like this:

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

async function sellNFT() {

    //Grab your api key from your .env file
    const apiKey = process.env.API_KEY;


    // If we weren't able to grab it, we should throw a new error
    if (apiKey == null) {
        throw new Error("Environment variables API_KEY must be present");
    }
    /* Create a new instance of Client */
    const client = new Client({apiKey});
    
    /* Init the connexion */
    await client.initConnexion();
    
    /* Update the fields with your informations */
    const fromAccountId = '' /* Account Id of the Seller */
    const hbarAmount = 10 /* Unit Price per NFT in Hbar */
    const nftIds = ['1@0.0.123456'] /* Array of nftIds to sell */
    const tokenId = ''; /* token Id of the NFT */
    
    /* If you're selling by nftIds replace quantity by ndtIds */
    await client.sellNFT({fromAccountId, hbarAmount, tokenId, nftIds});
    
    /* Subscribe to new sale NFT Validation */
    client.sellNFTValidation().subscribe(nft => {
        console.log('NFT successfully set in sale', nft);
    });
}

sellNFT();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xact.gitbook.io/xact/sdk/javascript/sell-a-nft.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
