Pages:
Author

Topic: Using BitcoinJ in .NET (C#) (Read 7065 times)

newbie
Activity: 9
Merit: 0
November 07, 2014, 08:55:40 AM
#22
Hello! I'm trying to develop a Bitcoin app for the Windows Store. I'm doing this like a hobby, so in many things I'm still new to this.
I've seen that many programs use BitcoinJ, but as the name implies, it's for Java. I've found some .NET ports, but they are from 2011, so I don't think they are that reliable.
But then I found about a program called IKVM, which can convert a Java library to a .NET one.

As this is a very delicate subject (an app that handles money), I would like to ask you: Is it OK if I follow this approach? Or maybe I should manually port it to .NET? (which will take me a long time since I'm still in university)

What are your opinions?


Thanks for sharing this nice and informative post...
hero member
Activity: 714
Merit: 662
August 08, 2014, 06:46:41 PM
#21
Although I could successfully create a console app, when I tried to import the references to the Windows Store app, it gave me compile errors because some references could not be resolved. This means that, since Windows Store has a limited .NET API, it can't use some of the features this library is using (at least the way IKVM generated it).

Either I find a way to generate a Windows Store compatible library, or I'm afraid I'll have to manually port the library.

I stopped developing for Windows Store because so many important methods are missing from the Windows Store version of .NET. System.Security.Cryptography, which was required for my app is a good example.

I think there may be alternative methods, but they made it very hard to port programs by not using the same ones.  Hmm, I wonder why there are no good Windows Store apps?  Roll Eyes

Razick, porting NBitcoin to Portable library is not complicated and definitively feasable thanks to the unit tests.
I say that because I did it for a customer of mine, it took approximately 7H.

To do that, you need to fetch the sources of BouncyCastle, and strip every thing that does not compile in portable.
Then, do the same with NBitcoin, strip every class you don't need.
Then, do the same with NBitcoin.Tests, so you can be sure you did not broke anything by porting or stripping too much. Run tests with Core and UnitTests traits.

For my customer, NBitcoin works on xamarin (IOS, Android, Windows Phone). I wanted to make it open source directly, but he pays the bill, so he got a private copy of this work. I might release the code in open source when the project is finished if he agrees.
If not, I will redo the port from scratch.

Some goodies : NBitcoin signature verification and generation, and all crypto ECC operations are manifold more performant thanks to the most recent version of BouncyCastle Smiley
All security stuff is implemented in BouncyCastle so no dependance on System.Security.Crypto.

One problematic thing is the Random generation, RandomUtils will not compile because generating a random number with enough entropy is plateform specific. Luckily, for the sig creation I implement determinitstic RFC. (http://tools.ietf.org/html/rfc6979)
legendary
Activity: 1330
Merit: 1003
August 08, 2014, 05:55:46 PM
#20
Although I could successfully create a console app, when I tried to import the references to the Windows Store app, it gave me compile errors because some references could not be resolved. This means that, since Windows Store has a limited .NET API, it can't use some of the features this library is using (at least the way IKVM generated it).

Either I find a way to generate a Windows Store compatible library, or I'm afraid I'll have to manually port the library.

I stopped developing for Windows Store because so many important methods are missing from the Windows Store version of .NET. System.Security.Cryptography, which was required for my app is a good example.

I think there may be alternative methods, but they made it very hard to port programs by not using the same ones.  Hmm, I wonder why there are no good Windows Store apps?  Roll Eyes
hero member
Activity: 658
Merit: 500
May 28, 2014, 10:40:49 AM
#19
But you can manually connect to the network and send the messages to support it yourself. (Partial Merkle Tree are implemented, and bloom filter also)
OK, I will consider it Smiley
hero member
Activity: 714
Merit: 662
May 28, 2014, 09:22:07 AM
#18
Alternatively, you can try https://github.com/NicolasDorier/NBitcoin
Support more feature than BitcoinJ, except for the payment (BIP70) that I'm developping right now.
You can sign and send transactions.

I wrote two small article on it.
http://www.codeproject.com/Articles/768412/NBitcoin-The-most-complete-Bitcoin-port-Part-Crypt
http://www.codeproject.com/Articles/775226/NBitcoin-Cryptography-Part
Does it support SPV mode? I was thinking on a Windows Phone app, and I don't think it could (or should) run a full node.

Sadly, not for now ;(
But you can manually connect to the network and send the messages to support it yourself. (Partial Merkle Tree are implemented, and bloom filter also)
hero member
Activity: 658
Merit: 500
May 28, 2014, 08:28:55 AM
#17
Alternatively, you can try https://github.com/NicolasDorier/NBitcoin
Support more feature than BitcoinJ, except for the payment (BIP70) that I'm developping right now.
You can sign and send transactions.

I wrote two small article on it.
http://www.codeproject.com/Articles/768412/NBitcoin-The-most-complete-Bitcoin-port-Part-Crypt
http://www.codeproject.com/Articles/775226/NBitcoin-Cryptography-Part
Does it support SPV mode? I was thinking on a Windows Phone app, and I don't think it could (or should) run a full node.
hero member
Activity: 714
Merit: 662
May 27, 2014, 02:09:05 PM
#16
Alternatively, you can try https://github.com/NicolasDorier/NBitcoin
Support more feature than BitcoinJ, except for the payment (BIP70) that I'm developping right now.
You can sign and send transactions.

I wrote two small article on it.
http://www.codeproject.com/Articles/768412/NBitcoin-The-most-complete-Bitcoin-port-Part-Crypt
http://www.codeproject.com/Articles/775226/NBitcoin-Cryptography-Part
newbie
Activity: 1
Merit: 0
March 08, 2014, 07:54:09 PM
#15
I can confirm that IKVM works, just compile the bundled jar using ikvmc (ikvm-7.2.4630.5), like so:

ikvmc -target:library bitcoinj-0.11-bundled.jar slf4j-nop-1.7.6.jar

this results in a .net library bitcoinj-0.11-bundled.dll

I had to include slf4j-nop-1.7.6.jar to prevent getting the following warning when running a simple WalletAppKit console app:

Code:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

during the compile IKVMC also warns about some missing org.apache.lucene classes, but the assembly still works.
member
Activity: 689
Merit: 14
World's First Crowd Owned Cryptocurrency Exchange
March 04, 2014, 03:20:30 AM
#14
Good tutorials on specialized sites always help a lot in such matters
sr. member
Activity: 449
Merit: 250
February 10, 2014, 06:59:07 AM
#13
Is there a BitcoinJ .NET API that can sign and send a raw transaction?


hero member
Activity: 658
Merit: 500
December 20, 2013, 12:05:34 PM
#12
Just remember: it only works on desktop applications (WPF, etc.), but not Windows Store applications.
newbie
Activity: 7
Merit: 0
December 15, 2013, 02:43:29 PM
#11
sweet.  Because the bitnetclient for .net that was written is great as far as it goes, but it doesn't seem to support signrawtransaction or sendrawtransaction.  I'll be back when I get this far.  Thanks a ton
legendary
Activity: 1526
Merit: 1134
December 15, 2013, 12:49:16 PM
#10
Sure
newbie
Activity: 7
Merit: 0
December 15, 2013, 10:19:33 AM
#9
This seems a great place to ask this question.

I need to build a windows app that can do just a few specific things:

1) create a local wallet with one or more addresses
2) display the public key of those addresses to the user
3) accept a cut-and-paste raw transaction, decode it, and show the user what the transaction does
4) Allow user to sign and send transaction to miners

