Example transaction updates (simple raw tx)

This commit is contained in:
thephez 2017-12-12 09:57:31 -05:00
parent 21cd8094d0
commit 31f7365466
2 changed files with 95 additions and 99 deletions

View file

@ -128,9 +128,9 @@ second) and clear the shell variable.
{% endautocrossref %} {% endautocrossref %}
<!-- Shell script to run previous example
<script src="https://gist.github.com/dash-docs/f40bddfc0844ec0d66d196720dc936f8.js"></script>
-->
#### Simple Raw Transaction #### Simple Raw Transaction
@ -152,48 +152,47 @@ This subsection covers one of the simplest possible raw transactions.
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
[ [
{ {
"txid" : "263c018582731ff54dc72c7d67e858c002ae298835501d\ "txid": "f84ca4ad33ec7889d3c6ac670152137a3ee1603c4096230a10562976f700d130",
80200f05753de0edf0", "vout": 0,
"vout" : 0, "address": "yRdk89fwSW1mUBxQo5fCmEfTva7b4wh2H5",
"address" : "muhtvdmsnbQEPFuEmxcChX58fGvXaaUoVt", "account": "",
"scriptPubKey" : "76a9149ba386253ea698158b6d34802bb9b550\ "scriptPubKey": "76a9143a4e8960f26c1fa82d937046959b656e4dd7966688ac",
f5ce36dd88ac", "amount": 10.00000000,
"amount" : 40.00000000, "confirmations": 1,
"confirmations" : 1, "ps_rounds": -2,
"spendable" : true, "spendable": true,
"solvable" : true "solvable": true
}, },
{ {
"txid" : "263c018582731ff54dc72c7d67e858c002ae298835501d\ "txid": "f84ca4ad33ec7889d3c6ac670152137a3ee1603c4096230a10562976f700d130",
80200f05753de0edf0", "vout": 1,
"vout" : 1, "address": "yavnyFMebbfX4F2VC25P18FW6LS66h2wqJ",
"address" : "mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou", "scriptPubKey": "76a914a0411dbed3eab4341d5c41496d61b4fa1b22037e88ac",
"account" : "", "amount": 490.00000000,
"scriptPubKey" : "76a914a57414e5ffae9ef5074bacbe10a320bb\ "confirmations": 1,
2614e1f388ac", "ps_rounds": -2,
"amount" : 10.00000000, "spendable": true,
"confirmations" : 1, "solvable": true
"spendable" : true, },
"solvable" : true {
}, "txid": "9036265a8f577421e556cd4f729752d73469953deea759de11efa9ba354936a8",
{ "vout": 0,
"txid" : "3f4fa19803dec4d6a84fae3821da7ac7577080ef754512\ "address": "yWtgzKSckhedxtJ8NXhShWGjfBivkvBGgG",
94e71f9b20e0ab1e7b", "scriptPubKey": "21023fff9c9dc9088c0aeba90d75413705091111311d761054de23ac\
"vout" : 0, dd217450869aac",
"address" : "mwJTL1dZG8BAP6X7Be3CNNcuVKi7Qqt7Gk", "amount": 500.00000000,
"scriptPubKey" : "210260a275cccf0f4b106220725be516adba27\ "confirmations": 101,
52db1bec8c5b7174c89c4c07891f88ac", "ps_rounds": -2,
"amount" : 50.00000000, "spendable": true,
"confirmations" : 101, "solvable": true
"spendable" : true, }
"solvable" : true
}
] ]
{% endhighlight %} {% endhighlight %}
{% highlight bash %} {% highlight bash %}
> UTXO_TXID=3f4fa19803dec4d6a84fae3821da7ac7577080ef75451294e71f[...] > UTXO_TXID=9036265a8f577421e556cd4f729752d73469953deea759de11ef[...]
> UTXO_VOUT=0 > UTXO_VOUT=0
{% endhighlight %} {% endhighlight %}
</div> </div>
@ -205,9 +204,9 @@ variables.
{% highlight bash %} {% highlight bash %}
> dash-cli -regtest getnewaddress > dash-cli -regtest getnewaddress
mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG yfV9Wirf5RkYHgNDttjpBz8Wdi8BavLHcP
> NEW_ADDRESS=mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG > NEW_ADDRESS=yfV9Wirf5RkYHgNDttjpBz8Wdi8BavLHcP
{% endhighlight %} {% endhighlight %}
Get a new address to use in the raw transaction. Get a new address to use in the raw transaction.
@ -223,13 +222,13 @@ Get a new address to use in the raw transaction.
] ]
''' ''' ''' '''
{ {
"'$NEW_ADDRESS'": 49.9999 "'$NEW_ADDRESS'": 499.9999
}''' }'''
01000000017b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de\ 0100000001a8364935baa9ef11de59a7ee3d956934d75297724fcd56e5217457\
0398a14f3f0000000000ffffffff01f0ca052a010000001976a914cbc20a7664\ 8f5a2636900000000000ffffffff01f04c3ba40b0000001976a914d240140859\
f2f69e5355aa427045bc15e7c6c77288ac00000000 744755d73e5967081c3bedceffc5db88ac00000000
> RAW_TX=01000000017b1eabe0209b1fe794124575ef807057c77ada2138ae4[...] > RAW_TX=0100000001a8364935baa9ef11de59a7ee3d956934d75297724fcd5[...]
{% endhighlight %} {% endhighlight %}
Using two arguments to the `createrawtransaction` RPC, we create a new Using two arguments to the `createrawtransaction` RPC, we create a new
@ -243,11 +242,11 @@ 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 dash and our output this example, our input had 500.0000 dash and our output
(`$NEW_ADDRESS`) is being paid 49.9999 dash, so the transaction will (`$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 10 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 fee dash with no other changes to this transaction, the transaction fee
would be a whopping 40 dash. See the Complex Raw Transaction would be a whopping 400 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.
@ -258,42 +257,38 @@ can send the change back to yourself.
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
"txid" : "c80b343d2ce2b5d829c2de9854c7c8d423c0e33bda264c4013\ "txid": "7cbd2245ee5d824c00fc08b3bf2f694ad9a215d38d897fcf2df64a43c59bb97b",
8d834aab4c0638", "size": 85,
"hash" : "c80b343d2ce2b5d829c2de9854c7c8d423c0e33bda264c40138d834aab4c0638", "version": 1,
"size" : 85, "locktime": 0,
"vsize" : 85, "vin": [
"version" : 1, {
"locktime" : 0, "txid": "9036265a8f577421e556cd4f729752d73469953deea759de11efa9ba354936a8",
"vin" : [ "vout": 0,
{ "scriptSig": {
"txid" : "3f4fa19803dec4d6a84fae3821da7ac7577080ef75\ "asm": "",
451294e71f9b20e0ab1e7b", "hex": ""
"vout" : 0, },
"scriptSig" : { "sequence": 4294967295
"asm" : "", }
"hex" : "" ],
}, "vout": [
"sequence" : 4294967295 {
} "value": 499.99990000,
], "valueSat": 49999990000,
"vout" : [ "n": 0,
{ "scriptPubKey": {
"value" : 49.99990000, "asm": "OP_DUP OP_HASH160 d240140859744755d73e5967081c3bedceffc5db\
"n" : 0, OP_EQUALVERIFY OP_CHECKSIG",
"scriptPubKey" : { "hex": "76a914d240140859744755d73e5967081c3bedceffc5db88ac",
"asm" : "OP_DUP OP_HASH160 cbc20a7664f2f69e5355a\ "reqSigs": 1,
a427045bc15e7c6c772 OP_EQUALVERIFY OP_CHECKSIG", "type": "pubkeyhash",
"hex" : "76a914cbc20a7664f2f69e5355aa427045bc15e\ "addresses": [
7c6c77288ac", "yfV9Wirf5RkYHgNDttjpBz8Wdi8BavLHcP"
"reqSigs" : 1, ]
"type" : "pubkeyhash", }
"addresses" : [ }
"mz6KvC4aoUeo6wSxtiVQTo7FDwPnkp6URG" ]
]
}
}
]
} }
{% endhighlight %} {% endhighlight %}
</div> </div>
@ -307,19 +302,18 @@ we just created does.
{% endhighlight %} {% endhighlight %}
{% highlight json %} {% highlight json %}
{ {
"hex" : "01000000017b1eabe0209b1fe794124575ef807057c77ada213\ "hex": "0100000001a8364935baa9ef11de59a7ee3d956934d75297724fcd\
8ae4fa8d6c4de0398a14f3f00000000494830450221008949f0\ 56e52174578f5a2636900000000049483045022100b4e5e9224afa\
cb400094ad2b5eb399d59d01c14d73d8fe6e96df1a7150deb38\ de8686bb22a957d1ec1587a66ee84943761b2d9061d5f751cd7602\
8ab8935022079656090d7f6bac4c9a94e0aad311a4268e082a7\ 203c88d4064641a413ce3d0824264d6d87908960487afe9a3a133e\
25f8aeae0573fb12ff866a5f01ffffffff01f0ca052a0100000\ 7d67a22fd05101ffffffff01f04c3ba40b0000001976a914d24014\
01976a914cbc20a7664f2f69e5355aa427045bc15e7c6c77288\ 0859744755d73e5967081c3bedceffc5db88ac00000000",
ac00000000", "complete": true
"complete" : true
} }
{% endhighlight %} {% endhighlight %}
{% highlight bash %} {% highlight bash %}
> SIGNED_RAW_TX=01000000017b1eabe0209b1fe794124575ef807057c77ada[...] > SIGNED_RAW_TX=0100000001a8364935baa9ef11de59a7ee3d956934d75297[...]
{% endhighlight %} {% endhighlight %}
</div> </div>
@ -335,7 +329,7 @@ actually spent anything because we could simply unset the
{% highlight bash %} {% highlight bash %}
> dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX > dash-cli -regtest sendrawtransaction $SIGNED_RAW_TX
c7736a0a0046d5a8cc61c8c3c2821d4d7517f5de2bc66a966011aaa79965ffba fa0f4105b0a2b2706d65581c5e6411d3970253c7f231944fa2f978b4a3d9010d
{% endhighlight %} {% endhighlight %}
Send the signed transaction to the connected node using the Send the signed transaction to the connected node using the

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
REGTEST_CMD="dash-cli -regtest -rpcuser=user -rpcpassword=pass" RPCUSER="user"
RPCPWD="pass"
REGTEST_CMD="dash-cli -regtest -rpcuser=$RPCUSER -rpcpassword=$RPCPWD"
# SIMPLE SPENDING EXAMPLE # SIMPLE SPENDING EXAMPLE
# ----------------------- # -----------------------