A First Look at Dashmate
Published:
A beginner friendly tutorial for running a local version of Dash Platform with Dashmate. Includes creating an identity, data contract, and documents.
Outline
Overview
Dashmate is a software tool designed to simplify the process of setting up and managing Dash masternodes. Key features include:
- Easy setup: It automates much of the complex process of setting up a Dash masternode.
- Management: Dashmate provides a user-friendly interface for monitoring and managing masternodes.
- Updates: It helps users keep their masternodes up-to-date with the latest software versions.
- Configuration: The tool allows for easy configuration of masternode settings.
- Multiple node support: Users can manage multiple masternodes from a single interface.
- Security: Dashmate implements best practices for securing masternodes.
By simplifying these technical aspects, Dashmate makes it more accessible for individuals to participate in the Dash network.
Prerequisites
- Node.js v20+
- Docker (latest)
- Dashmate installed
Install Dashmate
See all available dashmate
commands with dashmate --help
.
Setup and Start Dashmate Local Network
To avoid problems with variable network speeds and other challenges related to interacting with testnet, Dashmate makes it (mostly) easy to create a local development network. The network is only accessible to your computer since the nodes are exclusively running locally on your machine.
Setup Group of Local Nodes
Local networks can be set up with Dashmate via the dashmate setup local
command. This command sets up a full local Dash network environment on your machine for development purposes by creating a group of nodes that simulate a small network running the actual Dash network.
Other setup commands can configure nodes to connect to existing Dash networks including dashmate setup mainnet
or dashmate setup testnet
. The local
preset creates an isolated, self-contained network on your machine whereas mainnet
and testnet
presets connect to public Dash networks. With the local
setup, developers have more control over the network parameters and can easily reset or modify the environment.
The local
setup includes features that are not typically part of mainnet
or testnet
setups:
- Can create multiple nodes as part of a group while other setups typically configure a single node.
- Generates configs, mines some test Dash (tDash), registers masternodes, and populates nodes with data required for local development.
- Allows setting a miner interval between blocks using the
-m
or--miner-interval
flag.
All commands related to interacting or manipulating your group of nodes will start with dashmate group ...
. Every time you reset the network, the entire transaction history of the chain is also dropped.
Start Local Group and Check Network Status
Run the group of nodes with dashmate group start
.
Check the status of your network with dashmate group status
.
You can also check everything by hand by using docker ps
.
- Check to see if everything is in the
running
state. - If something is not running, check the logs via
docker logs
.
Always ensure the health of your local network before you start. Laptops will be more prone to chain halts and network crashes since many include automatic sleep timers that reduce computing resources for power conservation.
Stop or Restart Group
Various commands exist to provide different levels of “resetting” your node group. These range from simply stopping to completely wiping and starting over. Choosing the appropriate command will be based on how much you want to reset including whether you want to preserve configurations. Here’s a high level description of each method, followed by a more detailed explanation.
dashmate group:stop --force
only stops the nodes.dashmate group restart
restarts the nodes without changing data or configuration.dashmate group reset --force
resets the data but keeps configurations.dashmate group reset --hard --force
performs a complete reset, removing both data and configurations.
dashmate group:stop --force
forcefully stops all nodes in the current group. --force
ensures the stop operation is carried out even if services are still running or have any issues.
Use Case: Quickly shut down all nodes in a group regardless of their current state.
dashmate group restart
restarts all nodes in the current group, essentially equivalent to stopping the group and then starting it again.
Use Case: Apply configuration changes or refresh the state of all nodes in the group.
Reset Group
dashmate group reset --force
resets all nodes in the current group, forcefully removing all data associated with them. The --force
flag ensures the reset happens even if services are running. All services are stopped, all data for each node in the group is removed, and configuration files are kept intact.
Use Case: Start fresh with your node data while keeping your existing configuration.
dashmate group reset --hard --force
is the most aggressive reset command. The --hard
flag in addition to --force
means it will stop all services forcefully by removing all data for each node in the group plus removing and resetting all configuration files.
Use Case: You want a completely clean state for your group as if it had never been set up. To use the group, the setup process must be run again.
Setup JavaScript Project
Create a new Node.js project and set type
to module
for ESM imports and exports.
Set scripts
:
Create Wallet
Create a function for generating a new wallet and a function for getting the next unused address.
createWallet
creates a new wallet and console logs your new mnemonic and address.
Create Client File and Set Environment Variables
Add the following to .env
with the mnemonic and wallet address from the previous command.
Create a client.js
file for initializing and exporting a reusable Dash client.
Import Dash
and set the network
, dapiAddress
, and MNEMONIC
options.
This connects to the DAPI endpoint of the local Dash network and syncs up your wallet.
Mint Local tDash with Wallet Command
Lets mint some coins with our new wallet address. To do that, you must stop your network (dashmate group:stop --force
), issue the dashmate wallet mint
command with your address, and start your network again (dashmate group start
):
Output:
Register Identity
Registering an identity creates a unique account in the Dash Platform network. You must register an identity before you can use any Dash Platform features.
Create Data Contract
A Data Contract is a data type definition for your application that is like a schema for a database application that lets you store and query data.
The contractDefinitions
includes an object
type with one property, a message
set to type
string.
Once the schema has been created and we have our data contract, we can being storing our data in the chain. We can write and read data in the designed object format.
Submit and Query Documents
To insert documents in the data contract, we must define it in our Dash.Client
options:
Create a submitDocument.js
file.
To ensure your identity has the necessary credits to create the document, we’ll top up our identity before broadcasting our state change.
Our data is now in Dash Platform’s global state and using GroveDB we can make queries and retrieve our data. Create a getDocument.js
file.
Use the helloWorld.note
query syntax to get all documents.