# Mint NFTs · Decentralized marketplace with FT4 · Learn Chromia

> Now that the NFT model exists, you can move on to minting new NFTs.

Source: https://chromia.com/learn/marketplace-course/module-nft/mint-nfts/

Decentralized marketplace with FT4Lesson 8 of 15

1. [01Decentralized marketplace with FT4](https://chromia.com/learn/marketplace-course/introduction/)
2. [02Set up your project](https://chromia.com/learn/marketplace-course/setup/)

Module 1: Registering accounts and assets

1. [03Overview](https://chromia.com/learn/marketplace-course/module-ft4/)
2. [04Register payment token](https://chromia.com/learn/marketplace-course/module-ft4/register-token/)
3. [05Create user accounts](https://chromia.com/learn/marketplace-course/module-ft4/register-account/)

Module 2: Model NFTs in Rell

1. [06Overview](https://chromia.com/learn/marketplace-course/module-nft/)
2. [07Define the NFT model](https://chromia.com/learn/marketplace-course/module-nft/nft/)
3. [08Mint NFTs](https://chromia.com/learn/marketplace-course/module-nft/mint-nfts/)
4. [09Make card attributes random](https://chromia.com/learn/marketplace-course/module-nft/randomness/)

Module 3: Create the marketplace

1. [10Overview](https://chromia.com/learn/marketplace-course/module-assets/)
2. [11Charge a fee for mystery card purchases](https://chromia.com/learn/marketplace-course/module-assets/buy-mystery-card/)
3. [12Put a card up for sale on the marketplace](https://chromia.com/learn/marketplace-course/module-assets/list-card/)
4. [13Buy a card on the marketplace](https://chromia.com/learn/marketplace-course/module-assets/buy-listed-card/)
5. [14Test our marketplace](https://chromia.com/learn/marketplace-course/module-assets/test-marketplace/)
6. [15Test using Chromia CLI](https://chromia.com/learn/marketplace-course/module-assets/test-cli/)

[Learn](https://chromia.com/learn/)[Decentralized marketplace with FT4](https://chromia.com/learn/marketplace-course/)

08 / 15Module 2: Model NFTs in RellAdvanced

# Mint NFTs

Now that the NFT model exists, you can move on to minting new NFTs.

## Minting

The marketplace will expose operations that let users buy random cards. Each purchase mints a new card whose attributes come from the game rules combined with a random element. The first step is a function that mints a card.

To begin, the function creates an `nft_card` with fixed properties. Later on, these values will be calculated instead. For now, the goal is only to get the NFT created. Add this function:

src/rell\_marketplace/nft.rell

```
function mint_card(account) {
    val nft = create nft(account);
    val health = 10;
    val strength = 8;

    create nft_card(.nft = nft, .strength = strength, .health = health);
}
```

The function first creates an `nft` instance registered to an account.

It then declares the card attributes and creates the game-specific `nft_card`, passing in the fixed attribute values.

With minting in place, you can start on the marketplace. For authentication to work in the dapp, you must register an `auth_handler`. An auth handler is a function that defines the rules every call to the `auth.authenticate` function must follow. Add this handler:

src/rell\_marketplace/module.rell

```
import lib.ft4.auth;

@extend(auth.auth_handler)
function () = auth.add_auth_handler(
  flags = ["T"]
);
```

The handler requires the `T` flag for all operations in the marketplace module. This is the same flag you used when registering the account. If you want a handler to apply only to one specific operation, you can give it a `scope`. Here, the handler stays global instead, so every operation that uses FT4 authentication falls back to it.

Users first need a way to buy a new card. Create a new file, `src/rell_marketplace/marketplace.rell`, and add an operation for it:

src/rell\_marketplace/marketplace.rell

```
operation buy_mystery_card() {
    val account = auth.authenticate();
    mint_card(account);
}
```

The operation calls the FT4 function `auth.authenticate()` to check that the user is allowed to perform it. When authentication succeeds, it retrieves the account and uses it to mint a new card.

The next step adds randomness to each generated card so that cards differ from one another.

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Define the NFT model**](https://chromia.com/learn/marketplace-course/module-nft/nft/)[Next →**Make card attributes random**](https://chromia.com/learn/marketplace-course/module-nft/randomness/)
