# Test using Chromia CLI · Decentralized marketplace with FT4 · Learn Chromia

> Every piece of the marketplace is now in place, and you can try it out with Chromia CLI. This command-line tool gives you a set of commands for interacting…

Source: https://chromia.com/learn/marketplace-course/module-assets/test-cli/

Decentralized marketplace with FT4Lesson 15 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/)

15 / 15Module 3: Create the marketplaceAdvanced

# Test using Chromia CLI

Every piece of the marketplace is now in place, and you can try it out with Chromia CLI. This command-line tool gives you a set of commands for interacting with the Chromia blockchain. The [Chromia CLI documentation](https://docs.chromia.com/build/cli/introduction/) covers it in more detail.

## Queries for verification

Add two helper queries to the app first. You will use them to retrieve accounts and their balances so you can check the data at each step.

src/rell\_marketplace/module.rell

```nolines
import lib.ft4.assets.{ asset, Unsafe, balance };
```

src/rell\_marketplace/queries.rell

```
query get_all_accounts()
{
    return account @* {} ($.to_struct());
}

query get_all_balances()
{
    return balance @* {} ($.account.to_struct(), $.to_struct());
}
```

## Begin testing

Start the blockchain node with the following command:

### Create accounts

shell

```nolines
chr node start
```

In a second terminal, run your CLI commands. Begin by querying the accounts to confirm that the dapp account exists.

shell

```nolines
chr query get_all_accounts
```

---

Next, register two users: Alice and Bob.

shell

```
chr keygen --file .chromia/alice.keypair
chr keygen --file .chromia/bob.keypair

chr tx --await create_user "<alice pubkey>" --secret .chromia/alice.keypair
chr tx --await create_user "<bob pubkey>" --secret .chromia/bob.keypair
```

The `chr tx` command submits a transaction that invokes an operation on the blockchain.

To check that minting behaves as expected, query the balances of every account. Alice and Bob should each hold 1000 CRDs.

shell

```nolines
chr query get_all_balances
```

The output resembles the following. It lists both new accounts, each with the 1000 CRD balance minted by `create_user`.

shell

```
[
    [[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 1000L]], 
    [[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 1000L]]
]
```

### Buy a mystery card

With the balances confirmed, have Alice purchase a mystery card.

shell

```nolines
chr tx --await buy_mystery_card --ft-auth --ft-account-id=<first id from get_all_balances query> --secret .chromia/alice.keypair
```

To confirm the transaction went through, inspect the current `nft_cards` and look at the balances again.

shell

```nolines
chr query get_all_nfts
```

You should see output like this, describing a card NFT and its properties.

shell

```nolines
[["health": 10, "nft_id": 22, "owner_id": x"<owner id>", "strength": 8]]
```

Run this query to check the balances

shell

```nolines
chr query get_all_balances
```

and you get the following figures for Alice, Bob, and the Economy Account.

| Participant | Action | Amount | Balance |
| --- | --- | --- | --- |
| Alice | Purchased a mystery card | -100 CRD | 900 CRD |
| Bob | Nothing |  | 1000 CRD |
| Economy Account | Payment from Alice | +100 CRD | 100 CRD |

shell

```
[
    [[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 900L]],  // Alice
    [[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 1000L]],  // Bob
    [[x"522546AF72636ABA2AFE34E1BF2D7BF2B9C0A483C20F87E145BE32992339962C"], [2, 1, 100L]] // Economy account
]
```

### List cards on the marketplace

Alice now puts her card up for sale at 25 CRD. Take the `nft_id` from the earlier `get_all_nfts` output, and Alice's FT4 account id from the `get_all_balances` output.

shell

```nolines
chr tx --await list_nft "<nft_id from query>" "25L" --secret .chromia/alice.keypair --ft-auth --ft-account-id=<FT4 account from query>
```

Then call `get_cards`, supplying arguments that filter and sort the results.

shell

```nolines
chr query get_cards "amount=10" "card_sorting=PRICE_HIGH"
```

The query should return exactly one entry: the card Alice listed.

### Buy a card from the marketplace

Bob purchases Alice's card through the `buy_card` operation.

shell

```nolines
chr tx --await buy_nft "<nft id>" --secret .chromia/bob.keypair --ft-auth --ft-account-id=<Bobs FT4 account id from get_all_balances>
```

Afterwards, run the query.

shell

```nolines
chr query get_all_balances
```

The resulting balances should match this table

| Participant | Action | Balance |
| --- | --- | --- |
| Alice | Bought a mystery card for 100 CRD Got 25 CRD from Bob | 925 CRD |
| Bob | Paid 25 CRD for Alice's card | 975 CRD |
| Economy Account | Collected a 100 CRD fee from Alice | 100 CRD |

and the query output confirms them.

shell

```
[
    [[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 925L]],  // Alice
    [[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 975L]],  // Bob
    [[x"522546AF72636ABA2AFE34E1BF2D7BF2B9C0A483C20F87E145BE32992339962C"], [2, 1, 100L]]     // Economy account
]
```

That completes the Chromia CLI tests and the course as a whole. Happy coding!

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

[← Previous**Test our marketplace**](https://chromia.com/learn/marketplace-course/module-assets/test-marketplace/)[Course done →**Start building**](https://chromia.com/developers/#start)

On this page

* [Queries for verification](#queries-for-verification)
* [Begin testing](#begin-testing)
