> For the complete documentation index, see [llms.txt](https://docs.artinals.com/artinals-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.artinals.com/artinals-protocol/market-module/smart-contract-overview.md).

# Smart Contract Overview

Module Name:\
`module artinals_markets::MARKET;`

This module is responsible for enabling a **decentralized NFT marketplace** on the Sui blockchain. It provides functionalities for **listing, buying, selling, and batch transactions of NFTs** while ensuring security, transparency, and efficiency.

### **Dependencies**

The `MARKET` module relies on several core Sui libraries and external modules:

* **Sui Standard Libraries**
  * `sui::coin` – Handles fungible tokens used for transactions.
  * `sui::table` – Manages order book and trade ledger.
  * `sui::event` – Emits blockchain events for tracking trades.
  * `sui::clock` – Provides blockchain timestamps.
  * `sui::dynamic_object_field` – Stores NFT metadata efficiently.
* **ART20 Integration**
  * Uses `artinals::ART20::NFT`, `UserBalance`, and `CollectionCap` for NFT interactions.

### **Constants & Error Codes**

The contract defines several **error codes** for validating transactions and ensuring security.

#### **Error Codes**

| Error Code                      | Meaning                                                            |
| ------------------------------- | ------------------------------------------------------------------ |
| `ENotOfferOwner = 2`            | The sender is not the owner of the offer.                          |
| `E_NOT_CREATOR = 8`             | The sender is not the creator of the collection.                   |
| `EInsufficientBalance = 3`      | The user does not have enough balance to complete the transaction. |
| `EOfferNotOpen = 4`             | The offer is either closed or already completed.                   |
| `ECollectionMismatch = 6`       | The NFT collection does not match the expected collection.         |
| `EInvalidCurrency = 7`          | The provided currency is not valid for this offer.                 |
| `E_OVERFLOW = 1`                | Integer overflow detected in arithmetic operations.                |
| `E_INVALID_BATCH_SIZE = 2`      | The batch size exceeds the allowed limit.                          |
| `E_ADDRESS_DENIED = 3`          | The sender’s address is denied from performing this action.        |
| `E_INVALID_AMOUNT = 4`          | The amount provided is invalid.                                    |
| `E_BALANCE_CREATION_FAILED = 5` | The user balance creation process failed.                          |
| `EOFFER_NOT_FOUND = 2`          | The offer does not exist or was removed.                           |
| `EOFFER_ALREADY_FILLED = 3`     | The offer has already been fulfilled.                              |
| `ELedgerExists = 30`            | The ledger for this collection already exists.                     |
| `ELedgerNotFound = 31`          | No matching ledger found for the specified collection.             |

**Offer Status Constants**

| Constant         | Value                  | Description                                                   |
| ---------------- | ---------------------- | ------------------------------------------------------------- |
| `MAX_U64`        | `18446744073709551615` | Maximum value of a `u64` integer.                             |
| `MAX_BATCH_SIZE` | `200`                  | Maximum number of NFTs or offers processed in a single batch. |
