Linux shell commands for Bitcoin part II

Standard

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.sh

newBitcoinKey

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

 

Uncategorized

Linux shell commands for Bitcoin

Standard

This article is intended for sysadmins interested in bitcoin  and advanced linux users. By chaining all these commands together in different ways, you can do maintain a wallet, work with deterministic keys, generate QR codes and so on. This tutorial was created for Debian Linux and Ubuntu Linux, but other platforms should work too. A list of bitcoin command line utillities:

  • bitcoin native (very good, but wont be discussed here)
  • qrencode
  • sx

qrencode
The qrencode application is a tool to quickly produce qrcodes. Generating a QR code, a type of matrix barcode, for a bitcoin address from the command line :

$ sudo apt-get install qrencode
$ qrencode 125tQCeg89h8d3ccgBsipbjGUJpqx4c3H1 -o qrcode.png
$ display qrcode.png   (optional, display it)

This will output a QR code image of 111×111 pixels.  You can change the size of the dots, thus making the image larger using the -s command.

$ qrencode 125tQCeg89h8d3ccgBsipbjGUJpqx4c3H1 -s 6 -o qrcode.png
$ display qrencode.png

sx tools
sx is a set of modular Bitcoin commandline utilities. First clone libbitcoin from https://github.com/libbitcoin/libbitcoin#debianubuntu  and run

cd libbitcoin-version2
sudo install.sh

Installing command line tool sx :

wget https://github.com/spesmilo/sx/raw/master/install-sx.sh
sudo apt-get install bignum
sudo apt-get install sudo apt-get install libgmp-dev
chmod 755 install-sx.sh
sudo bash ./install-sx.sh

Installation will take a while, expect around 30 minutes installation time. It will download a lot of packages and compile them from source. This should work on latest versions of Debian Linux or Ubuntu Linux.

If that did not work try to download the packages into your /Downloads/ directory.

  • libbitcoin 2.0
  • libwallet 0.4
  • Obelisk 1.0

Open a console and for each of the packages type

$ bzip2 -d filename.tar.bz2
$ tar xvf filename.tar
$ cd filename
$ autoreconf -i
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig

( You might need sudo apt-get -f install libzmq-dev  and sudo apt-get install libcrypto* )

Finally download sx from  here:

  • sx 1.0

Run the commands:

sh ./install-sx.sh

If you get an error about leveldb_blockchain, this error to be exact:

initchain.cpp:19:5: error: ‘leveldb_blockchain’ was not declared in this scope
leveldb_blockchain chain(pool);

Then add the line

#include

to the file src/initchain.cpp using your favourite editor such as vim.   . Then run make, sudo make install.

Now that you have sx tools installed you can use it to run all kind of bitcoin related commands.
Converting BTC to satoshi, and satoshi to BTC

$ sx btc 90000
0.00090000
$ sx satoshi 0.00090000
90000

Create an experimental wallet

sx newseed > wallet.seed
cat wallet.seed
sx wallet wallet.seed

 Convert from hexadecimal to base58

sx base58-encode CAFEBABE

See http://sx.dyne.org/  for a full list.

Uncategorized