Jan 09

I’m often asked how bloggers and other online content producers can begin accepting bitcoins on their website, so I thought I’d quickly put together an article to save others the trouble.

Why accept bitcoins?

The first question is why should a blogger want to use bitcoins in the first place? Well, most bloggers want to have their efforts rewarded in some way, and most resort to providing context sensitive advertising. The income from this kind of offering can be very low, especially if the blog is in a niche that does not get well served by ads. There is also a sense of being disconnected from one’s audience, which works both ways. When I appreciate someone”s work I want to donate directly to them and I don’t want some advertiser or payment processor taking a cut.

Bitcoin solves this problem, quickly and efficiently.

Getting started

The quickest way is to offer a “Bitcoin swatch” (see the MultiBit FAQ for more information) as an image link with a Bitcoin URI and a suggested donation. For example, my blog has one over there on the right using the following HTML:

<div>
<a href="bitcoin:1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH?amount=0.5&label=Agile Stack">
<img src="http://gary-rowe.com/agilestack/wp-content/uploads/2011/10/AgileStack-0.5BTC.jpg" ></a>
<p>1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH</p>
</div>

The Bitcoin swatch image was dragged out of the MultiBit “Receive Bitcoins” screen onto the desktop and then uploaded using the standard WordPress image import process. MultiBit is a free and open source Bitcoin client.

You’ll notice that the “href” attribute uses a different protocol than the usual “http”. If someone has installed a Bitcoin client onto their system then it will very likely be configured as a handler for that protocol. Clicking on that link will cause the appropriate application (or browser plugin) to pop up, usually in the “Send bitcoins” screen with the details provided already filled in. MultiBit does this from version 0.3 onwards.

It doesn’t matter which browser is being used because it is the operating system that manages protocol handlers. Developers interested in getting this kind of functionality to work in their own systems may want to look at this Stack Exchange answer.

The QR component of the Bitcoin swatch allows people with smartphones to make donations using a Bitcoin wallet, or to use drag and drop payment. You’ll notice that I’ve also left the raw address visible. This is to allow people who do not have a suitable Bitcoin client to be able to copy paste the address into their respective client as a last resort.

Adding a donation counter (optional)

Finally, if you’re accepting donations rather than selling a product, it might be useful to provide a “donated so far” label to give people an indication of your ongoing campaign. The Block Explorer site provides a wealth of useful information about Bitcoin addresses, and coupled with a Text-to-Image web service can give a nice result without any server-side processing.

For example, the following snippet (inspired by the Bitcoin Trader blog and offered up by Jim Burton) provides the amount sent to a given address.

<img src="http://ansrv.com/png?s=http://blockexplorer.com/q/getreceivedbyaddress/1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH&amp;c=000000&amp;b=FFFFFF&amp;size=5" />

as shown here:

BTCs donated so far

Why not see it change value by sending it a bitcoin? ;-)

By cycling your public addresses you can reset the amount as required and provide a label indicating the time span.

Known problems

It does appear that if you are using WordPress.com to host your blog, then it may not allow you to use to bitcoin: protocol and will change it to http: or omit the link altogether. If you encounter this problem then contact the WordPress.com staff and they may be able to help you. If you host your own version of WordPress, or run your blog on Blogger.com, then this is not an issue.

Final word

So, if your blog offers content that is of real value to others then they can now show their appreciation by donating a small amount (less than a dollar) very easily. No fees. No registration. No hassle. Just you and them.

To all those who have donated to my blog – I thank you, personally.

Share
Tagged with:
Dec 28

Background

A little while ago I discovered Bitcoin. Put simply, it allows people to send any amount of money, anywhere in the world in about ten minutes without incurring an excessive transaction fee. It’s based on a very effective use of digital signatures and a public ledger of transactions to avoid double spending. In short, it is money, reinvented. If you want to send someone less than a dollar on the other side of the world, you can do it with Bitcoin.

