{% comment %} This file is licensed under the MIT License (MIT) available on http://opensource.org/licenses/MIT. {% endcomment %} {% assign filename="_includes/devdoc/example_transactions.md" %} ## Transactions {% include helpers/subhead-links.md %} ### Transaction Tutorial {% include helpers/subhead-links.md %} {% autocrossref %} Creating transactions is something most Bitcoin applications do. This section describes how to use Bitcoin Core's RPC interface to create transactions with various attributes. Your applications may use something besides Bitcoin Core to create transactions, but in any system, you will need to provide the same kinds of data to create transactions with the same attributes as those described below. In order to use this tutorial, you will need to setup [Bitcoin Core][core executable] and create a regression test mode environment with 50 BTC in your test wallet. {% endautocrossref %} #### Simple Spending {% include helpers/subhead-links.md %} {% autocrossref %} Bitcoin Core provides several RPCs which handle all the details of spending, including creating change outputs and paying appropriate fees. Even advanced users should use these RPCs whenever possible to decrease the chance that satoshis will be lost by mistake. {% highlight bash %} > bitcoin-cli -regtest getnewaddress mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou > NEW_ADDRESS=mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou {% endhighlight %} Get a new Bitcoin address and save it in the shell variable `$NEW_ADDRESS`. {% highlight bash %} > bitcoin-cli -regtest sendtoaddress $NEW_ADDRESS 10.00 263c018582731ff54dc72c7d67e858c002ae298835501d80200f05753de0edf0 {% endhighlight %} Send 10 bitcoins to the address using the `sendtoaddress` RPC. The returned hex string is the transaction identifier (txid). The `sendtoaddress` RPC automatically selects an unspent transaction output (UTXO) from which to spend the satoshis. In this case, it withdrew the satoshis from our only available UTXO, the coinbase transaction for block #1 which matured with the creation of block #101. To spend a specific UTXO, you could use the `sendfrom` RPC instead. {% highlight bash %} > bitcoin-cli -regtest listunspent [ ] {% endhighlight %} Use the `listunspent` RPC to display the UTXOs belonging to this wallet. The list is empty because it defaults to only showing confirmed UTXOs and we just spent our only confirmed UTXO.