# buyNFT

## Description

The `buyNFT` function facilitates the purchase of a non-fungible token (NFT) on a blockchain-based marketplace.&#x20;

The function requires the blockchain name, the private key of the user's wallet, the ID of the token, the payment amount in cryptocurrency, and the address of the NFT contract.

## Parameters

| Parameter    | Type   | Description                                                                                      |
| ------------ | ------ | ------------------------------------------------------------------------------------------------ |
| `blockchain` | string | The name of the blockchain on which the NFT is being sold (e.g., Ethereum, Binance Smart Chain). |
| `privateKey` | string | The private key of the user's wallet.                                                            |
| `tokenId`    | string | The ID of the token being purchased.                                                             |
| `payment`    | string | The amount of cryptocurrency being sent as payment.                                              |
| `nftAddress` | string | The address of the NFT contract.                                                                 |

## Response

| Parameter | Type   | Description                                                                                      |
| --------- | ------ | ------------------------------------------------------------------------------------------------ |
| `code`    | number | A code indicating whether the transaction was successful (1) or unsuccessful (0).                |
| `receipt` | string | The transaction hash of the purchase, returned if the transaction was successful.                |
| `error`   | string | An error message, returned if the transaction was unsuccessful. The message describes the error. |

## Example Request and Response

### Prerequisites

Before making requests with Volary SDK, you must have it installed.

You can install Volary SDK using either **`npm`** or **`yarn`**. Use the following commands to install Volary SDK:

```jsx
npm install @nest25/evm-chains-lib
OR
yarn add @nest25/evm-chains-lib
```

### Request

Here is an example of how to make a `buyNFT` request using the Volary SDK:

```jsx
const {NftMarketPlace} = require('@nest25/evm-chains-lib')
// create instance of SOULBOUND
const nftMarketPlace = new NftMarketPlace();
const privateKey = "your private key here"
// nft contract address
let nftContract = '0xaa223c2379daf21526925a07fe466fad7269103a';

const main = async () => {
    // buy nft with klay
    const contract = await nftMarketPlace.buyNFT(
        'klay',
        privateKey,
        '1',
        '10',
        nftContract
    );
    // print result
    console.log(contract);
}
main()
```

### Response

```jsx
{
  receipt: {
    type: 2,
    chainId: 1001,
    nonce: 247,
    maxPriorityFeePerGas: BigNumber { _hex: '0x3b9aca00', _isBigNumber: true },
    maxFeePerGas: BigNumber { _hex: '0x0bdfd63e00', _isBigNumber: true },
    gasPrice: null,
    gasLimit: BigNumber { _hex: '0x5208', _isBigNumber: true },
    to: '0x3D5Cc05B5419CcD3c1bD510ab026C76F42D20871',
    value: BigNumber { _hex: '0x8ac7230489e80000', _isBigNumber: true },
    data: '0x',
    accessList: [],
    hash: '0xad169c8ebe54a152ae5c50b578b88ef3bd765d62a3161e594b0743636af338b4',
    v: 0,
    r: '0xb8b9e3326cb0df557cf6f24d8173edbf4fd4df535047ace869e22051bffedd0f',
    s: '0x194c5f94dd1cf2644f369b78f2498549fb026d1721692c7b2d340a4836e904be',
    from: '0xE668C72D4C67236A712Ce69A91C74358586f31ed',
    wait: [Function (anonymous)]
  }
}
```

## Use Cases

* **Crypto Wallets:** The function can be used by crypto wallets to allow users to purchase NFTs on a blockchain-based marketplace.
* **NFT Marketplaces:** The function can be used by NFT marketplaces to facilitate the purchase of NFTs using cryptocurrency.
* **Cryptocurrency Exchanges:** The function can be used by cryptocurrency exchanges to enable users to buy and sell NFTs using cryptocurrency.


---

# 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://docs.volary.io/sdks-guide/blockchain-sdks/evm-chains-sdk/nftmarketplace/buynft.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.
