Midnight test environment
In the preceding parts of the tutorial, you ran DApps that were already complete and tested. In this part, however, you have been writing portions of the DApp yourself, and you probably want to try out your work before deploying the DApp to the Midnight network.
The Midnight team has already created a compose file for Docker that runs a proof server, Midnight node, and pub-sub indexer locally, configured so that they run disconnected from the Midnight network. In effect, the Midnight node acts as if it is its own isolated Midnight network. This allows you to test contracts and DApps entirely on your own system, before deploying them to the real network.
If you want to review the details, you can see the Docker compose definition in this file:
bboard-tutorial/bboard-cli/standalone.yml
The important part is the environment variable RUN_DEV_NET
in node
definition. That tells the node to run its own self-contained devnet,
without connecting to any other nodes.
Before running this test configuration, you must stop any existing
proof server, indexer, and node. Then, if you want, you can start and
stop the test configuration to verify that it works. Follow the
instructions for
running your own Midnight node,
but substitute standalone.yml
for local-node.yml
in the
instructions.
Do not leave the test configuration running in Docker for the next
steps, though, because you will test the bulletin board DApp by
launching it with a command that starts and stops the whole
standalone.yml
configuration automatically as part of running the
DApp.
Run the DApp in standalone mode
In the bboard-tutorial/bboard-cli
directory, launch the DApp with:
yarn standalone
After verifying that the latest images of the proof server, indexer,
and Midnight node are pulled from the Midnight image server, the DApp
will launch the Docker configuration in standalone.yml
and wait
for it to be ready.
Then, the DApp will start in standalone mode, not prompting to create or restore a wallet, but instead, creating a new wallet with tDUST that is valid only for such offline testing.
When the wallet is ready, DApp asks whether it should join an existing contract or deploy a new one. There is no existing contract to join, so deploy one. Then, explore the possibilities with the DApp, posting a message and examining the public and private state.
When you exit the DApp, the Docker containers should stop be and be cleaned up automatically.
Run the DApp connected to the devnet
When you are ready to try out your DApp on the Midnight devnet, be sure you have not left it running and that your standalone Docker configuration has exited. Then, start your proof server again. When it is ready, start the DApp with this command:
yarn devnet-remote
This time, you will need real tDUST, so either create a new wallet and transfer some tDUST to it from your Midnight Lace wallet, or look back at the logs from your experiments with the counter DApp in part 2 to find the seed for your headless wallet:
examples/counter/counter-cli/logs/devnet
Once the DApp has found some tDUST in your wallet, it will proceed and allow you to deploy your bulletin board to the devnet.
Summary
Have fun playing with the bulletin board DApp. If you are ambitious,
you could create a separate DApp to watch a bulletin board, showing
the messages that are posted and saying when they are taken down. The
code in the displayLedgerState
function in bboard-cli/src/index.ts
will help you get started. You could also share the address of your
bulletin board contract with a friend and see each other's posted
messages.
Congratulations! You have created a working DApp around a non-trivial Midnight contract, with real rules that are enforced automatically. You have written parts of the DApp yourself, and you have learned to test it offline.
At this point, with the help of the reference documentation, you know enough to begin creating your own command-line contracts and DApps. Later parts of this developer tutorial will show you how to add a web UI for your DApps and connect them to the Midnight Lace wallet.