# Spending BTC

Spending money is a secured process that requires several steps and moving files between your online client PC and your offline wallet machine. USB flash disk is probably the most convenient medium to use for this purpose.
Never move any files others than the ones that you actually need to move, which are:

- The `balance/` folder containing your unspent outputs - you move it from client to wallet
- Text files with signed transactions - these you move from wallet to client

Assuming that you would not sign a wrong transaction, nothing in the files you move between the two points is security sensitive, so you do not need to worry about protecting the medium (USB disk).

## 1. Export your balance

In order to spend your coins you will need to copy the `balance` folder (containing `unspent.txt` and one or more `<txid>.tx` files) to the PC that runs your wallet.

If you have no client: use balio tool | If you have a running client: use WebUI

There is a tool balio that can fetch a balance of your wallet from a public block explorer
Run the tool from a command line with a path to your wallet file or the list of (space separated) public addresses for which you want to fetch the balance.
It should create the `balance/` folder in the current directory, ready to be provided to your wallet.
Note: balio can also fetch balance of Litecoin addresses. You can then spent your Litecoins using gocoin wallet, along with `-ltc` switch.
Note:fetching the balance this way exposes your privacy.
To use balio through Tor, set TOR environment variable in your system, pointing it to your tor's socks proxy (e.g. `TOR=localhost:9050`).
Additionally, despite of using Tor, to further protect your privacy try to fetch balance of single addresses instead of entire wallets.

From the moment a content of `wallet.txt` file is properly stored in your browser, you can check and export your balance. Do it on the Wallet tab.
To spend your coins, you can choose one of the two ways here. It is recommended to use MakeTx page that allows you to assemble a transaction using a convenient, interactive way.

MakeTx tab: Use Coin Control | Wallet tab: download balance.zip
After you fill in all the transaction details, it will give you `payment.zip` with the exact command that you shall execute at the wallet machine. Note: MakeTx tab is currently the only way to spend coins from multisig addresses. | Use Wallet page of WebUI to download `balance.zip` file. Extract the zip file to get the `balance` folder.

## 2. Sign your transaction

As mentioned before, to spend your money you need to move the most recent `balance/` folder, from the client node to the PC with your wallet. Now, on the wallet PC, when you execute `wallet` without any parameters (in the same folder where the `balnace/` is placed), it should show you how much BTC you are able to spend, from the current balance.
To spend your coins, order the wallet to make and sign a new transaction, using a command like:
`wallet -send 1JbdKe4eBwtexisGTbCKY5v5CfphtdZXJs=0.01`
Please note no spaces between the address, the equal sign and the value. The value represents the amount in BTC, which you request to send to the given address.
There are also other switches which you may find useful at this stage. One of them (`-fee`) allows you to control the transaction's' fee. To see all the wallet's options, just run `wallet -h`

## 3. Verify signed transaction

If everything goes well with the wallet's' `-send ...` command, it will create a text file with a signed transaction. The file is named like `01234567.txt` - this is the file you need to move to your online node in order to notify the network about your payment. Before you broadcast your signed transaction to the network, verify carefully that it does exactly what you intended. You can do it in a several ways. In any case, first move the signed transaction file to your online PC.

Wallet | TextUI (requires client) | WebUI (requires client)

To see a decoded content of a transaction, execute: `wallet -d rawtxdata.txt`

Use the node's TextUI to execute `tx 01234567.txt` (where `01234567.txt` is the path to your transaction file). The node will decode the transaction and display it's details (inputs, outputs, fee, TXID).

Use WebUI and it's "Upload Transaction File" form. After you load the transaction, its details will be shown in your browser, for your verification.
Alternatively, you can click the Load TX link at the top of the page and paste a hex-dump of the signed transaction into the dialog that will pop up.

Note: always verify transaction before broadcasting it!
Verify that the decoded content of a transaction matches exactly what you intended to spend. If what you see would not be what you wanted, do not broadcast the transaction, but destroy the transaction file immediately.
If you follow this simple rule, your money will be safe, even in case if there was a critical bug in the wallet application that would otherwise destroy your coins (which we hope there isn't). Additionally this step allows you to double check that you did not make any mistake making the transaction, giving you the last chance to fix it.

## 4. Broadcast the transaction

After making sure that the transaction does indeed what you intended, you must broadcast it to the network, in order to actually move your coins.

WebUI (requires client) | TextUI (requires client) | Web services

Load the transaction using the client's WebUI. Click on the envelope icon with a green arrow to broadcast a loaded transaction to the network. Coming back to Transactions tab later, press the button in the "Own TXs" row, to see all the transactions you've loaded (those with a red background are yours). You can also unload a previously loaded transaction by clicking on the red X icon.

Use `stx` command with the transaction ID as its parameter (you had the ID printed, when loading it).

Use any web page that allows you to push a raw transaction to the bitcoin network.
For instance:
* https://blockchain.info/pushtx
* https://coinb.in/send-raw-transaction.html
* http://eligius.st/~wizkid057/newstats/pushtxn.php
Just copy the text from the transaction file, paste it into the form and push the button.
Note: you may want to access a web page via Tor, being concerned about exposing your IP.

Re-broadcasting transactions

The client never broadcasts transactions unrequested, so if your transaction does not appear in the chain soon enough, you may want to re-broadcast it, using the same method as for the initial broadcasting. There may of course be other reasons why your transaction does not get confirmed (usually because the fee was to low), in which case re-broadcasting it will not help you much.
There is also a TextUI command `stxa` that re-broadcasts all the transaction that have been loaded, but not yet confirmed by the network. Note that when a transaction gets mined into a block it gets removed from the list automatically.