There are many Bitcoin clients out there (I contribute development effort to the MultiBit project) and some have taken advantage of the Android platform. In particular there is Andreas Schildbach’s Bitcoin Wallet (an outstanding mobile solution with many ongoing developments) and Brian Armstrong’s Bitcoin Android (an early client that has seen a reduction in recent commits). I’ve used Andreas’ code for some time now as my primary mobile wallet and had an excellent experience.

And then my smartphone died as a result of faulty networking hardware.

Well, not a proper death, just enough to cause all the non-factory applications to stop working and to put my bitcoins (small “b” for the unit of currency with the Bitcoin protocol) at risk. Bitcoin requires you to keep your private keys safe since they provide access to your bitcoins in the public ledger (called the blockchain). Lose those private keys and you lose your bitcoins. Forever.

What follows is a guide that shows what I had to do to get my bitcoins back. If you find yourself in the same situation, perhaps this will help you. It does assume that you’re very technically proficient. If the idea of installing the Android SDK and using a shell to run up adb fills you with horror, stop now.

What you have to do

1) Do not attempt to re-install your Bitcoin wallet application – it will very likely delete your local wallet file and that’s the end of your keys.

2) You absolutely have to root your phone. Mine is (at the time of writing) a HTC Desire, so I used unrevoked3 (see http://unrevoked.com/). This should not delete any data from your system, but will enable you to access otherwise protected files.

3) Install the Android SDK and get the “platform tools” variant for your platform so that you get the adb application.

4) Hook up your phone with a USB cable (you’d probably have left it in after rooting it)

5) Fire up a terminal session and enter the following command (I’m using “>”, “$” and “#” to represent where you are in the shells, don’t actually type them)

> cd <wherever you've installed Android SDK>
> adb shell
$

In the adb shell switch to become root

$ su
#

If you get a # then you’re root. If not, try again with the unrevoked3.

6) Navigate to the wallet file directory

For the Andreas Schildbach Bitcoin Wallet do this

# cd /data/data/de.schildbach.wallet/files

Copy the all-important private key file somewhere that adb can get to it

# cat key-backup-base58 > /data/local

You’ll notice that “cp” and “mv” are not options for adb against a production build of Android. Hence the sneaky use of “cat”. And, yes, I did try mounting the partition as read-write and totally failed to get it to work.

For the Brian Armstrong Android Wallet do this

# cd /data/data/com.bitcoinwallet/files

Copy the all-important private key file somewhere that adb can get to it

# cat prodnet.wallet > /data/local/prodnet.wallet

7) Exit out of the shells (root then adb)

# exit
$ exit

8) Pull the private key files off the device and somewhere local

> adb pull /data/local/key-backup-base58
> cat key-backup-base58

The Schildbach key is stored as a simple base58 format that looks a bit like this:

5dsflkjsflklnsdaflsmdflmsortofthing

The Armstrong key is more complex, it is stored as a serialized ECKey. To get the private key out of it I had to use the BitCoinJ library (version 0.2) and make use of the DumpWallet.java file.  Poking around with an IDE and debugger lead me to the private key that looked a bit like this:

42a34b31e9a4eedf56980ee0fc32fe6e675ff7007651ff3sortofthing

So now you have to get this private key back into a safe place.

9) Use Mt Gox to import the key

By far the fastest way is to just register an account with Mt Gox (a major Bitcoin exchange) and use their very flexible private key import facility. Just select “Private key” as a deposit method and copy-paste the contents of your key. The Mt Gox exchange can recognise a wide variety of formats and if it recognises your input then it’ll immediately give you a balance associated with that key. A short while later your Mt Gox account will be credited with the bitcoins and you can do with them as you wish.

10) Finally do a clean up to make sure you don’t leave the private key lying around for anyone to grab easily

> adb shell
$ su
# cd /data/local
# rm key-backup-base58
# rm prodnet.wallet
# rm prodnet.keychain
# exit
$ exit
> exit

And you’re done.

This shows what must be done to recover your private keys and is correct at the time of writing. However, you should be aware that soon all private keys will be encrypted so that in addition to the above steps, you will also need to know the passphrase to gain access to the private key.

Share
Tagged with:

You should follow me on TwitterYou should follow me on Twiiter here.

preload preload preload