Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open local bitcoin database

I am trying to extract data from local bitcoin database. As I know, bitcoin-qt is using BerkeleyDB. I have installed berkley db from Oracle web site, and found here dll for .NET: libdb_dotnet60.dll. I am trying to open any file, but I get DatabaseException. Here is my code:

using BerkeleyDB;
class Program
{
    static void Main(string[] args)
    {
        var btreeConfig = new BTreeDatabaseConfig();
        var btreeDb = BTreeDatabase.Open(@"c:\Users\<user>\AppData\Roaming\Bitcoin\blocks\blk00000.dat", btreeConfig);
    }
}

Does anyone has examples how to work with bitcoin database (on any other language)?

like image 781
Zergatul Avatar asked Dec 07 '13 14:12

Zergatul


2 Answers

What are you trying to extract? Only the wallet.dat file is Berkeley database.

Blocks are stored one after the other in the blkxxxxx.dat files with four bytes representing a network identifier and four bytes giving the block size, before each block.

An index for unspent outputs in stored as a leveldb database.

Knowing what type of information you are looking for would help.

like image 60
Matthew Mitchell Avatar answered Oct 14 '22 17:10

Matthew Mitchell


In .NET you could use something like BitcoinBlockchain that is available as a NuGet package at https://www.nuget.org/packages/BitcoinBlockchain/. Its usage is trivial. If you want o see how it is implemented the sources are available on GitHub.

If you want to store the blockchain in a SQL database that you could query faster and in more ways that the raw blockchain you could use something like the BitcoinDatabaseGenerator tool available at https://github.com/ladimolnar/BitcoinDatabaseGenerator.

like image 21
Ladi Avatar answered Oct 14 '22 18:10

Ladi