<?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>Forem: Eric Khun</title>
    <description>The latest articles on Forem by Eric Khun (@eric_khun).</description>
    <link>https://forem.com/eric_khun</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%2F246328%2F563e1dc3-cb89-4d17-b7c5-b6bf01a80cbd.jpg</url>
      <title>Forem: Eric Khun</title>
      <link>https://forem.com/eric_khun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/eric_khun"/>
    <language>en</language>
    <item>
      <title>Explaining "Proof of Work" Blockchains to Developers
</title>
      <dc:creator>Eric Khun</dc:creator>
      <pubDate>Thu, 08 Jul 2021 04:03:23 +0000</pubDate>
      <link>https://forem.com/eric_khun/explaining-proof-of-work-blockchains-to-developers-4g66</link>
      <guid>https://forem.com/eric_khun/explaining-proof-of-work-blockchains-to-developers-4g66</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally &lt;a href="https://erickhun.com/posts/explaining-blockchains-to-developers/" rel="noopener noreferrer"&gt;posted in my personal blog&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;What is a blockchain?  Why are some people using it? Even as a developer, it took me a few years to understand what a blockchain really is,how it is working from inside out. I'll share here what I believe is a comprehensive explanation of what is a blockchain from a developer point of view.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a blockchain?
&lt;/h2&gt;

&lt;p&gt;In simple words, it’s a &lt;strong&gt;slow database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For Bitcoin, this database contains a ledger only. A ledger is basically records of how much “token” has been transferred between addresses. Everyone can create a “wallet”, and make a transaction on it. Those transactions will be visible by anyone in the world. Each time you want to “write” in the blockchain, it will cost a certain amount of “fees”. &lt;/p&gt;

&lt;p&gt;“Dubious dev: So... why not create a huge Postgresql/MySQL/MongoDB database cluster, and make it open to everyone? 🤔” &lt;/p&gt;

&lt;h2&gt;
  
  
  What looks like a “blockchain”?
&lt;/h2&gt;

&lt;p&gt;At a really high level, a blockchain is made of blocks containing some data. They are linked with each other with a reference (a hash) of its previous block:&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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-high-level.jpg" 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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-high-level.jpg" alt="Bitcoin structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s really similar to a &lt;a href="https://en.wikipedia.org/wiki/Linked_list" rel="noopener noreferrer"&gt;linked list&lt;/a&gt;, but there are some fundamental differences between the two, notably the mechanism of how blocks are added and the data it contains. &lt;/p&gt;

&lt;h4&gt;
  
  
  How are “blocks” built?
&lt;/h4&gt;

&lt;p&gt;The way new blocks get added is quite sophisticated and isn’t quite instant. &lt;/p&gt;

&lt;p&gt;When you want to make a new transaction on the blockchain - let’s say someone wants to transfer 5BTC to someone else - this will create a new “transaction” but is not immediately added to the blockchain: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The transaction first gets added to &lt;strong&gt;the mempool&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;From this mempool, a &lt;strong&gt;miner&lt;/strong&gt; will pick the transactions that he likes (the one that give him the most reward). The total size of all transaction transactions must be below 1MB. &lt;/li&gt;
&lt;li&gt;The miner will run a “brute-force” algorithm to solve a puzzle. Once he find it, it will have the possibility to add the transactions he picked to the blockchain , &lt;a href="https://medium.com/f2pool/into-the-mempool-empty-blocks-b368c6fbaad6" rel="noopener noreferrer"&gt;but not always&lt;/a&gt; (I’ll come to that one later).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Mempool&lt;/strong&gt; is a sort of waiting room with a priority ticket for transactions that are willing to pay more. The ship contains only a few seats (1MB), so it’s up to the &lt;strong&gt;miner&lt;/strong&gt; to decide if he let you in or not. But you might end up in a ship going nowhere. &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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-miners-pick-transactions.jpg" 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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-miners-pick-transactions.jpg" alt="Bitcoin structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check all the unconfirmed transactions waiting to be validated in the Bitcoin blockchain &lt;a href="https://www.blockchain.com/btc/unconfirmed-transactions" rel="noopener noreferrer"&gt;here&lt;/a&gt;. You can also read here a bit about the controversy to have a bigger block size .&lt;/p&gt;

