TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Bitcoin From Scratch – Part 1

293 pointsby monokhalmost 5 years ago

14 comments

tlrobinsonalmost 5 years ago
I wrote a toy (but working) implementation of the Bitcoin algorithm here: <a href="https:&#x2F;&#x2F;github.com&#x2F;tlrobinson&#x2F;tomcoin" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tlrobinson&#x2F;tomcoin</a><p>The main logic is a few hundred lines of code: <a href="https:&#x2F;&#x2F;github.com&#x2F;tlrobinson&#x2F;tomcoin&#x2F;blob&#x2F;master&#x2F;src&#x2F;node.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tlrobinson&#x2F;tomcoin&#x2F;blob&#x2F;master&#x2F;src&#x2F;node.j...</a><p>A somewhat unique aspect is since it&#x27;s written in JavaScript a node can run on the server or the browser, which makes for easy demos:<p>1. Open <a href="https:&#x2F;&#x2F;tomcoin.herokuapp.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tomcoin.herokuapp.com&#x2F;</a> and <a href="https:&#x2F;&#x2F;tomcoin1.herokuapp.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tomcoin1.herokuapp.com&#x2F;</a> in two browser windows (the private key is stored in localStorage so using different domains ensures each gets a different wallet)<p>2. Click &quot;Start Mining&quot; on one or both nodes<p>3. Once you&#x27;ve mined some TomCoin (should just take a few seconds unless more people start mining) copy the public key from one node to the other&#x27;s &quot;publicKey&quot; field, enter an amount, and click &quot;Transfer&quot;<p>4. Wait for another block to be mined and you should see the balances transfer<p>(There&#x27;s no persistence so the chain will reset when all the Heroku nodes idle out and other nodes close)<p>(It also just uses WebSockets to connect to the instances on Heroku, or in theory other server instances people are running. I meant to implement WebRTC for P2P between browser nodes but never got around to it)
评论 #23731342 未加载
评论 #23731186 未加载
nemo1618almost 5 years ago
&gt; The PoW is suffice if the hash begins with a certain number of 0s<p>This is a common explanation of PoW, but is actually incorrect. If you think about it, this would mean that the PoW difficulty could only increase (or decrease) by a factor of two. In reality, the block hash is simply interpreted as a (very large) number, and this number must be less than some other very large number (the &quot;target&quot;). So you <i>do</i> end up with a lot of leading zeros -- but these are just a side effect, not the thing being measured.
评论 #23728978 未加载
评论 #23728956 未加载
评论 #23729725 未加载
评论 #23732168 未加载
评论 #23730800 未加载
ggrrhh_taalmost 5 years ago
For people that need or want to know (really understand) in depth about Bitcoin without any previous background in Computer Science (for example, in Finance, investors, journalists, historians, curious people in general) I have to recommend Ted Nelson&#x27;s &quot;How Bitcoin actually works&quot; (2014) from his series &quot;Computers for Cynics&quot; [0]. I enjoyed it. (+)<p>[0] <a href="https:&#x2F;&#x2F;youtu.be&#x2F;3CMucDjJQ4E" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;3CMucDjJQ4E</a><p>(+) For the people with background in CS: it might be that the video at some point talks about the number of zeros instead of the comparison, but really, it does not detract a &#x27;bit&#x27; from its value.<p>edit: formatting
评论 #23730765 未加载
obilgicalmost 5 years ago
Here is a simple bitcoin implementation in ruby including the networking for interested, that I did some time ago:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;oguzbilgic&#x2F;zincir" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;oguzbilgic&#x2F;zincir</a>
ozankabakalmost 5 years ago
Clear, concise and to the point. Looking forward to reading the rest. If you finish the whole series and fix&#x2F;improve the posts in this sequence using the feedback from here, I think it might serve as one of the go-to pages for technically inclined people who are interested to learn about Bitcoin and blockchains.
评论 #23729411 未加载
aciswhatalmost 5 years ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;lhartikk&#x2F;naivechain" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lhartikk&#x2F;naivechain</a> is a rather decent introductory implementation as well.
ur-whalealmost 5 years ago
Love this way of learning about tech. : build one yourself (the truly noble way would be to try and build without having seen the specs, just from a description of what it does, but that&#x27;d take ages).<p>However: when it comes to implementations, the real hard part of the whole Bitcoin affair is where the gnarly details hide, namely consensu, and it is missing at this point.
rammy1234almost 5 years ago
Mining part is confusing for me. Is POW is essentially to achieve difficulty level ? You do in this while loop until you have achieved this difficulty level ? Is this the primary factor that differentiates having various protocol in crypto ?
评论 #23731661 未加载
评论 #23734405 未加载
cchancealmost 5 years ago
Please finish this series! Especially the networking and consensus models it&#x27;s an interesting read, really like that it&#x27;s in Rust as I&#x27;m also learning Rust so it&#x27;s nice to see the concepts in that language :)
fogettialmost 5 years ago
&gt; the transaction needs to be &quot;Signed&quot; by the `from` public key<p>Is that so? The code actually signs with the private key. Although I might have misunderstood what that sentence refer to.
评论 #23732552 未加载
mmahemoffalmost 5 years ago
Thanks for this info Monokh. Just want to raise a minor typo, which is the first line of code in &quot;Signed transactions&quot;. I think it&#x27;s missing two of the map keys.
shuringaialmost 5 years ago
I really like the intention and good will behind the post but almost every part is incorrect (even on an abstract level not restricting to bitcoin). I feel like OP is yet another someone who needed the keyword &quot;blockchain expert&quot; on his&#x2F;her linkedin profile and trying to justify it now with misleading and incomplete information.
评论 #23731023 未加载
评论 #23731058 未加载
评论 #23730922 未加载
Koshkinalmost 5 years ago
It would be nice to be told what programming language this page is using.
deevolutionalmost 5 years ago
Bookmarking this one.