<story><title>Bitcoin From Scratch – Part 1</title><url>https://monokh.com/posts/bitcoin-from-scratch-part-1</url></story><parent_chain></parent_chain><comment><author>tlrobinson</author><text>I wrote a toy (but working) implementation of the Bitcoin algorithm here: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;tlrobinson&amp;#x2F;tomcoin&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;tlrobinson&amp;#x2F;tomcoin&lt;/a&gt;&lt;p&gt;The main logic is a few hundred lines of code: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;tlrobinson&amp;#x2F;tomcoin&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;node.js&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;tlrobinson&amp;#x2F;tomcoin&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;node.j...&lt;/a&gt;&lt;p&gt;A somewhat unique aspect is since it&amp;#x27;s written in JavaScript a node can run on the server or the browser, which makes for easy demos:&lt;p&gt;1. Open &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;tomcoin.herokuapp.com&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;tomcoin.herokuapp.com&amp;#x2F;&lt;/a&gt; and &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;tomcoin1.herokuapp.com&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;tomcoin1.herokuapp.com&amp;#x2F;&lt;/a&gt; in two browser windows (the private key is stored in localStorage so using different domains ensures each gets a different wallet)&lt;p&gt;2. Click &amp;quot;Start Mining&amp;quot; on one or both nodes&lt;p&gt;3. Once you&amp;#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&amp;#x27;s &amp;quot;publicKey&amp;quot; field, enter an amount, and click &amp;quot;Transfer&amp;quot;&lt;p&gt;4. Wait for another block to be mined and you should see the balances transfer&lt;p&gt;(There&amp;#x27;s no persistence so the chain will reset when all the Heroku nodes idle out and other nodes close)&lt;p&gt;(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)</text></comment>
<story><title>Bitcoin From Scratch – Part 1</title><url>https://monokh.com/posts/bitcoin-from-scratch-part-1</url></story><parent_chain></parent_chain><comment><author>nemo1618</author><text>&amp;gt; The PoW is suffice if the hash begins with a certain number of 0s&lt;p&gt;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 &amp;quot;target&amp;quot;). So you &lt;i&gt;do&lt;/i&gt; end up with a lot of leading zeros -- but these are just a side effect, not the thing being measured.</text></comment>