If the IKVM .dll conversion works as expected, will this be pretty straightforward?
legendary
Activity: 1526
Merit: 1134
November 11, 2013, 06:39:43 AM
#8
OK. Like I said, if you point out which API's are not available, perhaps we can come up with workarounds.
hero member
Activity: 658
Merit: 500
November 11, 2013, 12:05:00 AM
#7
Or not distribute via the Windows Store?
I'm developing a Windows Store app. It needs to be distributed via the Windows Store.

Which API's were missing? Perhaps I will understand what it's trying to do that's forbidden. BitcoinJ doesn't use much in the way of the Java API, so I suspect Windows Store places restrictions on file IO or something like that.

The Windows Store API is somewhat restricted because it's more related to tablet and smartphone development than it is to the desktop, so for things such as file access, geolocation, etc., the app has to ask the user explicit permission to use it. Also, things like opening executables are forbidden for security reasons (although I know that is no problem for this app; it's just interesting to point out).

Thanks anyway for your help, and for writing this library Smiley
When I have something ready to test, I will show it here.

Just for the record, IKVM works fine when creating desktop apps in .NET. It's only when developing Windows Store apps when issues appear.
legendary
Activity: 1526
Merit: 1134
November 10, 2013, 09:26:27 AM
#6
Or not distribute via the Windows Store? It seems odd that the API would be missing chunks for store vs non-store apps.

Which API's were missing? Perhaps I will understand what it's trying to do that's forbidden. BitcoinJ doesn't use much in the way of the Java API, so I suspect Windows Store places restrictions on file IO or something like that.
hero member
Activity: 658
Merit: 500
November 08, 2013, 09:38:23 AM
#5
Although I could successfully create a console app, when I tried to import the references to the Windows Store app, it gave me compile errors because some references could not be resolved. This means that, since Windows Store has a limited .NET API, it can't use some of the features this library is using (at least the way IKVM generated it).

Either I find a way to generate a Windows Store compatible library, or I'm afraid I'll have to manually port the library.
legendary
Activity: 1526
Merit: 1134
November 06, 2013, 06:47:53 AM
#4
If you find ways we can adjust the library to make it more pleasant to use from C#, please do let us know.

Also, if you could write up a short guide once you're done, I'd love to include it on the website.
hero member
Activity: 658
Merit: 500
November 05, 2013, 09:43:46 PM
#3
Thanks  Grin. I'm already following the tutorials from the website, and everything seems to work well (except some Java-specific things such as the Listeners, but I'm sorting them out). If anything goes wrong, I'll let you know.
Pages:
Jump to: