I'd like to be able to add, remove, export etc. keypairs from my wallet.dat file. Looking over the source code of pywallet it doesn't look like such a tough task, but of course it's not as simple as from bsddb.db import * in C# and Google is failing me. Does anyone have some sample code or resources for how to handle wallet.dat in C#?

3 Answers 3


Wallet.dat is a Berkeley DB file. You could check out Berkeley DB for .NET to see if it is able to read the file.

  • For some reason I can't build this. I get a ton of these type of error: Error 1 Inconsistent accessibility: parameter type 'out BerkeleyDb.DB_SEQUENCE_STAT*' is less accessible than delegate 'BerkeleyDb.DB_SEQUENCE.StatFcn' C:\Users\enmaku\Documents\Visual Studio 2010\Projects\libdb-dotnet\src\DB_SEQUENCE.cs 146 30 libdb_dotNET45 Sep 10, 2011 at 19:17
  • VS2010 Win7 x64 if it matters. Sep 10, 2011 at 19:19
  • There are precompiled binaries in the Files section of the sourceforge project you could try.
    – Erv Walter
    Sep 11, 2011 at 14:19
  • The precompiled binaries worked well enough. If I figure it out 100% I'll start a github repo and link to it here. Sep 16, 2011 at 4:29

In addition to what Erv mentioned, the next version of the wallet may be using LevelDB for the block chain and some custom format for the private key store.

Here is more information on the LevelDB access from C# but I hope someone updates this post with a link to the best LevelDB for C# for our purposes


Take a look at BitcoinSharp, a port of bitcoinj.

  • I hadn't considered that BitcoinSharp, being a direct port of Bitcoin to C# would, by necessity, contain the necessary code to handle wallet.dat (duh). I'd much rather have a small snippet of sample code than dig through the whole BitcoinSharp project, but given that Erv's link goes to unbuildable code this may be my only choice... Sep 10, 2011 at 19:18
  • And now I get The input stream is not a valid binary format opening a perfectly valid wallet.dat with Wallet.LoadFromFile - has anyone actually USED this before? Sep 10, 2011 at 20:09
  • Glancing over the code it looks like BitcoinSharp just serializes and deserializes its wallet object with a BinaryFormatter, it doesn't appear to use the Berkeley DB format that the regular Bitcoin client does, so this is unfortunately a dead end :( Sep 10, 2011 at 20:25
  • BitcoinSharp and bitcoinj use a different wallet format than using by bitcoin-core. Aug 4, 2014 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.