&lt;p&gt;Well, this mempool/miner/puzzle architecture looks quite complicated for a database. Why is it needed?&lt;/p&gt;

&lt;h2&gt;
  
  
  Protecting the blockchain with Consensus and Decentralization
&lt;/h2&gt;

&lt;p&gt;A “classic” database will allow anyone who has its credential to add/remove/edit records at their will. Want to delete a transaction you’ve made? Add a higher amount in your own wallet? &lt;strong&gt;How would you know this database will always be managed the way it said it will&lt;/strong&gt;? How do you make sure the one managing the system will never attempt to change the transactions or the data in it? This is where decentralization, consensus, and immutability comes into play. &lt;/p&gt;

&lt;h3&gt;
  
  
  The race to add a block to the chain proof and work
&lt;/h3&gt;

&lt;p&gt;A blockchain “validates” and permanently stores the data after a consensus is reached. Consensus is an agreement about the state of the ledger. It agrees on things like account balances, the order of transactions, or even if transactions look legitimate. The &lt;a href="https://cbeci.org/cbeci/comparisons" rel="noopener noreferrer"&gt;most infamous&lt;/a&gt; consensus protocol is “Proof-of-Work” and used by Bitcoin and Ethereum.&lt;/p&gt;

&lt;h4&gt;
  
  
  Finding the “nonce”: Miners and Rewards
&lt;/h4&gt;

&lt;p&gt;“Proof of Work” blockchains have an interesting concept where you have to solve a puzzle to be able to add a block to to chain. This puzzle is run by miners. It is a brute-force algorithm where &lt;strong&gt;the first miner who solved it gets a reward&lt;/strong&gt; (and the privilege to add a block to the chain 😉). And this happens every time a new block needs to be added. Today, 1,000,000 miners are competing against each other in the hope to solve the puzzle. &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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-miners-adding-block.jpg" 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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-miners-adding-block.jpg" alt="Bitcoin Miners Adding blocks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Increasing difficulty
&lt;/h4&gt;

&lt;p&gt;Bitcoin has a built-in algorithm to try to get a target of 10 minutes to mine a block. If it takes a lot shorter to mine, the difficulty increases, if it takes longer, difficulty decreases. It means the more “hashpower”, the more difficult is the hash function to find the nonce. &lt;/p&gt;

&lt;p&gt;Since 2017, the difficulty has exponentially increased, requiring more powerful computation resource if you want to be lucky enough to mine a block. This is what lead to &lt;a href="https://www.ft.com/content/1aecb2db-8f61-427c-a413-3b929291c8ac" rel="noopener noreferrer"&gt;today’s heated discussion related to climate change and energy consumption&lt;/a&gt;: &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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fbitcoin-difficulty.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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fbitcoin-difficulty.png" alt="Bitcoin difficulty over time graph"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  How long would that take to mine a block with my computer?
&lt;/h4&gt;

&lt;p&gt;A difficulty of 1 corresponds to 2^32 = 4,3 trillion hashes. Your computer will have to hash a random number (via bruteforce) 4.3T times in the hope to find the nonce with the lowest difficulty possible. &lt;/p&gt;

&lt;p&gt;If we take today’s difficulty of &lt;a href="https://www.blockchain.com/charts/difficulty" rel="noopener noreferrer"&gt;about 20 trillions&lt;/a&gt; we will have to to go through 8.6 × 10^22 (it’s 86000000000000000000000 trillions 🤪) operation to try.&lt;/p&gt;

