This post is somewhat offtopic, but in the last couple of days I've been playing around with counterpartyd, the reference implementation of the counterparty protocol. It took me a while to figure everything out, so I thought I'd post a short tutorial to make it easier for anyone out there trying to do the same.
Counterparty is a protocol for a distributed, open source financial marketplace. With it, you can issue and trade assets, make broadcasts and make bets. Everything is decentralized, open source and built on top of the bitcoin blockchain. Sounds pretty good so far!
The only downside is, that in order to use the exchange, you need an altcoin, called XCP. It is used for issuing assets and making bets as well as for payouts. Although it can be exchanged for BTC directly through the counterpartyd client, that process is not exactly straightforward.
At the moment, the implementation is very much at an alpha stage. There is no GUI, so everything must be done via the terminal, and sometimes it throws not so helpful errors. But it works - Today I bought some XCP and I will explain every step in this post.
First install bitcoind and counterpartyd. This part is very well explained in the docs and I had no problems worth mentioning getting everything ready. Once everything is installed start the bitcoind server and the counterpartyd server:
$ bitcoind $ Bitcoin server starting $ counterpartyd Status: RESTART Block: 288486 Block: 288487 Block: 288488
You might have to wait until the whole blockchain is indexed by counterpartyd. As soon as the number of blocks is the same as the one given by "bitcoind getinfo | grep blocks", you are good to go. Open a second terminal window and leave the server running in the background. It'll give you useful information regarding order matches and so on later.
Next, make send the bitcoins you want to send to a new address. You can check if they have arrived using by typing "bitcoind listreceivedbyaddress". To make sure the counterpartyd client is aligned, type "counterpartyd balances <address>".
Figure out how many XCP you would like to receive for your BTC. You can check out the last price on blockscan. When I made the trade, the price was 0.01 BTC/XCP, and since I was going to spend 0.5 BTC, I'd expect to get 50 XCP. On that site you can also see the latest transactions, the current order book and so on. To place the order, type
counterpartyd order --source <address> --get-quantity 50 --get-asset XCP --give-quantity 0.5 --give-asset BTC --expiration 100 --fee-fraction-provided 0.001
The expiration is given in blocks (i.e. 100 blocks translates to roughly 16 hours). When buying BTC you need to provide a fee. I tried 0.0001 which resulted in an error, so I increased it to 0.001 and everything worked nicely.
After entering the order, you need to wait a little until it gets included in the next block (approximately 10 minutes). After that time, it should show up bith in your server window and on blockscan. There you can also click on "[View Order Matches"] to show you if it (or parts of it) have been matched. If there are matches, you will get the XCP as soon as you have paid the required BTC amount.
To do this, look in your counterpartyd server terminal windows for a line starting with "Order Match: " and compare it with the information on blockscan. It shows the amounts (both in BTC and XCP) and the transaction hash. Copy that into the clipboard.
In the other window, enter the command
btcpay --order-match-id <transaction hash>
Finally, to make sure the XCP have been credited to you, enter "counterpartyd wallet" to see the balances and the address.