A First Look at Dash
Published:
Dash is a cryptocurrency launched in 2014 that aims to be a convenient, fast, and private digital cash platform that is suitable for everyday transactions.
Outline
- Dash Platform Overview
- Create Wallet and Identity
- Data Contracts
- Setup Backend Server with Express
- Create Next App
Dash Platform Overview
Dash is a digital cryptocurrency that was launched in 2014. Originally called XCoin (XCO), it was renamed Darkcoin and then finally rebranded as Dash in 2015. “Dash” is a portmanteau of “Digital Cash” and was created as a fork of Bitcoin. Despite its origins, today Dash differs significantly from Bitcoin by aiming to be a convenient, fast, and private digital cash platform that is suitable for everyday transactions. This goal is reflected in its design features which include:
- PrivateSend: This feature ensures user privacy by mixing transactions together, making them untraceable to individual users.
- InstantSend: Dash’s InstantSend feature enables near-instant transaction confirmations that are faster than Bitcoin’s.
- Masternodes: Dash’s network includes masternodes (or full nodes) which power its unique features like InstantSend and PrivateSend, as well as its governance system.
- Decentralized Autonomous Organization: Dash operates as a DAO, meaning it is a transparent, member-controlled organization free from central government influence.
- Block Reward Allocation: Dash’s block reward is split between miners (45%), masternodes (45%), and a development fund (10%), ensuring ongoing platform maintenance and development.
In 2019, an MVP of the Dash Platform (originally codenamed “Evonet”) was launched. The Dash Platform is a technology stack for building decentralized applications (dApps) on the Dash network. It represents a shift away from the original, transaction-focused blockchain systems inspired by Bitcoin by aiming to make Dash more like newer, application-focused blockchains such as Ethereum and Solana.
Key features of the platform include:
- Dash Drive: A decentralized API that lets users store and interact with data on the Dash network, similar to a cloud database service.
- Decentralized API (DAPI): Allows developers secure, decentralized access to full node capabilities without needing to host one.
- Usernames via Dash Platform Name Service (DPNS): Enables the creation of memorable usernames to replace complex cryptographic addresses.
- Platform Chain: A separate chain for storing platform data, secured by the masternodes of the main Dash network.
- Dash Libraries: A collection of integrated open source libraries for developing on the Dash Platform.
The Dash roadmap is always publicly viewable so users and developers can see what is being worked on for the next year or so development. Right now the upcoming network implementations schedule for 2024 and beyond include the following:
- Dash Platform v1.0 (ROLL OUT) begins the roll out of the platform on Mainnet.
- The release will emphasize written documentation, tutorials, and Dash Improvement Proposals (DIPs).
- v1.0
ACTIVATION
will signal the official activation of the protocol and triggers after a specific number of masternode owners upgrade. - The DashPay Launch will complete the v1.0 release and enable creating on-chain usernames for the official DashPay mobile app.
- Dash Platform v2.0 plans to build in support for both of the following:
- Fungible tokens to mint specific tokens.
- Non-fungible tokens for storing NFT data on chain.
- Dash Platform v3.0 will add a Virtual Machine for Smart Contracts to allow on-chain computation.
- Dash Platform v4.0 implements the Inter-Blockchain Communication Protocol (IBC) to enable permissionless, cross-chain applications.
- As of April 2024, this is the last scheduled release currently on the roadmap
Setup and Configure Node Project
We’ll create each script file individually throughout the tutorial but for the sake of simplifying your life while following along with this tutorial, I’d recommend adding all of the Node scripts that will be implemented by the end of the tutorial.
Initialize Dash Client and Query Blocks
Create a scripts
directory for our Node scripts and an api
directory with a file called client.js
for initializing Dash.Client
. The network
will be set to testnet
via the NETWORK
environment variable in .env
.
Import Dash
from dash
, pass the project’s network and wallet configuration through Dash’s Client
constructor, and export client
.
- Because we haven’t created a wallet yet,
mnemonic
is set tonull
to indicate we want a new wallet to be generated. To get a new address for an existing wallet replacenull
with an existing wallet mnemonic. offlineMode
is set totrue
, indicating we don’t want to sync the chain. This can only be used when the mnemonic is set tonull
.
Create a file called getBlockMethods.js
which will be used to query block data.
getBestBlockHash
returns the block hash of the chaintip.getBlockHash
returns the block hash of a given height.- In blockchain terminology, “height” refers to the position of a block in the chain. The first block ever mined (also known as the genesis block) typically has a height of 0.
- Each subsequent block that’s added to the chain increases the height by one so the height of a block also represents the total number of blocks that precede it in the chain.
getBlockByHeight
fetches a specific block by its height.- Unlike
getBlockHash
, it returns a bufferized block instead of the corresponding block hash.
- Unlike
Run the getBlockMethods
script:
You’ll receive the following output:
-
getBlockByHeight()
returned a<Buffer>
object, which is a Node.js type used to efficiently represent a sequence of bytes. Since blockchain data is binary, it’s represented as a buffer when accessed programmatically. -
getBlockHash(1)
returns the hash of the block at height 1 as a hexadecimal string. Block hashes are unique identifiers for blocks and are derived from the block header information, including the previous block’s hash, a timestamp, and a nonce among other data. This particular hash identifies the first block after the genesis block in the Dash blockchain. -
getBestBlockHash()
returns the hash of the latest block in the longest chain, which is considered the current state of the blockchain and is the most recently confirmed block at the time of the query.
Create Wallet and Identity
Create a file called createWallet.js
.
We’ll use three functions to create a wallet:
getWalletAccount()
to get our walletexportWallet()
to export the 12 word mnemonic phrasegetUnusedAddress()
to create a new address
Run the createWallet
script.
The output will include our two environment variables:
Copy these and place them in your .env
. We’ll do the same throughout the rest of this tutorial.
Add Funds to Wallet with Testnet Faucet
Send test funds to the “unused address” from the console output using Dash’s testnet faucet. Wait for the funds to be confirmed before trying to use them, it may take a few minutes. You can check the status of confirmations with the Dash block explorer.
Search for your wallet address (yfvkghuK1fbDc7GBeadfMa47d9WaBpLxij
in my case) to see your balance and list of transactions:
Click on the transaction link (9ca05a57d2f8e55068a5c8be4453d3a84aa852304d1aa3d32d92b9b5afe32261
in my case) to view information on the transaction itself.
You can also click on the plus symbol (+) next to the transaction link for more information related to the transaction confirmation.
Register and Retrieve Identity
Modify the client again and include your wallet’s MNEMONIC
seed phrase saved in .env
.
Create a file called createIdentity.js
.
To create an identity, we’ll run the identities.register()
function.
Run the createIdentity
script.
Output:
Earlier, we saw how to view our transactions on the Dash block explorer. For operations performed on Dash Platform, there is a separate explorer at platform-explorer.com.
- Open the Identities tab to see your ID on the list.
- Alternatively,
createIdentity
appends the ID to the URLhttps://platform-explorer.com/identity/
and outputs the link to your terminal for convenience.
Create a file called retrieveIdentities.js
.
getIdentityIds()
with return your identity ID’s which can be passed to identities.get()
.
Run the retrieveIdentities
script:
When an Identity is created, a special transaction transforms Dash into credits which are used to interact with Dash Platform. 1 DASH is equal to 100,000,000 Duffs (Dash’s version of the Satoshi) and 100 million Duffs is equal to 100 billion credits. Since interacting with Dash Platform applications decreases your credit balance, at a certain point you’ll need to topup the balance by converting some Dash to credits.
Create a file called topupIdentities.js
.
getIdentityIds()
will be used again and the ID’s will be passed to identities.topUp()
.
Run the topupIdentities
script:
Register and Retrieve Name
Create a file called registerName.js
.
Create a LABEL
in .env
with your desired name. I will be using ajcwebdev
.
Run the registerName
script:
Create a file called retrieveName.js
.
Pass your name to platform.names.resolve()
.
Run the retrieveName
script:
Data Contracts
A Data Contract on Dash Platform serves as a blueprint for the structure of data that an application intends to store on the decentralized network. It defines the schema of documents (data records) with JSON Schema.
- Contracts enable the platform to validate data against these schemas to ensure consistency and integrity.
- They are crucial for dApps and provide a structured and predictable way to interact with the Dash blockchain.
- Data Contracts facilitate data storage, retrieval, and manipulation in a trustless environment.
Register, Retrieve, and Update Contract
Create a file called registerContract.js
.
contracts.create()
will take your identity and a spec for the contract. In this case the contract will be a simple string message.
Run the registerContract
script:
Create a file called retrieveContract.js
.
Pass your contract ID to contracts.get()
.
Run the retrieveContract
script.
Create a file called updateContract.js
.
Use your identity ID and contract ID along with setDocumentSchema()
and contracts.update()
.
Run the updateContract
script.
Add an apps
object to the client
options and pass the contract ID to enable <contract name>.<contract document>
syntax while accessing contract documents (for example, tutorialContract.note
).
Submit and Retrieve Documents
Create a file called submitNoteDocument.js
.
Run the submitNoteDocument
script.
Create a file called getDocuments.js
.
Run the getDocuments
script:
Output:
Update and Delete Documents
Create a file called updateNoteDocument.js
.
Run the updateNoteDocument
script:
Now that we can create, read, and update our notes, all we have left to do is delete our notes. Create a file called deleteNoteDocument.js
.
Run the deleteNoteDocument
script:
Setup Backend Server with Express
We’ve now learned how to run individual scripts to perform all the main functionality on the Dash Platform. Like any JavaScript library, we can extend this functionality with a backend and frontend. Let’s create an Express server that will return information on a given identity name.
Create a /name
endpoint that will take an identity name:
Start the server with the following command:
Open localhost:3001/name/ajcwebdev
or send a GET request with curl.
Create Next App
Now that’s add a frontend. We’ll use Next.js to build a React based frontend.
Open page.js
in next/src/app
and include the following code:
Start your server with the following command:
Setup React Project Structure
Now let’s include the logic to fetch our name.
Add Fetch Button to React App
Now lets add a button that when clicked will fetch our name information.
Wow, you made it all the way to the end! Great job!! In future blog posts we’ll expand out our frontend to include more of the functionality included in our Node scripts. We’ll also build out frontends with other popular frameworks.