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 Raw Transaction

The raw transaction RPCs allow users to create custom transactionstransactions - A transaction spending satoshis. and delay broadcasting those transactions. However, mistakes made in raw transactionsraw transactions - Complete transactions in their binary format; often represented using hexadecimal. Sometimes called raw format because of the various Dash Core commands with "raw" in their names. may not be detected by Dash Core, and a number of raw transaction users have permanently lost large numbers of 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., so please be careful using raw transactions on mainnetmainnet - The original and main network for Dash transactions, where duffs have real economic value..

This subsection covers one of the simplest possible raw transactions.

📘

Note: the following steps pick up where the Simple Spending Tutorial left off

1. List unspent outputs

Re-rerun listunspent. We now have three UTXOs: the two transactions we created before plus the coinbase transactioncoinbase transaction - The first transaction in a block. Always created by a miner, it includes a single coinbase. from block #2. We save the TXIDTXID - An identifier used to uniquely identify a particular transaction; specifically, the sha256d hash of the transaction. and output indexoutput index - The sequentially-numbered index of outputs in a single transaction starting from 0. number (vout) of that coinbasecoinbase - A special field used as the sole input for coinbase transactions. The coinbase allows claiming the block reward and provides up to 100 bytes for arbitrary data. UTXO to shell variables.

dash-cli -regtest listunspent
[
  {
    "txid": "f84ca4ad33ec7889d3c6ac670152137a3ee1603c4096230a10562976f700d130",
    "vout": 0,
    "address": "yRdk89fwSW1mUBxQo5fCmEfTva7b4wh2H5",
    "account": "",
    "scriptPubKey": "76a9143a4e8960f26c1fa82d937046959b656e4dd7966688ac",
    "amount": 10.00000000,
    "confirmations": 1,
    "ps_rounds": -2,
    "spendable": true,
    "solvable": true
  },
  {
    "txid": "f84ca4ad33ec7889d3c6ac670152137a3ee1603c4096230a10562976f700d130",
    "vout": 1,
    "address": "yavnyFMebbfX4F2VC25P18FW6LS66h2wqJ",
    "scriptPubKey": "76a914a0411dbed3eab4341d5c41496d61b4fa1b22037e88ac",
    "amount": 490.00000000,
    "confirmations": 1,
    "ps_rounds": -2,
    "spendable": true,
    "solvable": true
  },
  {
    "txid": "9036265a8f577421e556cd4f729752d73469953deea759de11efa9ba354936a8",
    "vout": 0,
    "address": "yWtgzKSckhedxtJ8NXhShWGjfBivkvBGgG",
    "scriptPubKey": "21023fff9c9dc9088c0aeba90d75413705091111311d761054de23ac\
                      dd217450869aac",
    "amount": 500.00000000,
    "confirmations": 101,
    "ps_rounds": -2,
    "spendable": true,
    "solvable": true
  }
]

> UTXO_TXID=9036265a8f577421e556cd4f729752d73469953deea759de11ef[...]
> UTXO_VOUT=0

2. Get new address

dash-cli -regtest getnewaddress
yfV9Wirf5RkYHgNDttjpBz8Wdi8BavLHcP

> NEW_ADDRESS=yfV9Wirf5RkYHgNDttjpBz8Wdi8BavLHcP

3. Create raw transaction

Using two arguments to the createrawtransaction RPC, we create a new raw format transaction. The first argument (a JSON array) references the txid of the coinbase transaction from block #2 and the indexindex - An index number used in the HD wallet formula to generate child keys from a parent key number (0) of the outputoutput - An output in a transaction which contains two fields: a value field for transferring zero or more duffs and a pubkey script for indicating what conditions must be fulfilled for those duffs to be further spent. from that transaction we want to spend. The second argument (a JSON object) creates the output with the address ( public keypublic key - The public portion of a keypair which can be used to verify signatures made with the private portion of the keypair. hash) and number of DASH we want to transfer. We save the resulting raw format transaction to a shell variable.

❗️

Transaction fee warning