&lt;p&gt;Now let’s use a standard &lt;a href="https://en.bitcoin.it/wiki/Non-specialized_hardware_comparison" rel="noopener noreferrer"&gt;processor a core i7 2600&lt;/a&gt;  with pretty good hashing power of 23.9 MHash per second, or 2.3e7 hashes/second (or 23,000,000 operation/second). It would take the computer 8.6 × 10^22 / 2.3e7 = 3.7e15 seconds to try all the possibilities, or about &lt;strong&gt;118,567,000 years&lt;/strong&gt;. In comparison, if the difficulty was at 1 (when Bitcoin was created) it only took 186 seconds to go through all the possibilities and find the nonce. I know, we would all be rich now right?&lt;/p&gt;

&lt;p&gt;This difficulty increase is why miners buy more and more GPUs (CPUs aren't fast enough) to put in those gigantic “&lt;a href="https://youtu.be/f0HC1Udk6-E?t=159" rel="noopener noreferrer"&gt;mining warehouses&lt;/a&gt;”, in the hope to find that &lt;em&gt;lucky number&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Some new consensus starts to emerge to solve those issues. Ethereum is currently moving to &lt;a href="https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/" rel="noopener noreferrer"&gt;a “Proof-of-Stake” consensus&lt;/a&gt;. The current Ethereum blockchain &lt;a href="https://ethereum.org/en/eth2/merge/" rel="noopener noreferrer"&gt;will "merge" (in 2022?) into the proof-of-stake system&lt;/a&gt;. Some (really) interesting variations of the Proof of Stake consensus are adopted in the blockchain space, particularly the &lt;a href="https://docs.avax.network/learn/platform-overview/avalanche-consensus" rel="noopener noreferrer"&gt;Avalanche&lt;/a&gt; and &lt;a href="https://arxiv.org/abs/1807.04938" rel="noopener noreferrer"&gt;Tendermint Byzantine Fault Tolerance&lt;/a&gt; consensus. Bitcoin however will keep the proof-of-work mechanism. &lt;/p&gt;

&lt;h2&gt;
  
  
  Securing the blockchain with decentralization and cryptography
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;“Dubious dev: What if I solve the puzzle and add a fake transaction 🤔?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It's &lt;em&gt;almost impossible&lt;/em&gt; to create new blocks that erase transactions or create fake ones. If you were lucky enough to find the nonce, this doesn’t mean it will be added to the blockchain: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You will broadcast the information to other other miners &lt;/li&gt;
&lt;li&gt;Other miners will check carefully if the transactions if the block submit are actually legit transactions. &lt;/li&gt;
&lt;li&gt;If 51% agree on the legitimacy of the block, &lt;strong&gt;consensus is reached&lt;/strong&gt;, and the block is permanently added &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The 2nd step is where the “crypto” in “cryptocurrency: plays its main role. Blockchains use cryptography functions in many ways, but the first use case is &lt;strong&gt;to make sure one’s doing a transaction is actually the “owner” of the transaction&lt;/strong&gt;. It is also called signing a transaction. You can do that with a “secret key” (or commonly called private key). You can “sign” transactions with that private key to finalize an action. It’s like a real-world signature. In the cryptographers world, it is called “asymmetric cryptography” or  “public-key cryptography” in the developer's world.  With Bitcoin and Ethereum, miners will use the &lt;a href="https://en.wikipedia.org/wiki/Bitcoin#Design" rel="noopener noreferrer"&gt;ECDSA (Elliptic Curve Digital Signature Algorithm)&lt;/a&gt; function to make that check. &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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-merging-block.jpg" 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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fblockchain-merging-block.jpg" alt="Bitcoin Merging blockchain blocks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  More than value transaction
&lt;/h2&gt;

&lt;p&gt;Some blockchains can store and execute some code, such as the Ethereum blockchain. The Ethereum “database” can store code and get the code executed. The code store is called a “smartcontract”. In Ethereum, the programming language is “&lt;a href="https://docs.soliditylang.org/" rel="noopener noreferrer"&gt;Solidity&lt;/a&gt;”. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;receiveMoneyEvent(amount) {
    facilitatortFee = amount * 2/100
    splitMoneyAmount = (amount - facilitatortFee) / 2
    sendTo(charityAddressX, splitMoneyAmount)
    sendTo(charityAddressY, splitMoneyAmount)
    sentTo(facilitatortAddress, facilitatortFee)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, each time the smart contract receives money, it will forward it to 2 charities. In between, the “facilitator” will take a 2% fee.  Pretty simple isn’t it?&lt;/p&gt;

&lt;p&gt;Once you publish this code to the blockchain ( you’ll have to pay each time you want to do that, it’s like an expensive git push command), anyone who wants to can call this contract. In this smartcontract, addresses that will send Ether (ETH) to this contract, those actions will be executed. &lt;/p&gt;

&lt;h4&gt;
  
  
  Smart Contract Immutability
&lt;/h4&gt;

&lt;p&gt;The logic in those contracts never changes and will be on-chain forever. The contract you agree to interact will always do what it said it will. No one will ever be able to change the logic. The ones creating this contract won’t be able to change it, even if they published it. So there is no risk of 1 party changing terms, because the contract can’t be changed. It will be on the chain as long as the network is alive. &lt;/p&gt;

&lt;p&gt;As a developer, you might think it’s a bad thing. What if there is a bug?  Well you better write perfect code 😉. There are &lt;a href="https://www.dasp.co/" rel="noopener noreferrer"&gt;many ways&lt;/a&gt; to “hack” smart contracts. Some (really expensive) services , often owned by famous  security companies, exist to review your smart contracts before you publish them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transparency (or Privacy?)
&lt;/h3&gt;

&lt;p&gt;Privacy is one of the hottest topics in 2021. We don’t want to be tracked anymore, and try to hide from Internet giants like Facebook or Google. Bitcoin or Ethereum are however fully transparent. The ledger is public and anyone that has your wallet address can see the full history. It’s like a database with read privilege where you can query any balance or operations that happened for any wallet. For example see &lt;a href="https://etherscan.io/address/0xab5801a7d398351b8be11c439e05c5b3259aec9b" rel="noopener noreferrer"&gt;here how many Ethereum has Vitalik&lt;/a&gt; (Ethereum's dad), or how he received $375 millions worth of &lt;a href="https://www.akitatoken.net/" rel="noopener noreferrer"&gt;“AKITA” token&lt;/a&gt;, and then &lt;a href="https://etherscan.io/tx/0x2fb8b58f85ab4773da00771f7f1e1a9eacf99af0ef3310b75ebcd017099f7b3c" rel="noopener noreferrer"&gt;forwarded that "unwanted money)&lt;/a&gt; to an India Covid relief fund: &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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fvitalik-akita.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%2Ferickhun.com%2Fimg%2Fexplaining-blockchain-developers%2Fvitalik-akita.png" alt=" Vitalik Akita covid19"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're looking for privacy, some blockchains such as zCash or Monero make that information hidden. (Read on to understand how). But they're still public since anyone can use them.&lt;/p&gt;

&lt;p&gt;Some blockchains are private only. An interesting use case could be sharing some confidential data, between a group of  specific persons. An idea could be applied for the CRS (&lt;a href="https://www.oecd.org/tax/automatic-exchange/common-reporting-standard/" rel="noopener noreferrer"&gt;Common Reporting Standard, for preventing tax avoidance&lt;/a&gt;). Governments could share information of bank accounts into that blockchain. With decentralization, no government will have the "privilege" to delete transactions in it. If a change needs to be made, the full history of changes will be written in the ledger. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;A Blockchains is giant database that stores a ledger with all transactions of its users. It sometimes stores code that can be executed. The decentralization and consensus algorithm built into them make them &lt;em&gt;almost&lt;/em&gt; impossible to be compromised by “bad actors”. With today’s &lt;a href="https://coinmarketcap.com/charts/" rel="noopener noreferrer"&gt;blockchains aggregated valuation ($1.39Trillion!)&lt;/a&gt;, it feels like the world is somehow betting that blockchains could be tomorrow's new way to exchange money and share information. Or is that valuation only &lt;a href="https://crypto-anonymous-2021.medium.com/the-bit-short-inside-cryptos-doomsday-machine-f8dcf78a64d3" rel="noopener noreferrer"&gt;blowing smoke&lt;/a&gt; 🤔?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was originally &lt;a href="https://erickhun.com/posts/explaining-blockchains-to-developers/" rel="noopener noreferrer"&gt;posted in my personal blog&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>proofofwork</category>
    </item>
    <item>
      <title>A beginner guide to setup an Ethereum full node</title>
      <dc:creator>Eric Khun</dc:creator>
      <pubDate>Thu, 10 Oct 2019 19:01:31 +0000</pubDate>
      <link>https://forem.com/eric_khun/a-beginner-guide-to-setup-an-ethereum-full-node-4d9</link>
      <guid>https://forem.com/eric_khun/a-beginner-guide-to-setup-an-ethereum-full-node-4d9</guid>
      <description>&lt;p&gt;This is a step by step guide to setup your own Ethereum node on the Ropsten network. At the end of this guide you'll be able to: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run your own ethereum node synced with the Ropsten testnet network&lt;/li&gt;
&lt;li&gt;Making sure to keep the node in sync with the blockchain on the network&lt;/li&gt;
&lt;li&gt;Be able to communicate via the JSON-RPC API of your own node&lt;/li&gt;
&lt;li&gt;Using the same method to run your node on the main network&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why do you want run your own node?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Once your dAPP and Smart Contract are working locally, you'll want to test it on a real network with (almost) real condition. &lt;/li&gt;
&lt;li&gt;There is a service called &lt;a href="https://infura.io"&gt;Infura&lt;/a&gt;, allowing you to communicate easily with Ropsten via json-rpc without having to setup your own node. However, Infura doesn't allow you to &lt;a href="http://solidity.readthedocs.io/en/develop/contracts.html#events"&gt;listen to events&lt;/a&gt; that  your smart contract could trigger. Events are useful when you want start to do some fancy thing like real time data replication on a second database or simply notify your users in your &lt;a href="https://ethereum.stackexchange.com/tags/dapp-development/info"&gt;dApp&lt;/a&gt;. If you do not need events, you should definitely use Infura :)&lt;/li&gt;
&lt;li&gt;An other reason would be to mine some new block and earn some money. But I won't cover that topic here&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Prerequisite :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Your own server. I have a &lt;a href="https://m.do.co/c/8cd97ac64536"&gt;Digital Ocean&lt;/a&gt; one. A good droplet to use is the one with 2GB memory and 50GB of diskspace. I also pick Ubuntu 16.04 for the OS. If you're a student, you can have a nice &lt;a href="https://education.github.com/pack"&gt;$50 free credits for testing purpose&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;At least 10GB availlable of space disk.  The Ropsten chain takes about 9.0GB on my server disk (4rd  February 2018) . The "real" ethereum blockchain requires about &lt;a href="https://etherscan.io/chart2/chaindatasizefast"&gt;50GB of diskspace&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step1: Setup geth (go ethereum)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;geth&lt;/code&gt; will allow you to sync the Ethereum blockchain, but also and run a rpc client&lt;/p&gt;

&lt;p&gt;To set that up :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum -y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I'm using &lt;code&gt;geth version: 1.7.3-stable&lt;/code&gt; for this guide&lt;/p&gt;

&lt;p&gt;Some people might prefer &lt;code&gt;parity&lt;/code&gt;. This guide will focus on &lt;code&gt;geth&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step2: Sync your node with the Ropsten network
&lt;/h3&gt;

&lt;p&gt;The sync will take about 4 hours. I'm running the command in a &lt;code&gt;screen&lt;/code&gt; console, just in case I lose the ssh connection or want to do something else in the server. You can also use &lt;code&gt;tmux&lt;/code&gt; if you prefer. &lt;/p&gt;

&lt;p&gt;Optional : Before syncing it , make sure to remove any previous data you might have locally. (don't run that if you're in a middle of a sync, or you'll need to start again) :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth --testnet removedb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then sync the full ropsten blockchain network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth --testnet --fast --bootnodes "enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303,enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303" console
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Those flags are really important for the first run. They are useful for: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--testnet&lt;/code&gt; : you'll sync with the Ropsten network. Alternatively you can use other flags&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--fast&lt;/code&gt; : you're enabling &lt;a href="https://ethereum.stackexchange.com/a/11300"&gt;fast syncing&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--bootnodes&lt;/code&gt; : Through these bootnodes a node can join the network and find other nodes. The one I've given are valid for the 3rd Feb 2018, and might change in the future. Check the &lt;a href="https://github.com/ethereum/ropsten"&gt;ropsten official repo&lt;/a&gt; to get the updated bootnodes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;console&lt;/code&gt;: I attached the console to know the current state of the sync . Without that, you'll be a bit blind on the progress of the sync&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Ethereum blockchain will store the data in the default directory (&lt;code&gt;/YOUR_HOME/.ethereum/testnet/geth/chaindata&lt;/code&gt;). You can also check the size of the blockchain with &lt;code&gt;du -hs /YOUR_HOME/.ethereum/testnet/geth/chaindata&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Note: &lt;code&gt;geth&lt;/code&gt; will run indefinitely until you exit with ctrl-c. It needs to keep your node in sync with the network with all new data. So once you run the command, &lt;code&gt;geth&lt;/code&gt; kept the &lt;code&gt;--fast&lt;/code&gt; and &lt;code&gt;--bootnodes xxxx&lt;/code&gt;  in memory. So you can safely run geth (with always keeping the network you want to use , &lt;code&gt;--testnet&lt;/code&gt; in that case)&lt;/p&gt;

&lt;h3&gt;
  
  
  (optional) Step2.1: restart the sync when &lt;code&gt;geth&lt;/code&gt; error-out
&lt;/h3&gt;

&lt;p&gt;It happened to me (several times) that &lt;code&gt;geth&lt;/code&gt; errored-out during the sync. I didn't find out why, but simply run the following command, and the sync will continue from where it exited :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth --testnet console
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: I didn't specify the  &lt;code&gt;--bootnodes&lt;/code&gt; and &lt;code&gt;--fast&lt;/code&gt; flags&lt;/p&gt;

&lt;p&gt;If like me, &lt;code&gt;geth&lt;/code&gt; kept erroring out, and you do not have time to monitor the sync, here a command you can run to run that command indefinitely if it errors-out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;until geth --testnet  console; do
  echo geth sync failed, retrying in 10 seconds...
  sleep 10
done
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can then come back few hours later without worrying if the sync went well :)&lt;br&gt;
Also, having &lt;code&gt;geth&lt;/code&gt; that keep exiting might be a sign that oyu do not have enough memory. I recommend at least 2GB.&lt;/p&gt;
&lt;h3&gt;
  
  
  (optional) Step2.2: Check the progress of the sync
&lt;/h3&gt;

&lt;p&gt;Because you attached the console to the geth command with the &lt;code&gt;console&lt;/code&gt; flag, you'll be able to know the progress of the sync by typing that following command inside the &lt;code&gt;geth&lt;/code&gt; console : &lt;br&gt;
&lt;code&gt;&amp;gt; eth.syncing&lt;/code&gt;&lt;br&gt;
It will return :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  currentBlock: 914011,
  highestBlock: 2579729,
  knownStates: 7383,
  pulledStates: 480,
  startingBlock: 914001
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: &lt;code&gt;highestBlock: 2579729&lt;/code&gt; should match (even be  greater) than the last block in &lt;a href="https://ropsten.etherscan.io/"&gt;Ropsten Etherscan website&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step3: Activate the JSON-RPC API (and keep your node in sync)
&lt;/h3&gt;

&lt;p&gt;As a developer, sooner or later you'll want to start interacting with Geth and the Ethereum network via your own programs and not manually through the console. &lt;code&gt;geth&lt;/code&gt; has built in support for a JSON-RPC based APIs (standard APIs and Geth specific APIs). These can be exposed via HTTP, WebSockets and IPC (unix sockets on unix based platforms).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;geth --testnet --rpc --rpcapi "eth,net,web3" --rpccorsdomain '*' --rpcaddr 0.0.0.0 --rpcport 8080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--rpc&lt;/code&gt; Enable the HTTP-RPC server&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rpcaddr&lt;/code&gt; HTTP-RPC server listening interface&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rpcport&lt;/code&gt; HTTP-RPC server listening port&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rpcapi&lt;/code&gt; API's offered over the HTTP-RPC interface&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rpccorsdomain&lt;/code&gt; &lt;code&gt;*&lt;/code&gt; for allowing everything access to it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When running that command, &lt;code&gt;geth&lt;/code&gt; will keep your node in sync with the network. You can let that one run in a &lt;code&gt;screen&lt;/code&gt; or &lt;code&gt;tmux&lt;/code&gt; terminal to keep it alive. The best thing would be to let the process managed by &lt;code&gt;supervisord&lt;/code&gt; or &lt;code&gt;systemd&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Step4: Query the JSON-RPC API
&lt;/h3&gt;

&lt;p&gt;You can test if the api is working with &lt;code&gt;curl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' http://0.0.0.0:8080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If all is fine, you should get a response that looks like :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"jsonrpc":"2.0","id":67,"result":"3"}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  (optional) Open the firewall
&lt;/h3&gt;

&lt;p&gt;If you want your dApp or Metamask to communicate with your node, you'll need to open the port of your server. On Digital Ocean, it's quite easy via &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-digitalocean-firewalls"&gt;their console&lt;/a&gt;. With my example, I've opened the port &lt;code&gt;8080&lt;/code&gt; in the Inbound settings.&lt;/p&gt;

&lt;p&gt;Then you can query the api via :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' http://X.X.X.X:8080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;with replacing &lt;code&gt;X.X.X.X&lt;/code&gt; the ip of your instance.&lt;/p&gt;

&lt;p&gt;Also, please understand the security implications of opening up an HTTP/WS based transport before doing so! Hackers on the internet are actively trying to subvert Ethereum nodes with exposed APIs!&lt;/p&gt;

&lt;h3&gt;
  
  
  Run on the main Ethereum network
&lt;/h3&gt;

&lt;p&gt;As many may have guess, you'll just need to remove the &lt;code&gt;--testet&lt;/code&gt; flag to all commands I've shown you to be able to sync to the main Ethereum network! That's all!&lt;/p&gt;

&lt;p&gt;Also, you can change the &lt;code&gt;--testnet&lt;/code&gt; flag to &lt;code&gt;--rinkeby&lt;/code&gt; to use the Rinkeby network. The main differences with Ropsten are &lt;a href="https://ethereum.stackexchange.com/a/30072"&gt;detailed here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What did I build with this?
&lt;/h3&gt;

&lt;p&gt;With the Ethereum node, I've built &lt;a href="https://citymayor.co"&gt;Citymayor&lt;/a&gt;, a virtual game to trade cities around the world. This node was used to get all the events from our smart contract. &lt;/p&gt;

&lt;p&gt;I hope this guide was useful! Please &lt;a href="https://twitter.com/eric_khun"&gt;reach me&lt;/a&gt; if you have any questions! You can also see &lt;a href="https://erickhun.com/posts/setup-your-ethereum-node-geth-ropsten-test-network/"&gt;original post here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ethereum</category>
      <category>blockchain</category>
      <category>devops</category>
      <category>digitalocean</category>
    </item>
  </channel>
</rss>
