Technical
This is a complete technical guide to bitcoin.
Each page contains simple text explanations and diagrams for how the different parts of bitcoin work. They also include real-world examples and tools to help you work with raw data in bitcoin.
So if you really want to know how bitcoin works under the hood, this guide is for you.
How to become a bitcoin programmer
I've included lots of code examples within this technical guide to help you with writing your own scripts.
This is because the best way to learn how to become a bitcoin developer is to actually write code.
Code examples are in these boxes
Most of the code examples are in Ruby because I think it's the easiest language to read.
If you're not using Ruby, you should be able to use the code snippets as a reference for rewriting the code in the programming language of your choice.
You can read about how bitcoin works as much as you want, but until you start coding, making mistakes (which you will), and building some useful tools, you're never going to make progress. So don't be afraid to give it a go. We've all got to start somewhere.
And if I can learn how to make stuff with bitcoin, so can you.
Anyway, there's no single "best" way to get started with working on bitcoin, but if you're completely new and have no idea where to start, this is what I would recommend…
Install Linux (optional)
This is completely optional, but I'd recommend installing Linux.
- Xubuntu – This is my Linux distribution of choice. It's just the popular Ubuntu bundled with the lightweight and functional XFCE desktop environment. It's easy to use, and is a good starting point if you're moving from Mac or Windows, because everything just works out of the box.
I really like Linux for programming work. Linux gives you complete control over your system, and it feels like a natural environment for writing your own programs and tools, because nothing is hidden away from you for your own safety or convenience.
I switched to Linux over a decade ago, and I haven't looked back since – it felt like I gained freedom over my operating system and I've never wanted to go back.
Obviously, if you're proficient with your current development environment, stick with that. But if you want to get better at programming and have felt limited in some way up until now, try using Linux instead.
Install Bitcoin Core
If you're going to be working with bitcoin, it's a good idea to install Bitcoin Core (the original bitcoin program).
There are a few benefits to running your own local bitcoin node:
- Access to raw bitcoin data. By running a full node on your local computer you can quickly and easily access raw block and transaction data without having to rely on a third-party API:
bitcoin-cli getrawtransaction <txid> bitcoin-cli getblock <hash>
- Useful command line tools. The Bitcoin Core program comes packaged with a bunch of command line tools that I regularly use for debugging and decoding. Here are a couple of useful examples:
bitcoin-cli decoderawtransaction <raw transaction data> bitcoin-cli decodescript <hex script>
- Sending raw transactions. If you're in the business of constructing your own raw transactions, you can send them in to the bitcoin network via your own local node:
bitcoin-cli sendrawtransaction <raw transaction data>
Depending on what kind of work you're doing with bitcoin, you may or may not need to run your own full Bitcoin Core node. But if you're not sure, it's good to have it there anyway.
You can list all of the available commands by running bitcoin-cli help
.
Use your favourite programming language
You can work with bitcoin in any programming language you like, so you might as well use your favourite.
You're more likely to succeed if you work with a programming language that you enjoy, rather than forcing yourself to try to code in a language that you think you "should" be using for some reason.
And if you don't know any languages yet, pick the one that you think looks cool.
Worse comes to worst, if it turns out the language you've chosen is too slow or completely inadequate for some reason, you can always rewrite your project in a different language later on. But you won't know until you try. And rewriting will be much easier the second time around, because you'll already have a library of code to work from.
So don't stress about which programming language to use. Just pick one and go for it. Some popular choices include:
- Python – Good for beginners.
- Ruby – My personal favourite language. Also good for beginners.
- Javascript – Good for web-based stuff.
- Go – Good for fast server-side programs.
- C++ – This is what the Bitcoin Core codebase is written in.
If you want to become a Bitcoin Core developer, you're going to need to learn C++.
I'm a big fan of PHP and Ruby. PHP because it's the language I'm most proficient with (it's what this website and my personal bitcoin library is coded in), and Ruby because it's enjoyable to use and easy to read (it's what most of the examples on this website are written in).
That's not to say you should use these particular languages. In fact, I'd probably get laughed out of some programming circles for using PHP and Ruby (and rightfully so). But they work well for me, and I've created some really useful tools with them, and that's all that matters.
So who's laughing now.
In short, don't get hung up on which language is "best" for bitcoin. The best language is always going to be the one that you can use to actually build stuff with.
There's going to be more help available if you stick to a fairly popular language. If you use a language that nobody else is using, you're going to find that you'll be on your own a lot when it comes to solving tricky problems.
Where to start with bitcoin programming
If I had to provide you with a specific route to take, I'd say these are the three most practical (and satisfying) milestones when learning how to program with bitcoin:
- Generating your own keys. This is the perfect place to start. Try generating your own private key, public key, and address. Then import the private key in to a wallet, and see if you get the same address as the one you generated.
- Decoding a transaction. Learning how to decode a raw transaction will teach you a lot about the structure of a bitcoin transaction, and they make up 99% of the data inside the blockchain.
Transaction Splitter - Creating your own transaction. After decoding a transaction, you're all set to create your own. This is a much bigger milestone (so take your time), but it's the natural next step. Signing it will be the tricky part, but if you can successfully send your own bitcoin transaction in to the network, then you can safely say that you're a pretty good bitcoin programmer.
Transaction Builder
And if you can create you own bitcoin transactions, there's nothing else in bitcoin that will be outside your ability.
Write command line tools
Writing command-line tools is a good way to get started with programming for bitcoin.
This is especially true if you don't have an idea for a project yet. Plus, if you're going to be spending any time working with bitcoin data, it's always going to be handy to have a bunch of command-line utilities to help you along the way.
Some basic command line tools that will prove to be very useful over the long run are:
- Hash Functions - It's handy to have a quick and easy way to get the HASH256 or HASH160 of some data, because they're used everywhere in Bitcoin.
HASH256
HASH160 - Reversing Byte Order - This one is invaluable to me. You often need to reverse the byte order of TXIDs and block hashes, because the byte order you use within raw transaction data and block data is the reverse of what you use to search for them in a blockchain explorer. Furthermore, most fields in raw bitcoin data are in "little-endian", so you'll often find yourself needing to reverse the byte order before converting numbers between hexadecimal and decimal.
Reverse Bytes - Base Converter - I can't tell you how many times I've converted something from hexadecimal to decimal (and vice versa). You can use an online tool if you want, but there's nothing quite like firing up a terminal and converting a number using a script you've written yourself.
Base Converter
But don't get bogged down by writing command line tools for the sake of it. It's a good way to get started, but your main focus on your journey to becoming a bitcoin programmer should be working on your own projects…
Your first bitcoin project (important)
The best way to learn to become a bitcoin programmer is to try and build something.
If you've got an idea for something you want to build, just go for it and learn what you need to learn as you go. You don't need to know about every aspect of bitcoin to start making something useful.
It may seem like an intimidating task at the start, especially if you're new to bitcoin and/or programming, but if you just take it one step at a time you'll get there eventually.
Because as with anything in life, it's impossible to fail if you refuse to give up.
Anyway, I'm guessing you've already got an idea of what you want to build. But if you need some inspiration, here are some popular tools that other people have built:
Web Tools
- Bitcoin Mempool Size Statistics (by Jochen Hoenicke)
- Mnemonic Code Converter (by Ian Coleman)
- Bitfeed (by mononaut)
- Yogh Explorer (by Jorn C)
Desktop Tools
- Electrum (by Thomas Voegtlin)
- Sparrow Wallet (by Craig Raw)
Command Line Tools
- bitcoin-iterate (by Rusty Russel)
- vanitygen (by samr7)
- bitcoin-utxo-dump (by Greg Walker)
This is just a handful of cool tools that I know have been made by individuals. I think they're good inspiration for what can be done with bitcoin if you have a good idea and the determination to see it through.
So just go ahead and create something useful that doesn't already exist, then make it available for other people to use, and see what happens.
Be responsible. You need to be very careful if you're creating a tool that handles private keys or creates transactions for other people (e.g. a wallet). It's one thing to make your own mistakes and lose your own coins, but it's another to make mistakes that cause other people to lose coins, so don't take it lightly.
Share your work on GitHub. This is a good way to share your code with the world, and it's also a good way to display your experience if you're looking to get a job (if that's the direction you want to go in).
Summary
Don't let anyone make you think that you can't be a bitcoin programmer.
Bitcoin is decentralized, open-source software. You can generate your own keys and construct your own transactions if you want to, and nobody can stop you. That's part of what makes bitcoin, bitcoin.
I'm sure some people will want to convince you that you need some kind of qualification to work with bitcoin, but allow me to tell you, you don't. Everything you need can be learnt for free on the Internet, or even by just looking at the bitcoin source code. The only real qualification you need to work on bitcoin is the desire to contribute, and everything else can be learnt along the way.
We've all got to start somewhere, and if you've got an idea and the passion to make it happen, then you're just as qualified to become a bitcoin programmer as anyone else.
The best wallets and tools were built by people that, at some point, had no prior experience with bitcoin.
Other Resources
Nobody learns about an entire subject from just a single book or website any more, so here are some other excellent technical resources for bitcoin that I've found useful:
Websites
- Bitcoin Developer Guide – The official guide. Quite technical, but covers a lot.
- Bitcoin Wiki – A lot of technical information that you won't find anywhere else.
- Bitcoin Stack Exchange – The best place for getting answers to questions.
- BIPs – Most proposals contain good technical information about a specific upgrade.
Books
Other
- lopp.net Resources – The famous hub for Bitcoin-related resources.
- Royal Fork Blog – Masterfully written articles explaining some aspects of Bitcoin. Some of these pages inspired this website.
- Minimum Viable Block Chain – Incredible single-page article on blockchain technology by a great technical writer.
- RaspiBolt – Guide to setting up a Bitcoin node on a Raspberry Pi. Worth doing at least once for the experience.
Libraries
A smart way to learn how bitcoin works is to learn from existing bitcoin libraries written in the language you're using yourself.
You can find a bitcoin library in pretty much any programming language by searching for "[language] bitcoin library". For example:
- Go: btcd (highly recommended; excellent code comments)
- PHP: bitcoin-php
- Ruby: bitcoin-ruby
- Javascript: bcoin
There's a wealth of open-source code out there, and sometimes it's best to see how someone else has solved a problem to help you figure out how to do it yourself.
Good luck.