<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: gmfcastro</title>
    <description>The latest articles on DEV Community by gmfcastro (@gmfcastro).</description>
    <link>https://dev.to/gmfcastro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F86930%2F9597897b-3bae-4dd5-93a8-c5e54f9ca74f.jpg</url>
      <title>DEV Community: gmfcastro</title>
      <link>https://dev.to/gmfcastro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gmfcastro"/>
    <language>en</language>
    <item>
      <title>The Bitcoin's lifecycle overview</title>
      <dc:creator>gmfcastro</dc:creator>
      <pubDate>Tue, 28 Aug 2018 22:42:52 +0000</pubDate>
      <link>https://dev.to/gmfcastro/the-bitcoins-lifecycle-overview-1fld</link>
      <guid>https://dev.to/gmfcastro/the-bitcoins-lifecycle-overview-1fld</guid>
      <description>&lt;p&gt;Blockchain is a disruptive subject and is very different from the traditional systems. That's why in my opinion the best way to understand and learn it, is studying the first successful implementation of it. The Bitcoin ! &lt;/p&gt;

&lt;p&gt;With Bitcoin the subject started to be at the spot, with the valorization of it a lot of tech and financial people started to look closer to the technology below Bitcoin, and what makes this so secure and better than the traditional way we care about money today ?&lt;/p&gt;

&lt;p&gt;The first point that I want to share with you today is how the bitcoin network works. The network used in the bitcoin's is a very old one and we use today to download torrents. The bitcoin and other implementations of blockchain uses P2P network ! &lt;/p&gt;

&lt;p&gt;Then you are going to ask yourself, how that works ? I know that this looks really crazy at first, but when you open your mind for blockchains you see that this makes sense and works very well when you aim decentralization and immutability !&lt;/p&gt;

&lt;h1&gt;
  
  
  Distributed Network
&lt;/h1&gt;

&lt;p&gt;First we have to understand the differences between Centralized, Decentralized and Distributed network. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo3l6wwmq8ouhiwr84v1k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo3l6wwmq8ouhiwr84v1k.jpg" alt="Types of network" width="735" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the centralized network we have only one central point where all peers send data to. This is how the traditional client-server works today, where the central point is the sever and it have all the data authority.&lt;/p&gt;

&lt;p&gt;In the other hand we have the decentralized one that is how the internet works today, we have some backbones that communicate to each other, but the peers still sending data to one backbone. In that case we yet have some central point that have the data authority. That's why we have the distributed network, where the central point of data doesn't exist and every peer in the network works as a server. This is the Peer-to-Peer also known as P2P network ! Now I can ask you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Between those three what is the best network to handle your money ? &lt;/li&gt;
&lt;li&gt;Do you think its fair or trusty that only some peers handle your money ? &lt;/li&gt;
&lt;li&gt;What if this central peer is a bad person/ company ?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is one of the problems that bitcoin is trying to solve, but how that works ?&lt;/p&gt;

&lt;h1&gt;
  
  
  The Bitcoin lifecycle
&lt;/h1&gt;

&lt;p&gt;Let's say that Sender wants to send 1 Bitcoin to Receiver. This is what is going to happen:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv10927ekqpfpypyhapq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv10927ekqpfpypyhapq.png" alt="Bitcoin Lifecycle" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sender creates a transaction.&lt;/li&gt;
&lt;li&gt;Sender's bitcoin wallet validates the transaction.&lt;/li&gt;
&lt;li&gt;The transaction is sent to Mempool.&lt;/li&gt;
&lt;li&gt;Miners get the transaction from Mempool and start mining the block using a consensus algorithm.&lt;/li&gt;
&lt;li&gt;After the block is fully mined, it is added to the network.&lt;/li&gt;
&lt;li&gt;The chain validates the new block and every peer in the network will get the blockchain with the new block added.&lt;/li&gt;
&lt;li&gt;Finally, the Receiver get your BTCs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here are some question you might have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the Mempool ?&lt;/li&gt;
&lt;li&gt;What the heck is Consensus Algorithm ?&lt;/li&gt;
&lt;li&gt;What happens with Sender's BTCs after the transaction is done ?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope that I thought in the same questions of you :) . &lt;/p&gt;

&lt;h1&gt;
  
  
  Mempool
&lt;/h1&gt;

&lt;p&gt;The Mempool (Shortcut for Memory Pool) is where the transactions stay until the miner is ready to get them. In the bitcoin's blockchain, the miner prioritize the biggest transactions over the smallest ones. This happens because here is where the miner makes money. Wait.. what? Yes, every transaction in the blockchain has a fee, and the miner get that fee to him plus the reward for mining the block. &lt;/p&gt;

&lt;p&gt;Ok, but how the miner "mine" the block ? This is done through the consensus algorithm.&lt;/p&gt;

&lt;h1&gt;
  
  
  Consensus Algorithm
&lt;/h1&gt;

