> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpectrum.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate with Xmarket

> Make any contract tradeable on Xpectrum

Xmarket does not care who deployed a contract. If your contract implements the XNS-1 interface, it is tradeable on Xpectrum the moment it is on-chain. There is no allowlist and no registration step.

## The minimum surface

Xmarket calls exactly five functions on a collection contract to settle trades and route royalties. Implement these and your contract is marketplace-compatible:

| Function               | Signature                                      | Returns                                               |
| ---------------------- | ---------------------------------------------- | ----------------------------------------------------- |
| `is_approved_or_owner` | `(token_id: u128, addr: address)`              | `1` if addr is owner, approved, or operator, else `0` |
| `transfer_from`        | `(from: address, to: address, token_id: u128)` | `bool`                                                |
| `owner_of`             | `(token_id: u128)`                             | `address`                                             |
| `creator_of`           | `(token_id: u128)`                             | `address`, the royalty recipient                      |
| `royalty_of`           | `(token_id: u128)`                             | royalty in basis points                               |

<Warning>
  `is_approved_or_owner` takes `token_id` first and `addr` second. Reversing them causes silent auth failures at settlement.
</Warning>

For the full standard (transfers, approvals, events, view returns), see [XNS-1](/standards/xns-1).

## How a trade settles

1. The seller approves Xmarket as an operator on the token (`approve` or `set_operator`)
2. The seller lists via `list_nft(contract, token_id, price)`
3. A buyer calls `buy_nft(listing_id)` with OCT attached
4. Xmarket reads `owner_of`, checks `is_approved_or_owner`, reads `royalty_of` + `creator_of`, then calls `transfer_from` and credits proceeds

Royalties are read from your contract's `royalty_of` at settlement, then **clamped to a 10% ceiling by Xmarket**. A contract reporting 50% still pays out 10%. The cap is enforced by the marketplace, not by trusting the collection.

## Good practices

* Bounds-check `token_id` in every view function and revert on nonexistent tokens. Xmarket and indexers rely on this.
* Emit `Transferred` on every ownership change, including mints (`from = 0` on mint), so indexers can follow ownership without rescanning.
* Keep proceeds pull-based. Octra's AML reverts earlier `transfer()` calls if a later `call()` in the same function fails, so pushing funds during settlement is fragile. Credit a balance and let recipients claim.

## Reference implementations

`Xcollection` and `XpectrumGenesis` both implement XNS-1 in AML and are formally verified. Use them as a reference for the exact event shapes and view return formats. See [Contracts](/contracts/overview).
