Bitcoin Forum
April 26, 2024, 04:32:30 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Using BitcoinJ in .NET (C#)  (Read 7021 times)
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
November 05, 2013, 03:26:57 AM
 #1

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?

An economy based on endless growth is unsustainable.
The forum strives to allow free discussion of any ideas. All policies are built around this principle. This doesn't mean you can post garbage, though: posts should actually contain ideas, and these ideas should be argued reasonably.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714149150
Hero Member
*
Offline Offline

Posts: 1714149150

View Profile Personal Message (Offline)

Ignore
1714149150
Reply with quote  #2

1714149150
Report to moderator
Mike Hearn
Moderator
Legendary
*
Offline Offline

Activity: 1526
Merit: 1128


View Profile
November 05, 2013, 10:28:07 AM
 #2

I've never used IKVM, but it's the approach I've been suggesting .NET developers try for a while.

From a language/operating system perspective bitcoinj is very simple. It doesn't do anything fancy like reflection or code synthesis. I've actually successfully transpiled it to C++ (although the result didn't run due to missing runtime stubs). It should be possible to either use IKVM and convert the Java at the bytecode level, or using the tool the Mono guys developed to do a source-to-source translation of the Android sources to C#.

It looks like IKVM is as simple as running a command line tool to convert the JAR to a DLL. What I suggest you try is creating a bundled JAR that contains everything together, and then converting it to a DLL and seeing if you can re-write the ForwardingService example in C#.

To get a bundled JAR, you can just use Maven to compile bitcoinj and then grab the tools/target/bitcoinj-tools-0.11-SNAPSHOT.jar file. That JAR contains the WalletTool app which is kind of useless, but more importantly it's been processed with the "maven shade" plugin that bundles bitcoinj with all its dependencies. That's the JAR you should convert to a DLL.
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
November 06, 2013, 02:43:46 AM
 #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.

An economy based on endless growth is unsustainable.
Mike Hearn
Moderator
Legendary
*
Offline Offline

Activity: 1526
Merit: 1128


View Profile
November 06, 2013, 11: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.
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
November 08, 2013, 02:38:23 PM
 #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.

An economy based on endless growth is unsustainable.
Mike Hearn
Moderator
Legendary
*
Offline Offline

Activity: 1526
Merit: 1128


View Profile
November 10, 2013, 02:26:27 PM
 #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.
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
November 11, 2013, 05: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.

An economy based on endless growth is unsustainable.
Mike Hearn
Moderator
Legendary
*
Offline Offline

Activity: 1526
Merit: 1128


View Profile
November 11, 2013, 11: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.
luvbcs
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
December 15, 2013, 03:19:33 PM
 #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?
Mike Hearn
Moderator
Legendary
*
Offline Offline

Activity: 1526
Merit: 1128


View Profile
December 15, 2013, 05:49:16 PM
 #10

Sure
luvbcs
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
December 15, 2013, 07: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
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
December 20, 2013, 05:05:34 PM
 #12

Just remember: it only works on desktop applications (WPF, etc.), but not Windows Store applications.

An economy based on endless growth is unsustainable.
Bitoy
Sr. Member
****
Offline Offline

Activity: 449
Merit: 250


View Profile
February 10, 2014, 11:59:07 AM
 #13

Is there a BitcoinJ .NET API that can sign and send a raw transaction?


JPSelzer
Member
**
Offline Offline

Activity: 689
Merit: 14

World's First Crowd Owned Cryptocurrency Exchange


View Profile
March 04, 2014, 08:20:30 AM
 #14

Good tutorials on specialized sites always help a lot in such matters

marsattacks
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
March 09, 2014, 12:54:09 AM
 #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.
Nicolas Dorier
Hero Member
*****
Offline Offline

Activity: 714
Merit: 619


View Profile
May 27, 2014, 07: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

Bitcoin address 15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
May 28, 2014, 01:28:55 PM
 #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.

An economy based on endless growth is unsustainable.
Nicolas Dorier
Hero Member
*****
Offline Offline

Activity: 714
Merit: 619


View Profile
May 28, 2014, 02:22:07 PM
 #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)

Bitcoin address 15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe
R2D221 (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 500



View Profile
May 28, 2014, 03:40:49 PM
 #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

An economy based on endless growth is unsustainable.
Razick
Legendary
*
Offline Offline

Activity: 1330
Merit: 1003


View Profile
August 08, 2014, 10: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

ACCOUNT RECOVERED 4/27/2020. Account was previously hacked sometime in 2017. Posts between 12/31/2016 and 4/27/2020 are NOT LEGITIMATE.
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!