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

# Xion Contract Requirements

> Requirements and specifications for Xion smart contracts

1. **Base Contract**: Your contract must extend the [CW721 Metadata Onchain contract](https://github.com/public-awesome/cw-nfts/tree/main/contracts/cw721-metadata-onchain) from Public Awesome.

2. **Minting Function**: The contract must include a minting function that allows Crossmint to mint NFTs on behalf of users.

3. **Minter Ownership**: The [CW721 Metadata Onchain contract](https://github.com/public-awesome/cw-nfts/tree/main/contracts/cw721-metadata-onchain) supports updating minter ownership to allow Crossmint to execute minting messages. This is implemented through the `update_minter_ownership` function which can be called to add or remove minting permissions.

<Note>
  Make sure your contract is properly tested and audited before deployment. While the base CW721-metadata-onchain
  contract is audited, any custom extensions you add should be thoroughly tested.
</Note>

The following example demonstrates how to implement requirements 1 and 2 by extending the CW721 Metadata Onchain contract:

```rust theme={null}

// Extend cw721_metadata_onchain contract
use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response};
use cw721_metadata_onchain::msg::ExecuteMsg;
use cw721_metadata_onchain::{Cw721MetadataContract, error::ContractError};


// Override the mint function
#[entry_point]
pub fn execute(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    msg: ExecuteMsg,
) -> Result<Response, ContractError> {
    // Add your custom code here

    Cw721MetadataContract::default().execute(deps, &env, &info, msg)
}
```

`msg: ExecuteMsg` format will be like:

```json theme={null}
{
    "mint": {
        "token_id": "your-token-id",
        "owner": "recipient-address",
        "token_uri": "ipfs://your-metadata-uri",
        "extension": {
            "name": "NFT Name",
            "description": "NFT Description",
            "image": "ipfs://your-image-uri"
        }
    }
}
```

The base contract already provides:

* On-chain metadata storage
* Standard NFT operations (mint, transfer, approve, etc.)
* Built-in metadata types and validation

## Updating Minter Ownership

To allow Crossmint to mint NFTs on your behalf, you need to update the minter ownership of your contract. This is done using the `update_minter_ownership` function.

### Command

```bash theme={null}
xiond tx wasm execute <your-contract-address> \
  '{"update_minter_ownership":{"action":"add","address":"CROSSMINT_ADDRESS"}}' \
  --from <your-wallet> \
  --chain-id xion
```

### Parameters

Replace the following placeholders:

* `<your-contract-address>` - Your deployed contract address
* `CROSSMINT_ADDRESS` - Crossmint's address (see below)
* `<your-wallet>` - Your wallet name

### Crossmint Addresses

Use the appropriate address based on your environment:

| Environment        | Address                                       |
| ------------------ | --------------------------------------------- |
| Staging Testnet    | `xion1sky4jrvn7s3u9wetshrutkmuuuu6jcwfju6qmt` |
| Production Mainnet | `xion162pp2eunext5skljzsshhzwjpkce9d3eceyr8z` |

You can verify that the ownership request has been executed by quering

```bash theme={null}
xiond query wasm contract-state smart <your-contract-address> '{"get_minter_ownership":{}}'
```

And response should be like

```
{
  "data": {
    "owner": "<CURRENT_OWNER>",
    "pending_owner": "<CROSSMINT_ADDRESS>",
    "pending_expiry": null
  }
}
```

Then, when Crossmint receives a mint request (either by the minting API or a successful checkout), the system will automatically verify `get_minter_ownership` upon your contract, and if the `pending_owner` address, matches the environment `<CROSSMINT_ADDRESS>`, the following message will be executed on your contract

```
{
  update_minter_ownership: "accept_ownership",
}
```

## Registering Your Contract

To register your Xion contract with Crossmint:

1. Deploy your contract to the Xion network
2. Go to the Crossmint Console
3. Navigate to "Token Collections"
4. Click "New Collection"
5. Select "Xion" as the blockchain
6. Enter your contract address
7. Follow the remaining steps in the wizard
