Run the counter DApp
Now you are ready to run the counter DApp, deploying a new instance of its contract to the Midnight Testnet and submitting transactions to the network.
A command-line wallet
Because this DApp has no web-based user interface and runs outside of your web browser, it cannot access the Midnight Lace wallet that you installed in part 1 of the tutorial. Instead, the DApp initializes a Midnight wallet that shares its core libraries with Lace wallet, but which can be invoked through library calls in command-line applications. (Many programmers refer to the software without a graphical user interface as 'headless', so you may find text elsewhere that refers to this wallet as the 'headless wallet'.)
When you run the DApp, the first thing it will do is instantiate its wallet, either by creating a completely fresh one or by rebuilding the wallet from a previously generated seed. On the first run, you must create a fresh one and transfer some tDUST to it from your Midnight Lace wallet. The instructions below guide you through the process.
Run the counter CLI
-
Be sure the proof server that you installed in part 1 of the tutorial is started.
-
In the
counter/counter-cli
folder, launch the DApp with:yarn testnet-remote
This starts the DApp in a configuration that uses your local proof server, but connects to cloud-deployed instances of a Midnight node and a pub-sub indexer, just as in part 1 of this tutorial.
-
Choose to build a fresh wallet. The DApp will display the wallet's address and a balance of 0 tokens.
The seed for the freshly created wallet will also be printed. Save this information so that you can reuse this wallet on a later run of the counter DApp.
Additionally, your interactions with the DApp, including the wallet address and seed, are stored in a
log
subdirectory ofcounter-cli
. -
Transfer tokens from your Lace wallet to your CLI wallet:
- Copy your new wallet's address and open the Midnight Lace wallet in your web browser by clicking its icon on the Chrome toolbar.
- Select Send and paste the CLI wallet address into the 'recipient's address' field.
- Enter an amount to transfer. The value of 3 tDUST will be more than enough.
- Review and click Send.
- Enter your wallet password and click Confirm.
-
Return to the counter DApp's window and wait for the tokens to be received. The DApp detects the funds that were transferred to your CLI wallet and reports your new wallet balance, followed by a new prompt.
-
The next prompt asks whether you want to deploy a new counter contract on Testnet or join an existing one. Choose to deploy your newly-compiled contract.
The DApp prints the deployed contract's address. Save this information, so that you can run the DApp again later and rejoin the contract.
-
Interact with the contract. You are prompted with three options: increment, display, or exit.
-
First, display the current value by selecting option 2. This retrieves the current state of the contract from the blockchain ledger. It should report a value of
0
. -
Next, increment the counter by selecting option 1. This submits a new transaction and awaits confirmation.
If you watch your proof server's output in another window at the same time, you will see that it generates a proof for the transaction, which is submitted to Testnet.
Generating the proof, submitting it to Testnet, and waiting for the transaction to be processed by the network takes some time. Eventually, the DApp should report the successful completion of the transaction, with output like:
Transaction <transaction hash> added in block <block number>
-
Now verify that the counter's value has been incremented by selecting option 2. It should report a new value of
1
. -
Repeat as you like, and then select (3) to exit. There is a problem in one of the underlying libraries that can cause error messages upon exit. You may safely ignore these.
-
-
Try running the DApp again, rebuilding the wallet from the saved seed, and rejoining the existing contract. Have fun playing and experimenting.
🎉 Congratulations, you are now building and deploying DApps on the Midnight Testnet.