How to create a bootstrap.dat file automatically

Syncing a crypto-currency wallet can take several hours or even days.

The process of downloading the whole blockchain is slow because it requires P2P communication and validation of this data.
The result is that the client must download much more than the total size of the blockchain at a speed much lower than the actual Internet connection available.

To solve this it’s possible to use a bootstrap.dat file. The user needs to follow these steps to use it:

  1. Download the file and uncompress it.
  2. Verify signatures or checksums provided by a trusted entity. This is to prevent using a fake file.
  3. Stop the wallet if it’s running.
  4. Move the bootstrap.dat file to the wallet’s data directory. It’s usually at %appdata% on Windows (ex: %appdata%\Bitcoin) or $HOME on Linux (ex: $HOME/.Bitcoin).
  5. Open the wallet.

Quite simple! Now the problem is how to create the bootstrap.dat file and how to keep it updated. If you already have a full node running Bitcoin or any other crypto-currency here I explain how to provide an always-updated bootstrap file, automatically.

How to create a bootstrap.dat file

First, you need to write a script to create the file on your server. This script must follow the following steps:

  • Go to the data directory of the coin whose bootstrap file you want to create
  • Read all the blkXXXX.dat files and concatenate them in a single file
  • Rename the result as bootstrap.dat
  • Calculate the checksum of the file
  • Optionally compress it
  • Move it to a public location when users can download it

Here’s a sample script written in bash.

# Go to the coin’s data directory
# Replace CAPTcoin by Bitcoin or any other currency
cd ~/.CAPTcoin

# Find all the block files with the command “ls -1 blk[0-9]*.dat”
# Use the sort command to make sure they’re in order
# Use xargs to prevent an “Argument list too long” error
ls -1 blk[0-9]*.dat | sort | xargs cat > bootstrap.dat

# Create a file including the current date and the checksum of the file
echo “bootstrap.dat file, created at `date`” > bootstrap-sum.txt
echo “sha256sum: `sha256sum bootstrap.dat | awk ‘{print $1}’`” >> bootstrap-sum.txt
echo “md5sum: `md5sum bootstrap.dat | awk ‘{print $1}’`” >> bootstrap-sum.txt
echo “Verify before using it!” >> bootstrap-sum.txt

# Optionally, compress the file. You need to install zip for this
zip bootstrap.dat
# Remove the original file
rm -f bootstrap.dat

# Finally, move the resulting files to a public directory
# It’s recommended to move bootstrap-sum.txt to another server for security
mv /var/www/
sftp … bootstrap-sum.txt


You can run this periodically by creating a cronjob. For example, this will execute the script every day at 6am:

crontab -e

Add the following line:

0 6 * * * sh ~/




Categories: Crypto-currencies, Tutorials