Bitcoin Forum
May 06, 2024, 06:31:11 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: My lightweight C# Bitcoin Miner  (Read 11122 times)
lithander (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 11, 2013, 03:06:18 PM
 #1

I've written a very simple CPU based Bitcoin Miner in C#. Only about 300 lines of code but functional.

It uses the basic GETWORK protocol to connect to pools and mines at 400Kh/s a second. Not enough for serious mining but enough to find a valid share eventually, submit it to the pool server and be happy about the fact that you understand every single line of code that made it happen!

If you are trying to understand how Bitcoin mining works and are frustrated about not finding a reference implementation that is minimal and easy to understand (like me, 2 days ago) here's my contribution:

https://github.com/lithander/Minimal-Bitcoin-Miner
1714977071
Hero Member
*
Offline Offline

Posts: 1714977071

View Profile Personal Message (Offline)

Ignore
1714977071
Reply with quote  #2

1714977071
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714977071
Hero Member
*
Offline Offline

Posts: 1714977071

View Profile Personal Message (Offline)

Ignore
1714977071
Reply with quote  #2

1714977071
Report to moderator
1714977071
Hero Member
*
Offline Offline

Posts: 1714977071

View Profile Personal Message (Offline)

Ignore
1714977071
Reply with quote  #2

1714977071
Report to moderator
1714977071
Hero Member
*
Offline Offline

Posts: 1714977071

View Profile Personal Message (Offline)

Ignore
1714977071
Reply with quote  #2

1714977071
Report to moderator
TrollByFire
Full Member
***
Offline Offline

Activity: 168
Merit: 100



View Profile WWW
May 11, 2013, 04:09:00 PM
 #2

Thank you for this.  I'm currently doing some development work, and this minimal implementation will go a long way.

BTC: 12JYhysrpqnzqhkZ6qRY8At3G14btEwTtF
shodan86
Newbie
*
Offline Offline

Activity: 11
Merit: 0


View Profile
May 11, 2013, 04:09:37 PM
 #3

looks like an interesting way to learn a bit more about the technical site of bitcoins, thanks a lot will have a look.
betonbro
Newbie
*
Offline Offline

Activity: 6
Merit: 0



View Profile
May 11, 2013, 08:12:13 PM
 #4

Hi, nice Smiley

Is it possible to use it to mine Litecoin or Feathercoin?

Have tried it with mining-foreman.org pool but it says:
ERROR Didn't find valid 'data' in Server Response

lithander (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 11, 2013, 10:48:26 PM
 #5

glad you like it! Smiley

@betonbro: I implemented the pool communication based on the information on: https://en.bitcoin.it/wiki/Getwork and tested it with btcguild and bitcoin.cz pools.

I'm not familiar with Litecoin and Feathercoin so no idea what it would take to mod it to support that.
judasiscariot
Newbie
*
Offline Offline

Activity: 46
Merit: 0



View Profile
May 12, 2013, 12:29:15 AM
 #6

This is awesome!  Thank you.  I'd also be interested in how to go about an scrypt implementation. 
lithander (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 12, 2013, 12:38:32 AM
 #7

I haven't looked into litecoin mining, yet. So I can't help you with scrypt! Smiley

I just started to learn all that stuff a couple of days ago. In fact when I wanted to write a blogpost about my miner I realized how awkwardly unfamiliar a lot of terms and principles still are. If you could have a quick look and correct potential misconception before I make a fool about myself that would be awesome. Blogpost is here: http://blog.pixelpracht.net/
OB1
Newbie
*
Offline Offline

Activity: 13
Merit: 0


View Profile
May 12, 2013, 07:34:18 AM
 #8

Quote
Nonetheless incredible amounts of electricity (~1 GW/h) are wasted on mining Bitcoins which is basically spend calculating zillion’s of SHA256 hashes.
Roll Eyes
Failed.
Source also failed (Virtual Bitcoin Mining Is a Real-World Environmental Disaster)
With that, how much of a failure is this lightweight C# Bitcoin Miner?
flatfly
Legendary
*
Offline Offline

Activity: 1078
Merit: 1011

760930


View Profile
May 12, 2013, 07:49:26 AM
 #9

Really nice and easy to understand! Thanks for this.
lithander (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 12, 2013, 09:29:22 AM
 #10

Quote
Nonetheless incredible amounts of electricity (~1 GW/h) are wasted on mining Bitcoins which is basically spend calculating zillion’s of SHA256 hashes.
Roll Eyes
Failed.
Source also failed (Virtual Bitcoin Mining Is a Real-World Environmental Disaster)
With that, how much of a failure is this lightweight C# Bitcoin Miner?

Failed in what way? It doesn't reflect your opinion or factual errors?
flatfly
Legendary
*
Offline Offline

Activity: 1078
Merit: 1011

760930


View Profile
May 12, 2013, 02:18:59 PM
 #11

About the binary that is included in your repo: could you post instructions on how to build it?
Can it be built using a free compiler? I have zero C# experience...

That way, anyone can verify that it is indeed derived from the source code. I'm sure it is, and am running it in a VM as a safety measure anyway, but this community is paranoid about new binaries in general, as I'm sure you'll understand.
SunCoin
Newbie
*
Offline Offline

Activity: 13
Merit: 0


View Profile
May 12, 2013, 02:24:33 PM
 #12

Hey,
that was a great work ... Now i can see how it works in a simple way ...
Thanks a lot
ppcko
Newbie
*
Offline Offline

Activity: 16
Merit: 0



View Profile
May 12, 2013, 03:02:13 PM
 #13

Nice. Thanks for sharing.
FaradayC
Newbie
*
Offline Offline

Activity: 24
Merit: 0


View Profile
May 12, 2013, 04:11:12 PM
 #14

Wow... That's amazing... I'll check out your code Smiley
aes1
Member
**
Offline Offline

Activity: 66
Merit: 10



View Profile
May 12, 2013, 07:23:06 PM
 #15

Neat. I had no idea mining could be that simple.

I compiled the source on an OS X machine by downloading Mono SDK from http://www.go-mono.com/mono-downloads/download.html. The compilation step and running the compiled binary was as easy as:

Quote
$ mcs Program.cs
$ mono Program.exe

Let's see if I actually manage to get any bitcoins with my 180 Kh/s miner Smiley

Next step: actually understanding what it does
JS2007
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
May 12, 2013, 07:34:55 PM
 #16

Good job, will look into this when I got some spare time... Easy sample code is always helpful for understanding concepts Smiley
flatfly
Legendary
*
Offline Offline

Activity: 1078
Merit: 1011

760930


View Profile
May 12, 2013, 07:46:01 PM
 #17

Neat. I had no idea mining could be that simple.

I compiled the source on an OS X machine by downloading Mono SDK from http://www.go-mono.com/mono-downloads/download.html. The compilation step and running the compiled binary was as easy as:

Quote
$ mcs Program.cs
$ mono Program.exe

Let's see if I actually manage to get any bitcoins with my 180 Kh/s miner Smiley

Next step: actually understanding what it does


Hmmm sorry to dampen your enthusiasm, but consider yourself lucky if you get one cent per week...

see:
http://tpbitcalc.appspot.com/?difficulty=11187257.4614&hashrate=0.2&exchangerate=114.40&bitcoinsperblock=25.00&rigcost=99.00&powerconsumption=40.00&powercost=0.10&investmentperiod=355
aes1
Member
**
Offline Offline

Activity: 66
Merit: 10



View Profile
May 13, 2013, 02:33:22 PM
 #18


Yeah,

after a day or so of mining, I finally got one share in btcguild... worth 0.00000071 BTC. Hurray!

Funny to think that it's more profitable to spend your time at bitcoin faucets. Or to collect recyclable bottles and return them to the store. Well, it was a nice exercise.
Constantinex13
Newbie
*
Offline Offline

Activity: 6
Merit: 0



View Profile
May 13, 2013, 02:38:10 PM
 #19

Awesome, This is much more effective than running lets say bfgminer, on a mid-range laptop (might as well mine while I'm at work!) lol
yager
Member
**
Offline Offline

Activity: 67
Merit: 10



View Profile
May 13, 2013, 03:39:57 PM
 #20

Awesome, This is much more effective than running lets say bfgminer, on a mid-range laptop (might as well mine while I'm at work!) lol

Good Idea, I might get my work pcs "working" for a change lol.
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!