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 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.
import lib.ft4.assets.{ asset, Unsafe, balance };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
chr node startIn a second terminal, run your CLI commands. Begin by querying the accounts to confirm that the dapp account exists.
chr query get_all_accountsNext, register two users: Alice and Bob.
chr keygen --file .chromia/alice.keypairchr keygen --file .chromia/bob.keypairchr tx --await create_user "<alice pubkey>" --secret .chromia/alice.keypairchr tx --await create_user "<bob pubkey>" --secret .chromia/bob.keypairThe 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.
chr query get_all_balancesThe output resembles the following. It lists both new accounts, each with the 1000 CRD balance minted by create_user.
[ [[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 1000L]], [[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 1000L]]]Buy a mystery card
With the balances confirmed, have Alice purchase a mystery card.
chr tx --await buy_mystery_card --ft-auth --ft-account-id=<first id from get_all_balances query> --secret .chromia/alice.keypairTo confirm the transaction went through, inspect the current nft_cards and look at the balances again.
chr query get_all_nftsYou should see output like this, describing a card NFT and its properties.
[["health": 10, "nft_id": 22, "owner_id": x"<owner id>", "strength": 8]]Run this query to check the balances
chr query get_all_balancesand 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 |
[ [[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.
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.
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.
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.
chr query get_all_balancesThe 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.
[ [[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!