<p>In addition to what Erv mentioned, the <a href="https://bitcoin.stackexchange.com/q/4809/1878">next version of the wallet</a> may be using LevelDB for the block chain and some custom format for the private key store.</p>

<p>Here is more information on the <a href="https://stackoverflow.com/questions/9292648/is-there-a-good-port-of-leveldb-for-c">LevelDB access from C#</a> but I hope someone updates this post with a link to the best LevelDB for C# for our purposes</p>

CC BY-SA 3.0
2012-09-23T22:54:50.293Z
2012-09-23T22:54:50.293Z
2017-05-23T12:34:59.703Z
makerofthings7
<p>Take a look at <a href="http://code.google.com/p/bitcoinsharp/" rel="nofollow">BitcoinSharp</a>, a port of <a href="http://code.google.com/p/bitcoinj/" rel="nofollow">bitcoinj</a>.</p>

CC BY-SA 3.0
2014-08-04T15:58:59.997Z
BitcoinSharp and bitcoinj use a different wallet format than using by bitcoin-core.
DeathAndTaxes
CC BY-SA 3.0
2011-09-10T19:18:46.473Z
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...
David Perry
CC BY-SA 3.0
2011-09-10T20:09:13.947Z
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?
David Perry
CC BY-SA 3.0
2011-09-10T20:25:44.680Z
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 :(
David Perry
CC BY-SA 3.0
2011-09-10T05:21:04.743Z
2011-09-10T05:21:04.743Z
ripper234
<p>Wallet.dat is a Berkeley DB file.  You could check out <a href="http://sourceforge.net/projects/libdb-dotnet/" rel="nofollow">Berkeley DB for .NET</a> to see if it is able to read the file.</p>

CC BY-SA 3.0
2011-09-10T19:17:20.197Z
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`
David Perry
CC BY-SA 3.0
2011-09-10T19:19:08.033Z
VS2010 Win7 x64 if it matters.
David Perry
CC BY-SA 3.0
2011-09-11T14:19:47.967Z
There are precompiled binaries in the Files section of the sourceforge project you could try.
Erv Walter
CC BY-SA 3.0
2011-09-16T04:29:36.230Z
The precompiled binaries worked well enough. If I figure it out 100% I'll start a github repo and link to it here.
David Perry
CC BY-SA 3.0
2011-09-10T14:13:01.687Z
2011-09-10T14:13:01.687Z
Erv Walter
<p>I'd like to be able to add, remove, export etc. keypairs from my wallet.dat file. Looking over the source code of <a href="https://github.com/joric/pywallet">pywallet</a> it doesn't look like such a tough task, but of course it's not as simple as <code>from bsddb.db import *</code> in C# and Google is failing me. Does anyone have some sample code or resources for how to handle wallet.dat in C#?</p>

<wallet><development>
How do I read the contents of wallet.dat in C#
David Perry
# How do I read the contents of wallet.dat in C#

(Asked by: username_0 on 2011-09-10)

I'd like to be able to add, remove, export etc. keypairs from my wallet.dat file. Looking over the source code of [pywallet](https://github.com/joric/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#?

**Tags:** wallet, development


---

## 3 answers

### Answer by username_4 on 2011-09-10. Score: 4 | Accepted answer

Wallet.dat is a Berkeley DB file. You could check out [Berkeley DB for .NET](http://sourceforge.net/projects/libdb-dotnet/) to see if it is able to read the file.

> **Comments:**
> **username_0**: 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`  
> **username_0**: VS2010 Win7 x64 if it matters.  
> **username_4**: There are precompiled binaries in the Files section of the sourceforge project you could try.  
> **username_0**: The precompiled binaries worked well enough. If I figure it out 100% I'll start a github repo and link to it here.  

---

### Answer by username_1 on 2012-09-23. Score: 1

In addition to what Erv mentioned, the [next version of the wallet](https://bitcoin.stackexchange.com/q/4809/1878) 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#](https://stackoverflow.com/questions/9292648/is-there-a-good-port-of-leveldb-for-c) but I hope someone updates this post with a link to the best LevelDB for C# for our purposes


---

### Answer by username_2 on 2011-09-10. Score: 0

Take a look at [BitcoinSharp](http://code.google.com/p/bitcoinsharp/), a port of [bitcoinj](http://code.google.com/p/bitcoinj/).

> **Comments:**
> **username_0**: 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...  
> **username_0**: 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?  
> **username_0**: 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 :(  
> **username_3**: BitcoinSharp and bitcoinj use a different wallet format than using by bitcoin-core.  

---

