Example testing/transaction updates

- Convert bitcoin -> dash
 - Complete testing section
 - Update transaction simple spending example

Added script to run through simple spending example on regtest
This commit is contained in:
thephez 2017-12-11 17:06:13 -05:00
parent 822098b5a1
commit 21cd8094d0
5 changed files with 239 additions and 164 deletions

View file

@ -7,9 +7,11 @@ http://opensource.org/licenses/MIT.
## Testing Applications ## Testing Applications
{% include helpers/subhead-links.md %} {% include helpers/subhead-links.md %}
<!-- __ -->
{% autocrossref %} {% autocrossref %}
Bitcoin Core provides testing tools designed to let developers Dash Core provides testing tools designed to let developers
test their applications with reduced risks and limitations. test their applications with reduced risks and limitations.
{% endautocrossref %} {% endautocrossref %}
@ -19,18 +21,26 @@ test their applications with reduced risks and limitations.
{% autocrossref %} {% autocrossref %}
When run with no arguments, all Bitcoin Core programs default to Bitcoin's main When run with no arguments, all Dash Core programs default to Dash's main
network ([mainnet][/en/glossary/mainnet]{:#term-mainnet}{:.term}). However, for development, network ([mainnet][/en/glossary/mainnet]{:#term-mainnet}{:.term}). However, for development,
it's safer and cheaper to use Bitcoin's test network (testnet) it's safer and cheaper to use Dash's test network (testnet)
where the satoshis spent have no real-world value. Testnet also relaxes some where the duffs spent have no real-world value. Testnet also relaxes some
restrictions (such as standard transaction checks) so you can test functions restrictions (such as standard transaction checks) so you can test functions
which might currently be disabled by default on mainnet. which might currently be disabled by default on mainnet.
To use testnet, use the argument `-testnet`<!--noref--> with `bitcoin-cli`, `bitcoind` or `bitcoin-qt` or add To use testnet, use the argument `-testnet`<!--noref--> with `dash-cli`, `dashd`
`testnet=1`<!--noref--> to your `bitcoin.conf` file as [described earlier][bitcoind initial setup]. To get or `dash-qt` or add `testnet=1`<!--noref--> to your `dash.conf` file as
free satoshis for testing, use [Piotr Piasecki's testnet faucet][]. [described earlier][dashd initial setup]. To get free duffs for testing,
Testnet is a public resource provided for free by members of the check the faucets listed below. They are community supported and due to
community, so please don't abuse it. potentially frequent Testnet changes, one or more of them may be unavailable at
a given time:
* [Testnet Faucet - Dash.org]
* [Testnet Faucet - Masternode.io]
* [Testnet Faucet - Dashninja.pl]
Testnet is a public resource provided for free by members of the community,
so please don't abuse it.
{% endautocrossref %} {% endautocrossref %}
@ -39,45 +49,41 @@ community, so please don't abuse it.
{% autocrossref %} {% autocrossref %}
For situations For situations where interaction with random peers and blocks is unnecessary or
where interaction with random peers and blocks is unnecessary or unwanted, Dash Core's regression test mode (regtest mode) lets you
unwanted, Bitcoin Core's regression test mode (regtest mode) lets you
instantly create a brand-new private block chain with the same basic instantly create a brand-new private block chain with the same basic
rules as testnet---but one major difference: you choose when to create rules as testnet---but one major difference: you choose when to create
new blocks, so you have complete control over the environment. new blocks, so you have complete control over the environment.
Many developers consider regtest mode the preferred way to develop new Many developers consider regtest mode the preferred way to develop new
applications. The following example will let you create a regtest applications. The following example will let you create a regtest
environment after you first [configure bitcoind][bitcoind initial setup]. environment after you first [configure dashd][dashd initial setup].
{% endautocrossref %} {% endautocrossref %}
{% highlight bash %} {% highlight bash %}
> bitcoind -regtest -daemon > dashd -regtest -daemon
Bitcoin server starting Dash Core server starting
{% endhighlight %} {% endhighlight %}
{% autocrossref %} {% autocrossref %}
Start `bitcoind` in regtest mode to create a private block chain. Start `dashd` in regtest mode to create a private block chain.
{% endautocrossref %} {% endautocrossref %}
~~~ ~~~
## Bitcoin Core 0.10.1 and earlier ## Dash Core
bitcoin-cli -regtest setgenerate true 101 dash-cli -regtest generate 101
## Bitcoin Core master (as of commit 48265f3)
bitcoin-cli -regtest generate 101
~~~ ~~~
{% autocrossref %} {% autocrossref %}
Generate 101 blocks using a special RPC Generate 101 blocks using a special RPC
which is only available in regtest mode. This takes less than a second on which is only available in regtest mode. This takes less than a second on
a generic PC. Because this is a new block chain using Bitcoin's default a generic PC. Because this is a new block chain using Dash's default
rules, the first blocks pay a block reward of 50 bitcoins. Unlike rules, the first blocks pay a block reward of 500 dash. Unlike
mainnet, in regtest mode only the first 150 blocks pay a reward of 50 bitcoins. mainnet, in regtest mode only the first 150 blocks pay a reward of 500 dash.
However, a block must have 100 confirmations before that reward can be However, a block must have 100 confirmations before that reward can be
spent, so we generate 101 blocks to get access to the coinbase spent, so we generate 101 blocks to get access to the coinbase
transaction from block #1. transaction from block #1.
@ -85,19 +91,19 @@ transaction from block #1.
{% endautocrossref %} {% endautocrossref %}
{% highlight bash %} {% highlight bash %}
bitcoin-cli -regtest getbalance dash-cli -regtest getbalance
50.00000000 500.00000000
{% endhighlight %} {% endhighlight %}
{% autocrossref %} {% autocrossref %}
Verify that we now have 50 bitcoins available to spend. Verify that we now have 500 dash available to spend.
You can now use Bitcoin Core RPCs prefixed with `bitcoin-cli -regtest`<!--noref-->. You can now use Dash Core RPCs prefixed with `dash-cli -regtest`<!--noref-->.
Regtest wallets and block chain state (chainstate) are saved in the `regtest`<!--noref--> Regtest wallets and block chain state (chainstate) are saved in the `regtest`<!--noref-->
subdirectory of the Bitcoin Core configuration directory. You can safely subdirectory of the Dash Core configuration directory. You can safely
delete the `regtest`<!--noref--> subdirectory and restart Bitcoin Core to delete the `regtest`<!--noref--> subdirectory and restart Dash Core to
start a new regtest. (See the [Developer Examples Introduction][devexamples] for default start a new regtest. (See the [Developer Examples Introduction][devexamples] for default
configuration directory locations on various operating systems. Always back up configuration directory locations on various operating systems. Always back up
mainnet wallets before performing dangerous operations such as deleting.) mainnet wallets before performing dangerous operations such as deleting.)

View file

@ -3,6 +3,7 @@ This file is licensed under the MIT License (MIT) available on
http://opensource.org/licenses/MIT. http://opensource.org/licenses/MIT.
{% endcomment %} {% endcomment %}
{% assign filename="_includes/devdoc/example_transactions.md" %} {% assign filename="_includes/devdoc/example_transactions.md" %}
<!-- __ -->
## Transactions ## Transactions
{% include helpers/subhead-links.md %} {% include helpers/subhead-links.md %}
@ -12,17 +13,17 @@ http://opensource.org/licenses/MIT.
{% autocrossref %} {% autocrossref %}
Creating transactions is something most Bitcoin applications do. Creating transactions is something most Dash applications do.
This section describes how to use Bitcoin Core's RPC interface to This section describes how to use Dash Core's RPC interface to
create transactions with various attributes. create transactions with various attributes.
Your applications may use something besides Bitcoin Core to create Your applications may use something besides Dash Core to create
transactions, but in any system, you will need to provide the same kinds transactions, but in any system, you will need to provide the same kinds
of data to create transactions with the same attributes as those of data to create transactions with the same attributes as those
described below. described below.
In order to use this tutorial, you will need to setup [Bitcoin Core][core executable] In order to use this tutorial, you will need to setup [Dash Core][core executable]
and create a regression test mode environment with 50 BTC in your test and create a regression test mode environment with 500 DASH in your test
wallet. wallet.
{% endautocrossref %} {% endautocrossref %}
@ -37,36 +38,36 @@ wallet.
{% autocrossref %} {% autocrossref %}
Bitcoin Core provides several RPCs which handle all the details of Dash Core provides several RPCs which handle all the details of
spending, including creating change outputs and paying appropriate fees. spending, including creating change outputs and paying appropriate fees.
Even advanced users should use these RPCs whenever possible to decrease Even advanced users should use these RPCs whenever possible to decrease
the chance that satoshis will be lost by mistake. the chance that duffs will be lost by mistake.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou yLp6ZJueuigiF4s9E1Pv8tEunDPEsjyQfd
> NEW_ADDRESS=mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou > NEW_ADDRESS=yLp6ZJueuigiF4s9E1Pv8tEunDPEsjyQfd
{% endhighlight %} {% endhighlight %}
Get a new Bitcoin address and save it in the shell variable `$NEW_ADDRESS`. Get a new Dash address and save it in the shell variable `$NEW_ADDRESS`.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest sendtoaddress $NEW_ADDRESS 10.00 > dash-cli -regtest sendtoaddress $NEW_ADDRESS 10.00
263c018582731ff54dc72c7d67e858c002ae298835501d80200f05753de0edf0 c7e5ae1240fdd83bb94c94a93816ed2ab7bcb56ec3ff8a9725c5c1e0482684ea
{% endhighlight %} {% endhighlight %}
Send 10 bitcoins to the address using the `sendtoaddress` RPC. The Send 10 dash to the address using the `sendtoaddress` RPC. The
returned hex string is the transaction identifier (txid). returned hex string is the transaction identifier (txid).
The `sendtoaddress` RPC automatically selects an unspent transaction The `sendtoaddress` RPC automatically selects an unspent transaction
output (UTXO) from which to spend the satoshis. In this case, it output (UTXO) from which to spend the duffs. In this case, it
withdrew the satoshis from our only available UTXO, the coinbase withdrew the duffs from our only available UTXO, the coinbase
transaction for block #1 which matured with the creation of block #101. transaction for block #1 which matured with the creation of block #101.
To spend a specific UTXO, you could use the `sendfrom` RPC instead. To spend a specific UTXO, you could use the `sendfrom` RPC instead.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest listunspent > dash-cli -regtest listunspent
[ [
] ]
{% endhighlight %} {% endhighlight %}
@ -77,35 +78,33 @@ UTXOs and we just spent our only confirmed UTXO.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest listunspent 0 > dash-cli -regtest listunspent 0
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
[ [
{ {
"txid" : "263c018582731ff54dc72c7d67e858c002ae298835501d\ "txid":"c7e5ae1240fdd83bb94c94a93816ed2ab7bcb56ec3ff8a9725c5c1e0482684ea",
80200f05753de0edf0", "vout":0,
"vout" : 0, "address":"yLp6ZJueuigiF4s9E1Pv8tEunDPEsjyQfd",
"address" : "muhtvdmsnbQEPFuEmxcChX58fGvXaaUoVt", "account":"",
"scriptPubKey" : "76a9149ba386253ea698158b6d34802bb9b550\ "scriptPubKey":"76a914056b1fe57914236149feb21dcbc6b86f4bdd9f4988ac",
f5ce36dd88ac", "amount":10.00000000,
"amount" : 40.00000000, "confirmations":0,
"confirmations" : 0, "ps_rounds":-2,
"spendable" : true, "spendable":true,
"solvable" : true "solvable":true
}, },
{ {
"txid" : "263c018582731ff54dc72c7d67e858c002ae298835501d\ "txid":"c7e5ae1240fdd83bb94c94a93816ed2ab7bcb56ec3ff8a9725c5c1e0482684ea",
80200f05753de0edf0", "vout":1,
"vout" : 1, "address":"yeP6Tw2uW4nWAFWRytw8TyshErTq59dUkN",
"address" : "mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou", "scriptPubKey":"76a914c622e98a6ccf34d02620612f58f20a50061cf4b188ac",
"account" : "", "amount":490.00000000,
"scriptPubKey" : "76a914a57414e5ffae9ef5074bacbe10a320bb\ "confirmations":0,
2614e1f388ac", "ps_rounds":-2,
"amount" : 10.00000000, "spendable":true,
"confirmations" : 0, "solvable":true
"spendable" : true, }
"solvable" : true
}
] ]
{% endhighlight %} {% endhighlight %}
</div> </div>
@ -114,12 +113,12 @@ Re-running the `listunspent` RPC with the argument "0" to also display
unconfirmed transactions shows that we have two UTXOs, both with the unconfirmed transactions shows that we have two UTXOs, both with the
same txid. The first UTXO shown is a change output that `sendtoaddress` same txid. The first UTXO shown is a change output that `sendtoaddress`
created using a new address from the key pool. The second UTXO shown is 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 satoshis to 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 someone else, that second transaction would not be displayed in our
list of UTXOs. list of UTXOs.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest generate 1 > dash-cli -regtest generate 1
> unset NEW_ADDRESS > unset NEW_ADDRESS
{% endhighlight %} {% endhighlight %}
@ -141,15 +140,15 @@ second) and clear the shell variable.
The raw transaction RPCs allow users to create custom transactions and The raw transaction RPCs allow users to create custom transactions and
delay broadcasting those transactions. However, mistakes made in raw delay broadcasting those transactions. However, mistakes made in raw
transactions may not be detected by Bitcoin Core, and a number of raw transactions may not be detected by Dash Core, and a number of raw
transaction users have permanently lost large numbers of satoshis, so transaction users have permanently lost large numbers of duffs, so
please be careful using raw transactions on mainnet. please be careful using raw transactions on mainnet.
This subsection covers one of the simplest possible raw transactions. This subsection covers one of the simplest possible raw transactions.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest listunspent > dash-cli -regtest listunspent
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
[ [
@ -205,7 +204,7 @@ txid and output index number (vout) of that coinbase UTXO to shell
variables. variables.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG
> NEW_ADDRESS=mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG > NEW_ADDRESS=mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG
@ -215,7 +214,7 @@ Get a new address to use in the raw transaction.
{% highlight bash %} {% highlight bash %}
## Outputs - inputs = transaction fee, so always double-check your math! ## Outputs - inputs = transaction fee, so always double-check your math!
> bitcoin-cli -regtest createrawtransaction ''' > dash-cli -regtest createrawtransaction '''
[ [
{ {
"txid": "'$UTXO_TXID'", "txid": "'$UTXO_TXID'",
@ -238,24 +237,24 @@ raw format transaction. The first argument (a JSON array) references
the txid of the coinbase transaction from block #2 and the index the txid of the coinbase transaction from block #2 and the index
number (0) of the output from that transaction we want to spend. The number (0) of the output from that transaction we want to spend. The
second argument (a JSON object) creates the output with the address second argument (a JSON object) creates the output with the address
(public key hash) and number of bitcoins we want to transfer. (public key hash) and number of dash we want to transfer.
We save the resulting raw format transaction to a shell variable. We save the resulting raw format transaction to a shell variable.
![Warning icon](/img/icons/icon_warning.svg) ![Warning icon](/img/icons/icon_warning.svg)
**Warning:** `createrawtransaction` does not automatically create change **Warning:** `createrawtransaction` does not automatically create change
outputs, so you can easily accidentally pay a large transaction fee. In outputs, so you can easily accidentally pay a large transaction fee. In
this example, our input had 50.0000 bitcoins and our output this example, our input had 50.0000 dash and our output
(`$NEW_ADDRESS`) is being paid 49.9999 bitcoins, so the transaction will (`$NEW_ADDRESS`) is being paid 49.9999 dash, so the transaction will
include a fee of 0.0001 bitcoins. If we had paid `$NEW_ADDRESS` only 10 include a fee of 0.0001 dash. If we had paid `$NEW_ADDRESS` only 10
bitcoins with no other changes to this transaction, the transaction fee dash with no other changes to this transaction, the transaction fee
would be a whopping 40 bitcoins. See the Complex Raw Transaction would be a whopping 40 dash. See the Complex Raw Transaction
subsection below for how to create a transaction with multiple outputs so you subsection below for how to create a transaction with multiple outputs so you
can send the change back to yourself. can send the change back to yourself.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest decoderawtransaction $RAW_TX > dash-cli -regtest decoderawtransaction $RAW_TX
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
@ -304,7 +303,7 @@ we just created does.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $RAW_TX > dash-cli -regtest signrawtransaction $RAW_TX
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
@ -328,14 +327,14 @@ Use the `signrawtransaction` RPC to sign the transaction created by
`createrawtransaction` and save the returned "hex" raw format signed `createrawtransaction` and save the returned "hex" raw format signed
transaction to a shell variable. transaction to a shell variable.
Even though the transaction is now complete, the Bitcoin Core node we're Even though the transaction is now complete, the Dash Core node we're
connected to doesn't know anything about the transaction, nor does any connected to doesn't know anything about the transaction, nor does any
other part of the network. We've created a spend, but we haven't other part of the network. We've created a spend, but we haven't
actually spent anything because we could simply unset the actually spent anything because we could simply unset the
`$SIGNED_RAW_TX` variable to eliminate the transaction. `$SIGNED_RAW_TX` variable to eliminate the transaction.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest sendrawtransaction $SIGNED_RAW_TX > dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX
c7736a0a0046d5a8cc61c8c3c2821d4d7517f5de2bc66a966011aaa79965ffba c7736a0a0046d5a8cc61c8c3c2821d4d7517f5de2bc66a966011aaa79965ffba
{% endhighlight %} {% endhighlight %}
@ -345,7 +344,7 @@ would usually then broadcast it to other peers, but we're not currently
connected to other peers because we started in regtest mode. connected to other peers because we started in regtest mode.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest generate 1 > dash-cli -regtest generate 1
> unset UTXO_TXID UTXO_VOUT NEW_ADDRESS RAW_TX SIGNED_RAW_TX > unset UTXO_TXID UTXO_VOUT NEW_ADDRESS RAW_TX SIGNED_RAW_TX
{% endhighlight %} {% endhighlight %}
@ -371,7 +370,7 @@ transaction together (such as a CoinJoin transaction).
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest listunspent > dash-cli -regtest listunspent
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
[ [
@ -446,10 +445,10 @@ transactions. We need the addresses so we can get the corresponding
private keys from our wallet. private keys from our wallet.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest dumpprivkey $UTXO1_ADDRESS > dash-cli -regtest dumpprivkey $UTXO1_ADDRESS
cSp57iWuu5APuzrPGyGc4PGUeCg23PjenZPBPoUs24HtJawccHPm cSp57iWuu5APuzrPGyGc4PGUeCg23PjenZPBPoUs24HtJawccHPm
> bitcoin-cli -regtest dumpprivkey $UTXO2_ADDRESS > dash-cli -regtest dumpprivkey $UTXO2_ADDRESS
cT26DX6Ctco7pxaUptJujRfbMS2PJvdqiSMaGaoSktHyon8kQUSg cT26DX6Ctco7pxaUptJujRfbMS2PJvdqiSMaGaoSktHyon8kQUSg
> UTXO1_PRIVATE_KEY=cSp57iWuu5APuzrPGyGc4PGUeCg23PjenZPBPoUs24Ht[...] > UTXO1_PRIVATE_KEY=cSp57iWuu5APuzrPGyGc4PGUeCg23PjenZPBPoUs24Ht[...]
@ -470,9 +469,9 @@ These examples are to help you learn, not for you to emulate on
mainnet. mainnet.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
n4puhBEeEWD2VvjdRC9kQuX2abKxSCMNqN n4puhBEeEWD2VvjdRC9kQuX2abKxSCMNqN
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
n4LWXU59yM5MzQev7Jx7VNeq1BqZ85ZbLj n4LWXU59yM5MzQev7Jx7VNeq1BqZ85ZbLj
> NEW_ADDRESS1=n4puhBEeEWD2VvjdRC9kQuX2abKxSCMNqN > NEW_ADDRESS1=n4puhBEeEWD2VvjdRC9kQuX2abKxSCMNqN
@ -483,7 +482,7 @@ For our two outputs, get two new addresses.
{% highlight bash %} {% highlight bash %}
## Outputs - inputs = transaction fee, so always double-check your math! ## Outputs - inputs = transaction fee, so always double-check your math!
> bitcoin-cli -regtest createrawtransaction ''' > dash-cli -regtest createrawtransaction '''
[ [
{ {
"txid": "'$UTXO1_TXID'", "txid": "'$UTXO1_TXID'",
@ -514,7 +513,7 @@ before, except now we have two inputs and two outputs.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $RAW_TX '[]' ''' > dash-cli -regtest signrawtransaction $RAW_TX '[]' '''
[ [
"'$UTXO1_PRIVATE_KEY'" "'$UTXO1_PRIVATE_KEY'"
]''' ]'''
@ -567,7 +566,7 @@ transaction hex to a shell variable.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $PARTLY_SIGNED_RAW_TX '[]' ''' > dash-cli -regtest signrawtransaction $PARTLY_SIGNED_RAW_TX '[]' '''
[ [
"'$UTXO2_PRIVATE_KEY'" "'$UTXO2_PRIVATE_KEY'"
]''' ]'''
@ -654,7 +653,7 @@ variable.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest decoderawtransaction $OLD_SIGNED_RAW_TX > dash-cli -regtest decoderawtransaction $OLD_SIGNED_RAW_TX
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
@ -751,17 +750,17 @@ specific one of its UTXOs to spend and save that UTXO's output index number
(vout) and hex pubkey script (scriptPubKey) into shell variables. (vout) and hex pubkey script (scriptPubKey) into shell variables.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mfdCHEFL2tW9eEUpizk7XLZJcnFM4hrp78 mfdCHEFL2tW9eEUpizk7XLZJcnFM4hrp78
> NEW_ADDRESS=mfdCHEFL2tW9eEUpizk7XLZJcnFM4hrp78 > NEW_ADDRESS=mfdCHEFL2tW9eEUpizk7XLZJcnFM4hrp78
{% endhighlight %} {% endhighlight %}
Get a new address to spend the satoshis to. Get a new address to spend the duffs to.
{% highlight bash %} {% highlight bash %}
## Outputs - inputs = transaction fee, so always double-check your math! ## Outputs - inputs = transaction fee, so always double-check your math!
> bitcoin-cli -regtest createrawtransaction ''' > dash-cli -regtest createrawtransaction '''
[ [
{ {
"txid": "'$UTXO_TXID'", "txid": "'$UTXO_TXID'",
@ -784,7 +783,7 @@ subsections.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $RAW_TX > dash-cli -regtest signrawtransaction $RAW_TX
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
@ -821,7 +820,7 @@ so it can't automatically insert the previous pubkey script.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $RAW_TX ''' > dash-cli -regtest signrawtransaction $RAW_TX '''
[ [
{ {
"txid": "'$UTXO_TXID'", "txid": "'$UTXO_TXID'",
@ -862,7 +861,7 @@ broadcasts it.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest sendrawtransaction $SIGNED_RAW_TX > dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
error: {"code":-22,"message":"TX rejected"} error: {"code":-22,"message":"TX rejected"}
@ -874,9 +873,9 @@ first transaction. The node rejects this attempt because the second
transaction spends an output which is not a UTXO the node knows about. transaction spends an output which is not a UTXO the node knows about.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest sendrawtransaction $OLD_SIGNED_RAW_TX > dash-cli -regtest sendrawtransaction $OLD_SIGNED_RAW_TX
682cad881df69cb9df8f0c996ce96ecad758357ded2da03bad40cf18ffbb8e09 682cad881df69cb9df8f0c996ce96ecad758357ded2da03bad40cf18ffbb8e09
> bitcoin-cli -regtest sendrawtransaction $SIGNED_RAW_TX > dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX
67d53afa1a8167ca093d30be7fb9dcb8a64a5fdecacec9d93396330c47052c57 67d53afa1a8167ca093d30be7fb9dcb8a64a5fdecacec9d93396330c47052c57
{% endhighlight %} {% endhighlight %}
@ -886,7 +885,7 @@ the UTXO.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getrawmempool > dash-cli -regtest getrawmempool
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
[ [
@ -919,7 +918,7 @@ Remove old shell variables.
{% autocrossref %} {% autocrossref %}
In this subsection, we will create a P2SH multisig address, spend In this subsection, we will create a P2SH multisig address, spend
satoshis to it, and then spend those satoshis from it to another duffs to it, and then spend those duffs from it to another
address. address.
Creating a multisig address is easy. Multisig outputs have two Creating a multisig address is easy. Multisig outputs have two
@ -928,11 +927,11 @@ parameters, the *minimum* number of signatures required (*m*) and the
called m-of-n, and in this case we'll be using 2-of-3. called m-of-n, and in this case we'll be using 2-of-3.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mhAXF4Eq7iRyvbYk1mpDVBiGdLP3YbY6Dm mhAXF4Eq7iRyvbYk1mpDVBiGdLP3YbY6Dm
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
moaCrnRfP5zzyhW8k65f6Rf2z5QpvJzSKe moaCrnRfP5zzyhW8k65f6Rf2z5QpvJzSKe
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mk2QpYatsKicvFVuTAQLBryyccRXMUaGHP mk2QpYatsKicvFVuTAQLBryyccRXMUaGHP
> NEW_ADDRESS1=mhAXF4Eq7iRyvbYk1mpDVBiGdLP3YbY6Dm > NEW_ADDRESS1=mhAXF4Eq7iRyvbYk1mpDVBiGdLP3YbY6Dm
@ -943,7 +942,7 @@ called m-of-n, and in this case we'll be using 2-of-3.
Generate three new P2PKH addresses. P2PKH addresses cannot be used with Generate three new P2PKH addresses. P2PKH addresses cannot be used with
the multisig redeem script created below. (Hashing each public key is the multisig redeem script created below. (Hashing each public key is
unnecessary anyway---all the public keys are protected by a hash when unnecessary anyway---all the public keys are protected by a hash when
the redeem script is hashed.) However, Bitcoin Core uses addresses as a the redeem script is hashed.) However, Dash Core uses addresses as a
way to reference the underlying full (unhashed) public keys it knows way to reference the underlying full (unhashed) public keys it knows
about, so we get the three new addresses above in order to use their about, so we get the three new addresses above in order to use their
public keys. public keys.
@ -955,7 +954,7 @@ redeem script. You must give them a full public key.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest validateaddress $NEW_ADDRESS3 > dash-cli -regtest validateaddress $NEW_ADDRESS3
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
@ -987,7 +986,7 @@ We save the address returned to a shell variable.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest createmultisig 2 ''' > dash-cli -regtest createmultisig 2 '''
[ [
"'$NEW_ADDRESS1'", "'$NEW_ADDRESS1'",
"'$NEW_ADDRESS2'", "'$NEW_ADDRESS2'",
@ -1019,16 +1018,16 @@ one public key---all of which will be converted to public keys in the
redeem script. redeem script.
The P2SH address is returned along with the redeem script which must be The P2SH address is returned along with the redeem script which must be
provided when we spend satoshis sent to the P2SH address. provided when we spend duffs sent to the P2SH address.
![Warning icon](/img/icons/icon_warning.svg) ![Warning icon](/img/icons/icon_warning.svg)
**Warning:** You must not lose the redeem script, especially if you **Warning:** You must not lose the redeem script, especially if you
don't have a record of which public keys you used to create the P2SH don't have a record of which public keys you used to create the P2SH
multisig address. You need the redeem script to spend any bitcoins sent multisig address. You need the redeem script to spend any dash sent
to the P2SH address. If you lose the redeem script, you can recreate it to the P2SH address. If you lose the redeem script, you can recreate it
by running the same command above, with the public keys listed in the by running the same command above, with the public keys listed in the
same order. However, if you lose both the redeem script and even one of same order. However, if you lose both the redeem script and even one of
the public keys, you will never be able to spend satoshis sent to that the public keys, you will never be able to spend duffs sent to that
P2SH address. P2SH address.
Neither the address nor the redeem script are stored in the wallet when Neither the address nor the redeem script are stored in the wallet when
@ -1037,13 +1036,13 @@ you use `createmultisig`. To store them in the wallet, use the
you should also make a new backup. you should also make a new backup.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest sendtoaddress $P2SH_ADDRESS 10.00 > dash-cli -regtest sendtoaddress $P2SH_ADDRESS 10.00
7278d7d030f042ebe633732b512bcb31fff14a697675a1fe1884db139876e175 7278d7d030f042ebe633732b512bcb31fff14a697675a1fe1884db139876e175
> UTXO_TXID=7278d7d030f042ebe633732b512bcb31fff14a697675a1fe1884[...] > UTXO_TXID=7278d7d030f042ebe633732b512bcb31fff14a697675a1fe1884[...]
{% endhighlight %} {% endhighlight %}
Paying the P2SH multisig address with Bitcoin Core is as simple as Paying the P2SH multisig address with Dash Core is as simple as
paying a more common P2PKH address. Here we use the same command (but paying a more common P2PKH address. Here we use the same command (but
different variable) we used in the Simple Spending subsection. As different variable) we used in the Simple Spending subsection. As
before, this command automatically selects an UTXO, creates a change before, this command automatically selects an UTXO, creates a change
@ -1054,7 +1053,7 @@ We save that txid to a shell variable as the txid of the UTXO we plan to spend n
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getrawtransaction $UTXO_TXID 1 > dash-cli -regtest getrawtransaction $UTXO_TXID 1
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
@ -1123,11 +1122,11 @@ We save that txid to a shell variable as the txid of the UTXO we plan to spend n
We use the `getrawtransaction` RPC with the optional second argument We use the `getrawtransaction` RPC with the optional second argument
(*true*) to get the decoded transaction we just created with (*true*) to get the decoded transaction we just created with
`spendtoaddress`. We choose one of the outputs to be our UTXO and get `sendtoaddress`. We choose one of the outputs to be our UTXO and get
its output index number (vout) and pubkey script (scriptPubKey). its output index number (vout) and pubkey script (scriptPubKey).
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mxCNLtKxzgjg8yyNHeuFSXvxCvagkWdfGU mxCNLtKxzgjg8yyNHeuFSXvxCvagkWdfGU
> NEW_ADDRESS4=mxCNLtKxzgjg8yyNHeuFSXvxCvagkWdfGU > NEW_ADDRESS4=mxCNLtKxzgjg8yyNHeuFSXvxCvagkWdfGU
@ -1138,7 +1137,7 @@ create.
{% highlight bash %} {% highlight bash %}
## Outputs - inputs = transaction fee, so always double-check your math! ## Outputs - inputs = transaction fee, so always double-check your math!
> bitcoin-cli -regtest createrawtransaction ''' > dash-cli -regtest createrawtransaction '''
[ [
{ {
"txid": "'$UTXO_TXID'", "txid": "'$UTXO_TXID'",
@ -1161,9 +1160,9 @@ We generate the raw transaction the same way we did in the Simple Raw
Transaction subsection. Transaction subsection.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest dumpprivkey $NEW_ADDRESS1 > dash-cli -regtest dumpprivkey $NEW_ADDRESS1
cVinshabsALz5Wg4tGDiBuqEGq4i6WCKWXRQdM8RFxLbALvNSHw7 cVinshabsALz5Wg4tGDiBuqEGq4i6WCKWXRQdM8RFxLbALvNSHw7
> bitcoin-cli -regtest dumpprivkey $NEW_ADDRESS3 > dash-cli -regtest dumpprivkey $NEW_ADDRESS3
cNmbnwwGzEghMMe1vBwH34DFHShEj5bcXD1QpFRPHgG9Mj1xc5hq cNmbnwwGzEghMMe1vBwH34DFHShEj5bcXD1QpFRPHgG9Mj1xc5hq
> NEW_ADDRESS1_PRIVATE_KEY=cVinshabsALz5Wg4tGDiBuqEGq4i6WCKWXRQd[...] > NEW_ADDRESS1_PRIVATE_KEY=cVinshabsALz5Wg4tGDiBuqEGq4i6WCKWXRQd[...]
@ -1182,7 +1181,7 @@ complex raw transaction].
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $RAW_TX ''' > dash-cli -regtest signrawtransaction $RAW_TX '''
[ [
{ {
"txid": "'$UTXO_TXID'", "txid": "'$UTXO_TXID'",
@ -1224,7 +1223,7 @@ to the signature script after the two signatures.
<div markdown="1" class="multicode"> <div markdown="1" class="multicode">
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest signrawtransaction $PARTLY_SIGNED_RAW_TX ''' > dash-cli -regtest signrawtransaction $PARTLY_SIGNED_RAW_TX '''
[ [
{ {
"txid": "'$UTXO_TXID'", "txid": "'$UTXO_TXID'",
@ -1269,7 +1268,7 @@ two required signatures have been provided, the transaction is marked as
complete. complete.
{% highlight bash %} {% highlight bash %}
> bitcoin-cli -regtest sendrawtransaction $SIGNED_RAW_TX > dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX
430a4cee3a55efb04cbb8718713cab18dea7f2521039aa660ffb5aae14ff3f50 430a4cee3a55efb04cbb8718713cab18dea7f2521039aa660ffb5aae14ff3f50
{% endhighlight %} {% endhighlight %}

View file

@ -326,7 +326,7 @@ http://opensource.org/licenses/MIT.
[Bitcoin Core 0.14.1]: /en/release/v0.14.1 [Bitcoin Core 0.14.1]: /en/release/v0.14.1
[Bitcoin Core 0.14.2]: /en/release/v0.14.2 [Bitcoin Core 0.14.2]: /en/release/v0.14.2
[bitcoin URI subsection]: /en/developer-guide#bitcoin-uri [bitcoin URI subsection]: /en/developer-guide#bitcoin-uri
[bitcoind initial setup]: /en/developer-examples [dashd initial setup]: /en/developer-examples
[bitcoinpdf]: https://bitcoin.org/en/bitcoin-paper [bitcoinpdf]: https://bitcoin.org/en/bitcoin-paper
[choose your wallet]: https://www.dash.org/wallets/ [choose your wallet]: https://www.dash.org/wallets/
[communities]: https://www.dash.org/community/ [communities]: https://www.dash.org/community/
@ -519,6 +519,9 @@ http://opensource.org/licenses/MIT.
[Stratum mining protocol]: http://mining.bitcoin.cz/stratum-mining [Stratum mining protocol]: http://mining.bitcoin.cz/stratum-mining
[study of SPV privacy over tor]: http://arxiv.org/abs/1410.6079 [study of SPV privacy over tor]: http://arxiv.org/abs/1410.6079
[superblock example]: https://chainz.cryptoid.info/dash/block.dws?731104.htm [superblock example]: https://chainz.cryptoid.info/dash/block.dws?731104.htm
[Testnet Faucet - Dash.org]: https://test.faucet.dash.org/
[Testnet Faucet - Masternode.io]: http://test.faucet.masternode.io/
[Testnet Faucet - Dashninja.pl]: https://test.faucet.dashninja.pl/
[Tor]: https://en.wikipedia.org/wiki/Tor_%28anonymity_network%29 [Tor]: https://en.wikipedia.org/wiki/Tor_%28anonymity_network%29
[transifex]: https://www.transifex.com/projects/p/bitcoinorg/ [transifex]: https://www.transifex.com/projects/p/bitcoinorg/
[unix epoch time]: https://en.wikipedia.org/wiki/Unix_time [unix epoch time]: https://en.wikipedia.org/wiki/Unix_time

View file

@ -5,7 +5,7 @@
layout: base layout: base
lang: en lang: en
id: developer-examples id: developer-examples
title: "Developer Examples - Bitcoin" title: "Developer Examples - Dash"
breadcrumbs: breadcrumbs:
# - bitcoin # - bitcoin
- dev docs - dev docs
@ -18,9 +18,9 @@ end_of_page: |
--- ---
<link rel="stylesheet" href="/css/jquery-ui.min.css"> <link rel="stylesheet" href="/css/jquery-ui.min.css">
# Bitcoin Developer Examples # Dash Developer Examples
<p class="summary">Find examples of how to build programs using Bitcoin.</p> <p class="summary">Find examples of how to build programs using Dash.</p>
<div markdown="1" id="toc" class="toc"><div markdown="1"> <div markdown="1" id="toc" class="toc"><div markdown="1">
@ -28,8 +28,8 @@ end_of_page: |
{:toc} {:toc}
<ul class="goback"><li><a href="/en">Return To Overview</a></li></ul> <ul class="goback"><li><a href="/en">Return To Overview</a></li></ul>
<ul class="reportissue"><li><a href="https://github.com/bitcoin-dot-org/bitcoin.org/issues/new" onmouseover="updateIssue(event);">Report An Issue</a></li></ul> <ul class="reportissue"><li><a href="https://github.com/thephez/dash.org/issues/new" onmouseover="updateIssue(event);">Report An Issue</a></li></ul>
<ul class="editsource"><li><a href="https://github.com/bitcoin-dot-org/bitcoin.org/tree/master/_includes" onmouseover="updateSource(event);">Edit On GitHub</a></li></ul> <ul class="editsource"><li><a href="https://github.com/thephez/dash.org/tree/master/_includes" onmouseover="updateSource(event);">Edit On GitHub</a></li></ul>
</div></div> </div></div>
<div markdown="1" class="toccontent"> <div markdown="1" class="toccontent">
@ -44,7 +44,9 @@ end_of_page: |
{% include devdoc/example_transactions.md %} {% include devdoc/example_transactions.md %}
<!-- Services like Blockcyper are more likely to be used by most than building a ground-up payment system
{% include devdoc/example_payment_processing.md %} {% include devdoc/example_payment_processing.md %}
-->
{% include devdoc/example_p2p_networking.md %} {% include devdoc/example_p2p_networking.md %}

View file

@ -0,0 +1,65 @@
#!/bin/bash
REGTEST_CMD="dash-cli -regtest -rpcuser=user -rpcpassword=pass"
# 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