&lt;p&gt;The consensus algorithm is probably the most important part of any implementation of blockchain. Here is where you achieve democratization of your network !&lt;/p&gt;

&lt;p&gt;The Bitcoin uses one consensus algorithm called Proof Of Work, also you'll find written as PoW. There are some other strategies for getting consensus in a blockchain network that I'll write more about them later, but for now let's focus in the basics of PoW.&lt;/p&gt;

&lt;p&gt;What this basically does is: try to get the right nonce number by checking the hash created for the block until the result hash have the same number of zero's in it's prefix as the current difficulty set in the Blockchain. This difficulty exists to control how fast the block will be mined in the network. Bitcoin uses a number to try to have the time of mining near of 10 minutes. If the mining is faster than it, the network increases the difficulty and if this is getting slow, the network decreases the difficulty. &lt;/p&gt;

&lt;p&gt;That sounds familiar? This is how Bitcoin controls inflation ! &lt;/p&gt;

&lt;p&gt;This execution to try to get the right nonce number takes a lot of energy cost and computational work, and that's why the miners get the fees from the transaction. Also the miners are rewarded for mining the block, but this decreases over time until some day the miner will get only the transaction fees.&lt;/p&gt;

&lt;h1&gt;
  
  
  Wallet deduction
&lt;/h1&gt;

&lt;p&gt;Hoping that you understand everything until here, as you can see that in the picture above Sender sent 1 BTC and Receiver got 1 BTC, but as I said in this post there is transaction fees that should be deducted here. &lt;/p&gt;

&lt;p&gt;Let's suppose that Sender is sending 1 BTC to Receiver and he got 1.50 BTC in your wallet. Also lets assume that the transaction fee is 0.20 BTC. Here is what happens below the blankets over there:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sender says that he wants to send 1 BTC to Receiver.&lt;/li&gt;
&lt;li&gt;The transaction will have as a input 1.50 BTC, but one output of the transaction is going to be 1 BTC that Receiver should receive.&lt;/li&gt;
&lt;li&gt;The other output is going to be the change that Sender will get from this transaction: 1.50BTC - 1 BTC - 0.20 BTC = 0.30 BTC is the other output of the transaction. Those outputs are called UTXO( Unspent transaction Output)&lt;/li&gt;
&lt;li&gt;Then sender gets your change and your balance now is 0.30 and the Receiver gets your 1 BTC.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The UTXO have an important part inside in the bitcoin's network, but that is subject to other post :)&lt;/p&gt;

&lt;p&gt;I know that there is a lot of information over here, but I think that these concepts are really important to understand together before going deeper in each component in a blockchain's network.&lt;/p&gt;

&lt;p&gt;Cheers ! See you in the next post.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>crypto</category>
    </item>
    <item>
      <title>Explaining blockchain basics</title>
      <dc:creator>gmfcastro</dc:creator>
      <pubDate>Sun, 12 Aug 2018 01:03:26 +0000</pubDate>
      <link>https://dev.to/gmfcastro/my-best-shot-explaining-blockchain-4873</link>
      <guid>https://dev.to/gmfcastro/my-best-shot-explaining-blockchain-4873</guid>
      <description>&lt;p&gt;Following my studies of blockchain, I've focused to have a deeper understanding of what is a blockchain and how it works. Of course a lot of you may have already know what is it, but I'll share with you what I've learned so far.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is it in simple words ?
&lt;/h1&gt;

&lt;p&gt;Blockchain is a virtual ledger, where each record of this is a block. That records are  distributed in a network for everybody, where them can read and write, but not change the information of it. To understand this better, let's get to know what is a block and what is inside of it, and then how a block connects with other block. For this explanation, I'm going to explain blockchain based in the bitcoin implementation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Anatomy of a block
&lt;/h1&gt;

&lt;p&gt;Each block contains a header and a body.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fps5ay7rlfco877p7eua7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fps5ay7rlfco877p7eua7.png" alt="Block"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are the data that each block have. Besides that, every block has a max size in bytes that is defined by the developer. When this max size is reached, this block is added to the blockchain and a new one starts to be created. I'll explain each of those items below.&lt;/p&gt;

&lt;h4&gt;
  
  
  Block Number
&lt;/h4&gt;

&lt;p&gt;Every block in a blockchain have a number that represents your position in the chain. The 1st block added to the chain has a special name, they are called &lt;strong&gt;genesis block&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  PrevBlockHash
&lt;/h4&gt;

&lt;p&gt;Every block have in the header a reference of the previous block hash number. This is really important, because this is how the blockchain keeps consistent and control the immutability.&lt;br&gt;
The genesis block, doesn't have nothing that refers a previous block, since it is the first block.&lt;/p&gt;

&lt;h4&gt;
  
  
  MerkleRoot
&lt;/h4&gt;

