Dash Core

Dash Core Developer Documentation

Welcome to the Dash Core developer documentation. You'll find guides and documentation to help you start working with Dash Core as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Guides

Simple Spending

Dash Core provides several RPCs which handle all the details of spending, including creating a change outputchange output - An output in a transaction which returns duffs to the spender, thus preventing too much of the input value from going to transaction fees. and paying an appropriate transaction feetransaction fee - The amount remaining when the value of all outputs in a transaction are subtracted from all inputs in a transaction; the fee is paid to the miner who includes that transaction in a block.. Even advanced users should use these RPCs whenever possible to decrease the chance that duffsduffs - Denominations of Dash value, usually measured in fractions of a dash but sometimes measured in multiples of a duff. One dash equals 100,000,000 duffs. will be lost by mistake.

1. Get new address

Get a new Dash addressaddress - A 20-byte hash formatted using base58check to produce either a P2PKH or P2SH Dash address. Currently the most common way users exchange payment information. and save it in the shell variable $NEW_ADDRESS.

> dash-cli -regtest getnewaddress
yLp6ZJueuigiF4s9E1Pv8tEunDPEsjyQfd

> NEW_ADDRESS=yLp6ZJueuigiF4s9E1Pv8tEunDPEsjyQfd

2. Send to address

Send 10 dash to the address using the sendtoaddress RPC. The returned hex string is the transaction identifier (TXIDTXID - An identifier used to uniquely identify a particular transaction; specifically, the sha256d hash of the transaction.).

The sendtoaddress RPC automatically selects an unspent transaction outputunspent transaction output - An Unspent Transaction Output (UTXO) that can be spent as an input in a new transaction. (UTXO) from which to spend the duffs. In this case, it withdrew the duffs from our only available UTXO, the coinbase transactioncoinbase transaction - The first transaction in a block. Always created by a miner, it includes a single coinbase. for blockblock - One or more transactions prefaced by a block header and protected by proof of work. Blocks are the data stored on the block chain. #1 which matured with the creation of block #101. To spend a specific UTXO, you could use the sendfrom RPC instead.

> dash-cli -regtest sendtoaddress $NEW_ADDRESS 10.00
c7e5ae1240fdd83bb94c94a93816ed2ab7bcb56ec3ff8a9725c5c1e0482684ea

3. List unspent outputs

3a. Confirmed outputs only

Use the listunspent RPC to display the UTXOs belonging to this walletwallet - Software that stores private keys and monitors the block chain (sometimes as a client of a server that does the processing) to allow users to spend and receive duffs.. The list is empty because it defaults to only showing confirmed UTXOs and we just spent our only confirmed UTXO.

> dash-cli -regtest listunspent
[
]

3b. All outputs

Re-running the listunspent RPC with the argument "0" to also display each unconfirmed transactionunconfirmed transaction - A score indicating the number of blocks on the best block chain that would need to be modified to remove or modify a particular transaction. A confirmed transaction has a confirmation score of one or higher. shows that we have two UTXOs, both with the same TXIDTXID - An identifier used to uniquely identify a particular transaction; specifically, the sha256d hash of the transaction.. The first UTXO shown is a change output that sendtoaddress created using a new address from the key pool. The second UTXO shown is the spend to the address we provided. If we had spent those duffs to someone else, that second transaction would not be displayed in our list of UTXOs.

> dash-cli -regtest listunspent 0
[  
   {  
      "txid":"c7e5ae1240fdd83bb94c94a93816ed2ab7bcb56ec3ff8a9725c5c1e0482684ea",
      "vout":0,
      "address":"yLp6ZJueuigiF4s9E1Pv8tEunDPEsjyQfd",
      "account":"",
      "scriptPubKey":"76a914056b1fe57914236149feb21dcbc6b86f4bdd9f4988ac",
      "amount":10.00000000,
      "confirmations":0,
      "ps_rounds":-2,
      "spendable":true,
      "solvable":true
   },
   {  
      "txid":"c7e5ae1240fdd83bb94c94a93816ed2ab7bcb56ec3ff8a9725c5c1e0482684ea",
      "vout":1,
      "address":"yeP6Tw2uW4nWAFWRytw8TyshErTq59dUkN",
      "scriptPubKey":"76a914c622e98a6ccf34d02620612f58f20a50061cf4b188ac",
      "amount":490.00000000,
      "confirmations":0,
      "ps_rounds":-2,
      "spendable":true,
      "solvable":true
   }
]

4. Mine block

Create a new block to confirm the transaction above (takes less than a second) and clear the shell variable.

> dash-cli -regtest generate 1

> unset NEW_ADDRESS

Simple Spending Script

Shell script to run the previous example (available here):

#!/bin/bash

# Set RPCUSER and RPCPWD to the username and password configure in dash.conf
RPCUSER="user"
RPCPWD="pass"
REGTEST_CMD="dash-cli -regtest -rpcuser=$RPCUSER -rpcpassword=$RPCPWD"

# SIMPLE SPENDING EXAMPLE
# -----------------------

BLOCKTOGEN=101
printf "\nGenerating %s block(s)...\n" $BLOCKTOGEN
COMMAND="$REGTEST_CMD generate $BLOCKTOGEN"
echo $COMMAND
GENERATED=$($COMMAND)
echo "Generated $BLOCKTOGEN block(s)"

printf "\nChecking balance...\n"
COMMAND="$REGTEST_CMD getbalance"
echo $COMMAND
BALANCE=$($COMMAND)
echo "Balance is: " $BALANCE

printf "\nGetting new address...\n"
COMMAND="$REGTEST_CMD getnewaddress"
echo $COMMAND
NEW_ADDRESS=$($COMMAND)
echo "New address is: " $NEW_ADDRESS

printf "\nSending to address...\n"
COMMAND="$REGTEST_CMD sendtoaddress $NEW_ADDRESS 10.00"
echo $COMMAND
TXID=$($COMMAND)
echo "Transaction ID (TXID) is: " $TXID

printf "\nList unspent...\n"
COMMAND="$REGTEST_CMD listunspent"
echo $COMMAND
UNSPENT=$($COMMAND)
echo "Unspent (excluding unconfirmed): " $UNSPENT

printf "\nList unspent (unconfirmed)...\n"
COMMAND="$REGTEST_CMD listunspent 0"
echo $COMMAND
UNSPENT=$($COMMAND)
echo "Unspent (including unconfirmed): " $UNSPENT


BLOCKTOGEN=1
printf "\nGenerating %s block(s) to confirm...\n" $BLOCKTOGEN
COMMAND="$REGTEST_CMD generate $BLOCKTOGEN"
echo $COMMAND
GENERATED=$($COMMAND)
echo "Generated $BLOCKTOGEN block(s)"

printf "\nList unspent...\n"
COMMAND="$REGTEST_CMD listunspent"
echo $COMMAND
UNSPENT=$($COMMAND)
echo "Unspent (excluding unconfirmed): " $UNSPENT

unset REGTEST_CMD
unset BLOCKTOGEN
unset COMMAND
unset GENERATED
unset BALANCE
unset NEW_ADDRESS
unset TXID
unset UNSPENT

Updated about a year ago



Simple Spending


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.