Install, Update and Tweak BitcoinLib
Install with pip
$ pip install bitcoinlib
Package can be found at https://pypi.org/project/bitcoinlib/
Install from source
sudo apt install -y postgresql postgresql-contrib mysql-server libpq-dev libmysqlclient-dev
Create a virtual environment for instance on linux with virtualenv:
$ virtualenv -p python3 venv/bitcoinlib $ source venv/bitcoinlib/bin/activate
Then clone the repository and install dependencies:
$ git clone https://github.com/1200wd/bitcoinlib.git $ cd bitcoinlib $ pip install -r requirements-dev.txt
Required Python Packages, are automatically installed upon installing bitcoinlib:
fastecdsa (or ecdsa on Windows)
If you want to use BIP38 encrypted private keys, it is strongly advised to install the much faster scrypt library.
pip install scrypt
Other requirements Linux
On Debian, Ubuntu or their derivatives:
sudo apt install build-essential python3-dev libgmp3-dev
On Fedora, CentOS or RHEL:
sudo dnf install python3-devel gmp-devel
To install OpenSSL development package on Debian, Ubuntu or their derivatives
sudo apt install libssl-dev
To install OpenSSL development package on Fedora, CentOS or RHEL
sudo yum install gcc openssl-devel
Install database packages for MySQL and PostgreSQL
sudo apt install mysql-server postgresql postgresql-contrib libmysqlclient-dev
Check for the latest version of the PostgreSQL dev server:
sudo apt install postgresql-server-dev-<version>
From library root directory install the Python requirements
pip install -r requirements-dev.txt
Then run the unittests to see if everything works
python setup.py test
Other requirements Windows
This library requires a Microsoft Visual C++ Compiler. For python version 3.5+ you will need Visual C++ 14.0. Install Microsoft Visual Studio and include the “Microsoft Visual C++ Build Tools” which can be downloaded from https://visualstudio.microsoft.com/downloads. Also see https://wiki.python.org/moin/WindowsCompilers
The fastecdsa library is not enabled at this moment in the windows install, the slower ecdsa library is installed. Installation of fastecdsa on Windows is possible but not easy, read https://github.com/AntonKueltz/fastecdsa/issues/11 for steps you could take to install this library.
If you have problems with installing this library on Windows you could try to use the pycryptodome library instead of scrypt. The pycryptodome library is pure Python so it doesn’t need any C compilers installed. But this will run slower.
Before you update make sure to backup your database! Also backup your settings files in ./bitcoinlib/config if you have made any changes.
If you installed the library with pip upgrade with
$ pip install bitcoinlib --upgrade
Otherwise pull the git repository.
After an update it might be necessary to update the config files. The config files will be overwritten with new versions if you delete the .bitcoinlib/install.log file.
$ rm .bitcoinlib/install.log
If the new release contains database updates you have to migrate the database with the updatedb.py command. This program extracts keys and some wallet information from the old database and then creates a new database. The updatedb.py command is just a helper tool and not guaranteed to work, it might fail if there are a lot of database changes. So backup database / private keys first and use at your own risk!
$ python updatedb.py Wallet and Key data will be copied to new database. Transaction data will NOT be copied Updating database file: /home/guest/.bitcoinlib/database/bitcoinlib.sqlite Old database will be backed up to /home/guest/.bitcoinlib/database/bitcoinlib.sqlite.backup-20180711-01:46 Type 'y' or 'Y' to continue or any other key to cancel: y
When you experience issues with the scrypt package when installing you can try to solve this by installing scrypt separately:
$ pip uninstall scrypt $ pip install scrypt
Please make sure you also have the Python development and SSL development packages installed, see ‘Other requirements’ above.
You can also use pycryptodome or pyscrypt instead of scrypt. Pycryptodome is a pure Python scrypt password-based key derivation library. It works but it is slow when using BIP38 password protected keys.
If you run into issues do not hesitate to contact us or file an issue at https://github.com/1200wd/bitcoinlib/issues
Using library in other software
If you use the library in other software and want to change file locations and other settings you can specify a location for a config file in the BCL_CONFIG_FILE:
os.environ['BCL_CONFIG_FILE'] = '/var/www/blocksmurfer/bitcoinlib.ini'
You can Add another service Provider to this library by updating settings and write a new service provider class.
If you use this library in a production environment it is advised to run your own Bcoin, Bitcoin, Litecoin or Dash node, both for privacy and reliability reasons. More setup information: Setup connection to bitcoin node
Some service providers require an API key to function or allow additional requests. You can add this key to the provider settings file in .bitcoinlib/providers.json