How to Setup BTCD - Go Implementation of Bitcoin Full Node - with Address Index
Repository
https://github.com/btcsuite/btcd
What Will I Learn?
- Installing golang on Ubuntu
- Installing btcd
- Checking bitcoin address history with btcctl
Requirements
- Ubuntu VPS or local VM
- 200+GB block storage
- Unmetered internet connection
Difficulty
- Intermediate
Why BTCD
bitcoind (default Bitcoin Core full node) doesn’t support address lookup for past transactions, I’m building web applications that require bitcoin address monitoring and doing transaction notifications. Starting btcd with --addrindex gives you this feature.
I’m writing how to monitor any bitcoin address (not just your wallet) and sending transaction notifications in a separate post.
Let’s start
I don’t suggest running a bitcoin node on your laptop, but if you have 200GB+ space and unmetered internet bandwidth you can do it in a local virtual machine.
It’s better to spin up a cheap Ubuntu VPS with 200GB+ block storage, I recommend DigitalOcean or AWS. After creating your VPS, we’ll install btcd.
First, we need to install golang to our new ubuntu instance:
$ sudo apt install golang
$ echo 'export GOPATH=$HOME/go' >> ~/.bashrc
$ echo 'export PATH=${PATH}:${GOPATH}/bin' >> ~/.bashrc
$ source ~/.bashrc
Check the go version, we need at least 1.8 to use btcd.
$ go version
go version go1.10.1 linux/amd64
Now we can download btcd.
$ go get -u github.com/Masterminds/glide
$ git clone https://github.com/btcsuite/btcd $GOPATH/src/github.com/btcsuite/btcd
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ glide install$ go install . ./cmd/...
Now btcd and btcctl installed, but before starting btcd, make sure we set config options, otherwise btcd creates rpc.cert only for localhost. We’ll need rpc.cert when we start developing our applications that connects JSON-RPC service of this node.
.btcd/btcd.conf configuration file
[Application Options]
rpcuser=myuser
rpcpass=SomeDecentp4ssw0rd
rpclisten=:8334
.btcd/btcctl.conf configuration file
[Application Options]
rpcuser=myuser
rpcpass=SomeDecentp4ssw0rd
We need to use --addrindex flag to create address index while blockchain history is synchronizing.
$ cd $GOPATH/bin
$ ./btcd --addrindex
This may take 1-3 days, depending on your connection and machine specs. But you can start testing on past blockchain data while it’s synchronizing.
You may also want to use bitcoin testnet by adding --testnet flag to btcd. This way you can easily test transactions with testnet coins.
You can check btcd documentation for more info.
Let’s try that address lookup:
$ cd $GOPATH/bin
$btcctl searchrawtransactions "12ib7dApVFvg82TXKycWBNpN8kFyiAN1dr"
If you get a large JSON response, you are good to go. Now we can start developing our apps that uses searchrawtransactions method.
Feel free to ask any questions. Thank you.