3

I'm a little late to the game, but I just learned about Web Assembly and am considering using this to mine bitcoin instead of serving ads (which tend to expose a user's identity/data). I have never mined bitcoin and haven't learned Web Assembly yet, so it would be convenient to have an open source solution for this to begin my learning. Does anyone know of an open-source project for this? (Preferably written in Java or C#)

I did find this: https://github.com/altermarkive/JavaScript-Emscripten-Bitcoin-Miner/blob/master/native/miner.c But honestly, I'm not sure if it's what I need and it doesn't seem to create a web assembly, but a javascript.

ColinE
  • 68,894
  • 15
  • 164
  • 232
pcalkins
  • 1,188
  • 13
  • 20

2 Answers2

1

Contrary to what David Schwartz says, there are a significant number of people that think using WebAssembly to mine cryptocurrency on the web does make sense. A recent study found that 1 in 600 of the top 1,000,000 websites on the internet use WebAssembly. They estimated that approx. 50% of these sites were using it for cryptocurrency mining.

The paper points to CoinHive as the mining software often used for this purpose. It compiles to both WebAssembly and asm.js. However, I would strongly warn against going down this route. Hijacking a user's CPU cycles without consent is widely considered malicious.

Finally, there is anecdotal evidence that ventures of this type don't really make much money.

So - unless you've got an incredibly popular site, and you're willing to ask your users whether it's OK to mine on their hardware, I wouldn't even bother.

(and you're not going to find a Java or C# miner either, they require garbage collection so will be bloated and slow)

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • I have found some Java and C# options (nothing specifically for mining though)... they just use the syntax and compile to WebAssembly. Though the C# one seems like it might be bloated... (MS calls it "Blazor") – pcalkins Oct 30 '19 at 16:23
  • thanks for the link, btw, I'm reading it now. I don't want to use it maliciously, but as an alternative to ads, which I really don't like... for 2 reasons, 1 they're annoying.... 2 they mine user data. In a perfect world we could use the same amount of cpu power as current ads (+fingerprinting) and just use that to process transactions for a bit-currency built on web visits. This might take a whole new type of currency which would limit the amount of CPU per unique web visitor to be feasible, but oh what a great future the web would have. – pcalkins Oct 30 '19 at 20:16
  • The question was specifically about mining bitcoin and was tagged "bitcoin". Your answer is about mining monero. – David Schwartz Oct 08 '21 at 20:25
0

No, that wouldn't make any sense. Users aren't going to be browsing your web site using a bitcoin miner, they're going to be browsing using a general purpose computer. General purpose computers are so bad at mining bitcoins there's really no point in doing something like this. If you did go to all the trouble, you would likely materialize zero revenue because no machine would ever mine enough to even cover the fees associated with transferring the value of the mining to you.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • I had no idea there were fees involved in bitcoin mining. I need to do more research here. Thanks for your response. – pcalkins Oct 25 '19 at 18:46
  • I would also like it to take up less resources than displaying your typical adsense ad.... so maybe this is a pipe-dream. – pcalkins Oct 25 '19 at 19:24
  • @pcalkins 1) Transferring bitcoins takes up scarce space on a public system. You have to pay for that space. 2) If the resources it takes up are not valuable, neither will the coins mined be. – David Schwartz Oct 25 '19 at 23:47
  • "the fees associated with transferring the value of the mining to you." - what are those fees? My knowledge of crypto is very basic, but to my understanding you need to find a value that hashes to a hash. You can then divide all possible values into small ranges, which you send to clients, which will see if any of values in the range given to them produces given hash - if so, it would send the value. If you don't want to check if a client is cheating (not checking a range and just reporting a failure to find solution in the range), you only need the transfer of ranges to be worth it, right? – Markus von Broady Dec 27 '20 at 18:05
  • @MarkusvonBroady At some point, you have to pay them for the work they did though. That requires space in a block -- space you could have used for transactions that pay you fees. – David Schwartz Dec 30 '20 at 16:31
  • @DavidSchwartz As far as I understand, you don't pay the clients for the work. You use their machines as if they were your machines. Again, I know little about crypto, so maybe I'm missing something obvious here. – Markus von Broady Jan 02 '21 at 10:40
  • @MarkusvonBroady You don't pay the clients for the work, but somebody has to pay *you* for the work or you won't make any money. The party that pays you has to use up space in a bitcoin block to hold the transaction that makes the payment to you. If the value of the work is less than the cost of the payment, you will not get a payment. – David Schwartz Jan 03 '21 at 05:09
  • @DavidSchwartz is insinuating that I use a pool and why do they charge a transaction? If so, what would happen if there was no pool and I mined alone – molo32 Oct 08 '21 at 20:21
  • @molo32 If you were mining alone, nothing would ever happen. Solo mining bitcoin on a regular computer has been entirely hopeless for many years now. – David Schwartz Oct 11 '21 at 18:58