If you have not read part 1 of this tutorial, see https://talkera.org/wpTalkera/linux-shell-commands-for-bitcoin/ I had a lot of replies and decided to write a follow up;
Are you a sysadmin, software developer, linux guru? Have you ever dreamt to build the worlds biggest bitcoin exchange? Do you want to create an online marketplace? This article will help you to get started with your exciting new bitcoin project!
Let us take some of the latest bitcoin software tools:
- zbar-tools
- pybitcointools
- python-trezor
- python-mnemonic
- bitcoin-bash tools
zbar-tools
ZBar is an open source software suite for reading bar codes from various sources. QR codes are very popular amongst the bitcoin community. You can either compile zbar from source (bzip2 -d zbar.tar.bz2; tar xvf zbar.tar; ./configure; make) or right from the repository:
$ sudo apt-get install zbar-tools
Once installed we can get the text from a QR code using the command:
$ zbarimg qrcode.png
tip : try it with the image you created with qrencode in the previous tutorial
You can get the output in the XML format using:
$ zbarimg qrcode.png –xml
pybitcointools
An API that combines the power of Python and Bitcoin? This sounds very promising. We install using:
sudo pip install pybitcointools
Pybitcointools is not a full node, it has no idea what blocks are. It relies on centralized service (blockchain.info) for blockchain operations. This should not be a problem, but keep this in mind;
We write the first program, which simply fetches the account transaction history from the blockchain (through blockchain.info). Openup your favourite editor and paste:
from pybitcointools import *
addr = “1A1bBJwQMsbEbdyAnfe1ESvVAM3hmB6fSC”
h = history(addr)
print h
Save the file as example.py and execute it with
python example.py
The program will output the list of transactions for the bitcoin address 1A1bBJwQMsbEbdyAnfe1ESvVAM3hmB6fSC. Pretty neat, eh?
Now we will do some cool stuff with a brain wallet. Open https://brainwallet.github.io/ and type a passphrase to generate an address. In my case I took a very weak password “hello world”. You will see the private key and public key being generated on the fly. Use this as a reference later on; We will create a program now which can generate the public and private key directly from this password. In addition, we will create the bitcoin address from the public key.
from pybitcointools import *
priv = sha256(‘hello world’)
pub = privtopub(priv)
address = pubtoaddr(pub)print “Private key: ” + priv
print “Public key : ” + pub
print “Address : ” + address
This bitcoin address will obviously not have any transaction history. The complete list of commands can be found at: https://github.com/vbuterin/pybitcointools
python-trezor
Remember the hardware wallet Trezor we discussed? You can interact with it using python. Install using:
sudo apt-get install python-dev python-setuptools cython
git clone https://github.com/trezor/python-trezor.git
cd python-trezor
python setup.py install (or develop)
Then follow the instructions on https://github.com/trezor/python-trezor and http://www.bitcointrezor.com/
python-mnemonic
This library can be used for generating the mnenomic, and converting it into a binary seed. This seed can be later used to generate deterministic wallets using BIP-0032 or similar methods.
First install the python package pbkdf2, it is a dependency.
sudo pip install pbkdf2
Clone the python-mnemonic package using:
git clone https://github.com/trezor/python-mnemonic
You should have git installed. If not, install git. Next, enter these commands:
cd python-mnemonic/
python test_mnemonic.py
This will execute some tests, should work fine. Remove vectors.json using
rm -r vectors.json
Run the example using
generate_vectors.py
The passphrase “TREZOR” is used for all vectors. Read more on https://github.com/trezor/python-mnemonic
bitcoin-bash tools
First clone the package using the command
git clone https://github.com/grondilu/bitcoin-bash-tools
Let us do the next steps:
cd bitcoin-bash-tools/
vim test.sh
Paste this code
#!/bin/bash
source bitcoin.shnewBitcoinKey
Then save it. Run
chmod 755 test.sh
./test.sh
It will generate a secret key, public exponent and a bitcoin address. To see the complete list of commands open https://github.com/grondilu/bitcoin-bash-tools