> For the complete documentation index, see [llms.txt](https://dg-market.gitbook.io/dg-live/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dg-market.gitbook.io/dg-live/developer-resources/smart-contract-reference/methods/buy.md).

# Buy

**Description:** This function allows a user to buy an NFT listed for sale in the marketplace by transferring the required amount of tokens to the seller and the royalty receiver, if applicable.

**Method header:**

```solidity
function buy(address _nftAddress, uint256 _tokenId) public nonReentrant
```

**Parameters:**

| Parameter Type | Parameter Name | Parameter Description              |
| -------------- | -------------- | ---------------------------------- |
| address        | \_nftAddress   | The address of the NFT contract.   |
| uint256        | \_tokenId      | The ID of the NFT to be purchased. |