Warning: createrawtransaction does not automatically create change outputs, so you can easily accidentally pay a large transaction fee.

In this example, our input had 500.0000 DASH and our output ($NEW_ADDRESS) is being paid 499.9999 DASH, so the transaction will include a fee of 0.0001 DASH. If we had paid $NEW_ADDRESS only 100 DASH with no other changes to this transaction, the 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. would be a whopping 400 DASH. See the Complex Raw Transaction subsection below for how to create a transaction with multiple outputs so you can send the change back to yourself.

## Outputs - inputs = transaction fee, so always double-check your math!
dash-cli -regtest createrawtransaction ''' \
    [ \
      { \
        "txid": "'$UTXO_TXID'", \
        "vout": '$UTXO_VOUT' \
      } \
    ] \
    ''' ''' \
    { \
      "'$NEW_ADDRESS'": 499.9999 \
    }'''
0100000001a8364935baa9ef11de59a7ee3d956934d75297724fcd56e5217457\
8f5a2636900000000000ffffffff01f04c3ba40b0000001976a914d240140859\
744755d73e5967081c3bedceffc5db88ac00000000

> RAW_TX=0100000001a8364935baa9ef11de59a7ee3d956934d75297724fcd5[...]

4. Decode raw transaction

Use the decoderawtransaction RPC to see exactly what the transaction we just created does.

dash-cli -regtest decoderawtransaction $RAW_TX
{
  "txid": "7cbd2245ee5d824c00fc08b3bf2f694ad9a215d38d897fcf2df64a43c59bb97b",
  "size": 85,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "9036265a8f577421e556cd4f729752d73469953deea759de11efa9ba354936a8",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 499.99990000,
      "valueSat": 49999990000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 d240140859744755d73e5967081c3bedceffc5db\
                  OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914d240140859744755d73e5967081c3bedceffc5db88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yfV9Wirf5RkYHgNDttjpBz8Wdi8BavLHcP"
        ]
      }
    }
  ]
}

5. Sign transaction

Use the signrawtransaction RPC to sign the transaction created by createrawtransaction and save the returned "hex" raw format signed transaction to a shell variable.

dash-cli -regtest signrawtransaction $RAW_TX
{
  "hex": "0100000001a8364935baa9ef11de59a7ee3d956934d75297724fcd\
          56e52174578f5a2636900000000049483045022100b4e5e9224afa\
          de8686bb22a957d1ec1587a66ee84943761b2d9061d5f751cd7602\
          203c88d4064641a413ce3d0824264d6d87908960487afe9a3a133e\
          7d67a22fd05101ffffffff01f04c3ba40b0000001976a914d24014\
          0859744755d73e5967081c3bedceffc5db88ac00000000",
  "complete": true
}
> SIGNED_RAW_TX=0100000001a8364935baa9ef11de59a7ee3d956934d75297[...]

Even though the transaction is now complete, the Dash Core nodenode - A computer that connects to the Dash network. we're connected to doesn't know anything about the transaction, nor does any other part of the networknetwork - The Dash P2P network which broadcasts transactions and blocks.. We've created a spend, but we haven't actually spent anything because we could simply unset the $SIGNED_RAW_TX variable to eliminate the transaction.

6. Send raw transaction

Send the signed transaction to the connected node using the sendrawtransaction RPC. After accepting the transaction, the node would usually then broadcast it to other peerspeers - A computer that connects to the Dash network., but we're not currently connected to other peers because we started in regression test moderegression test mode - A local testing environment in which developers can almost instantly generate blocks on demand for testing events, and can create private duffs with no real-world value..

dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX
fa0f4105b0a2b2706d65581c5e6411d3970253c7f231944fa2f978b4a3d9010d

7. Mine a block

Generate a block to confirm the transaction and then clear our shell variables.

dash-cli -regtest generate 1

unset UTXO_TXID UTXO_VOUT NEW_ADDRESS RAW_TX SIGNED_RAW_TX

Updated about a year ago



Simple Raw Transaction


Suggested Edits are limited on API Reference Pages

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