&lt;p&gt;The merkleRoot is the hashing result of all transactions inside the block. If anything is changed inside the block, this hash also changes and invalidate the changed block and the next ones also. &lt;br&gt;
Now you can wonder: why this field is called MerkleRoot instead of blockHash ? This is because Bitcoin uses the &lt;a href="https://en.wikipedia.org/wiki/Merkle_tree" rel="noopener noreferrer"&gt;Merkle Tree&lt;/a&gt; to generate the hash from block's data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Nonce
&lt;/h4&gt;

&lt;p&gt;This is a 32-bit number that is related with the mining process of a block. This number is used only once to find a hash that matches the difficulty of the blockchain. I'm going to write about mining later and hopefully this will be more clear for you.&lt;/p&gt;

&lt;h4&gt;
  
  
  CreationTimestamp
&lt;/h4&gt;

&lt;p&gt;This is the timestamp of the block creation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Data
&lt;/h4&gt;

&lt;p&gt;Here is where all the transactions data remains.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hashing
&lt;/h2&gt;

&lt;p&gt;I've talked a lot about hashing, right? What kind of hashing algorithm is used here? &lt;br&gt;
That's really depends of each implementation of the blockchain, but for the cases that I talked here this should be a One-Way hashing algorithm. Bitcoin uses the SHA-256 (Secure Hash Algorithm) with 256-bit length. If you want to read more about: &lt;a href="https://en.wikipedia.org/wiki/SHA-2" rel="noopener noreferrer"&gt;SHA-2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we know what is inside a block and what type of hashing is used, let's show how is it inside a blockchain.&lt;/p&gt;

&lt;h1&gt;
  
  
  Blockchain
&lt;/h1&gt;

&lt;p&gt;Here is where we will have our blocks linked together by the prevBlockHash as you can see below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa521yws9wrjbjz9tn482.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa521yws9wrjbjz9tn482.png" alt="Blockchain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The merkleRoot value is generated from the Data information, and if anything changes in there, the merkleRoot will change too and the rest of the blocks that was linking the prevBlockHash after the changed block won't be valid anymore. That's why the blockchain is immutable.&lt;/p&gt;

&lt;p&gt;I think this is a good start and if you want to know more, there is a really good website that you can use to play around and understand better what I said here: &lt;a href="https://anders.com/blockchain/block.html" rel="noopener noreferrer"&gt;Anders Block&lt;/a&gt; and &lt;a href="https://anders.com/blockchain/blockchain.html" rel="noopener noreferrer"&gt;Anders Blockchain&lt;/a&gt;. Also you can read the &lt;a href="https://bitcoin.org/bitcoin.pdf" rel="noopener noreferrer"&gt;whitepaper&lt;/a&gt; from the bitcoin's anonymous creator, Satoshi Nakamoto.&lt;/p&gt;

&lt;p&gt;Hope that this post helps you to understand more about blockchain and in my next post I'll explain about the blockchain network.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>bitcoin</category>
    </item>
    <item>
      <title>Why start learning blockchain ?</title>
      <dc:creator>gmfcastro</dc:creator>
      <pubDate>Wed, 08 Aug 2018 03:07:21 +0000</pubDate>
      <link>https://dev.to/gmfcastro/why-start-learning-blockchain--1k6o</link>
      <guid>https://dev.to/gmfcastro/why-start-learning-blockchain--1k6o</guid>
      <description>&lt;p&gt;Lots of developers at some point of their careers feels that what they are developing looks almost the same, maybe for a different public or different business scope, but the results is almost the same. I mean, a product with some new features that people are enjoying (or not) and this will keep their company's earning money and growing. I'm not saying that this is a rule, but I know developers that feel this way and I'm one of those.&lt;/p&gt;

&lt;p&gt;In my opinion the developers could do more to the world than only crafting applications that people will use to interact or manage businesses. Of course that they are important and should keep existing, but  we can create solutions for solving problems related to social inequality, food distribution and fair price policies. I'm not going to go deeper in those problems, but everybody knows that they exists and make a lot of people's life harder.&lt;/p&gt;

&lt;p&gt;Looking into the Blockchain, it really can help the world with problems like those and that's why I started studying it.&lt;/p&gt;

&lt;p&gt;With a blockchain we can create applications for tracking government transactions and make it impossible to commit embezzlement or money laundry. This is possible because blockchain is basically an accounts book that everyone have it and every time a new transaction happens a new record is generated and added to everybody's book. This brings transparency, trust that from where to where the money goes and that the amount taken from the sender to the destiny was really effective.&lt;/p&gt;

&lt;p&gt;Ok, that is not going to solve all problems, but this is an example of what we can do to help the world to became a better place ( Even that is a little bit :D ) for everyone. Let's use our knowledge to something that makes a positive impact to the world !&lt;/p&gt;

&lt;p&gt;I'm going to post all my studying learnings related to blockchain here and hopefully to make you more motivated to start learning it too.&lt;/p&gt;

&lt;p&gt;Cheers :D&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>career</category>
    </item>
  </channel>
</rss>
