Note
If you are new to the blockchain technology, taking our Introduction to Blockchain Technology self-paced course is highly recommended. Also, for a comprehensive coverage of blockchain development in Ethereum or mastering Solidity programming, taking our below self paced courses is highly recommended:
Recap
In our previous article (How to Run Geth on a Local Private Ethereum Blockchain), we discussed how to setup and run Geth on a local private Ethereum network.
In this article, we learn how to develop a local private Ethereum network that includes mining component.
Private blockchains with mining
We have shown you the steps to start a simple private blockchain. With some additional steps, you can set up private blockchains with mining enabled too. We will discuss the steps you need to take to get a mining blockchain up and running in the local environment here:
Setting up an environment
Let’s create another directory for a blockchain with mining. It’s very similar to how we set up an environment in the Private blockchain without miningarticle. In the following code, we create two more subdirectories, data and src, under hello_world_mining:
$ cd hello_world_mining $ mkdir data $ mkdir src
When data and src are created, you list the information of the directories under
hello_world_mining to verify the names and locations.
Configuring the custom genesis file
When we created the blockchain without mining, we left the alloc section blank. We will prefund the accounts this time. You may want to tune the difficulty to a lower value in your first attempt. It is better to choose some random value for a nonce, in case it connects to any unknown nodes. Let’s have a look at the following configuration:
{ "config": { "chainId": 135, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 },
“alloc” : {
“0x0000000000000000000000000000000000000001”: {“balance”: “111111111”},
“0x0000000000000000000000000000000000000002”: {“balance”: “222222222”}
},
“coinbase” : “0x0000000000000000000000000000000000000000”,
“difficulty” : “0x00001”, “extraData” : “”, “gasLimit” : “0x2fefd8”,
“nonce” : “0x0000000000000107”,
“mixhash” : “0x0000000000000000000000000000000000000000000000000000000000000000”,
“parentHash” : “0x0000000000000000000000000000000000000000000000000000000000000000”,
“timestamp” : “0x00”
}
The configuration here is the pre-funding address 0x0000000000000000000000000000000000000001 and the balance of 111111111 and 222222222 to the 0x0000000000000000000000000000000000000002 address.
One-to-One Live Blockchain Classes
Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.
Let’s take the opportunity to look at the other parameters here:
- coinbase: A 160-bit address that gets the ether rewards from successful mining.
- difficulty: The difficulty level of how hard it is to mine a block when a nonce discovers the block. The higher the value or the difficulty is, the more calculations that need is needed to be done to mine the block. The difficulty of the current block normally calculated using the timestamp and the difficulty of the previous block. Difficulty plays an important role in controlling the frequency of block generation. Difficulty is set to keep the waiting time of generating a block in the target range. When we read difficulty, we can interpret it using its reciprocal. For example, difficulty is set to 0 x 0400 in hexadecimal, which is 1,024 in decimal. The reciprocal of decimal 1,024 is 1/1024. Basically, 1/1024 indicates there will be 1 successful mining out of 1,024 hash operations on average. The faster your machine can finish 1,024 hash operations, the faster you will get a valid block.
- mixhash and nonce: mixhash is a 256-bit hash and nonce is a 64-bit hash. Both of them are used together to verify if the block is cryptographically mined and is a valid block. The verification requirement for them combined is defined in the yellow paper. The reason why both of them are needed rather than just a nonce is that a nonce can be falsified in an attack. It will cost a large amount of computational power of the network to discover the nonce was false. An intermediate calculation, which mixhash provides, can help to find out a nonce. And this calculation is not as expensive. So, when a suspicious mixhash is found when the block is being validated, the block can be discarded without us having to do any additional calculation to check the nonce.
- parenthash: The Keccak 256-bit hash of an entire block header of the parent. It includes both mixhash and the nonce.
- gaslimit: This is the upper limit of computations that any block can support. We will talk about this in detail in later in this series.
- timestamp: This provides the Unix time() output at the block’s inception. The timestamp helps to verify the order of the blocks on the chain.
- extraData: This is an optional space with a maximum of 32 bytes.
By now, you should understand the structure and content of a genesis file. Be our guest and customize a genesis file on your own. Doing so will deepen your understanding.
Next Article
In our next article (How to Run Geth on a Local Private Ethereum Blockchain with Mining), we discuss how to run Geth on a local private Ethereum network that includes mining component.
This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.
Resources
Free Webinars on Blockchain
Here is the list of our free webinars that are highly recommended:
- Hyperledger Fabric for system admin versus developers
- How to harness blockchain for environmental and corporate sustainability
- Review of Initial Coin Offering, Security Token Offering and asset tokenization use cases and best practices
- Hyperledger Fabric Deployment on Cloud
- Hyperledger Fabric for entrepreneurship- 21 blockchain business use cases
Free Courses
Here is the list of our 10 free self-paced courses that are highly recommended:
- IT Career Roadmap Explained
- Web Design with Bootstrap
- User Experience Best Practices
- Intro to Search Engine Optimization
- Web Design with WordPress
- Introduction to Drupal CMS
- Intro to Joomla CMS
- Intro to Cybersecurity
- Introduction to Cloud Technology
- Recorded Live Webinars and Classes
Self-Paced Blockchain Courses
If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:
- Intro to Blockchain Technology
- Blockchain Management in Hyperledger for System Admins
- Hyperledger Fabric for Developers
- Intro to Blockchain Cybersecurity
- Learn Solidity Programming by Examples
- Introduction to Ethereum Blockchain Development
- Learn Blockchain Dev with Corda R3
- Intro to Hyperledger Sawtooth for System Admins
Live Blockchain Courses
If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:
- Live and self-paced blockchain development with Ethereum
- Live and self-paced blockchain development with Hyperledger Fabric
- Live and self-paced blockchain development with Corda
- Immersive Blockchain Bootcamp with live and self-paced courses
- Live crash course for learning Ethereum with Solidity
- Live crash course for building DApps with Hyperledger Fabric
- Live crash course for building DApps with Corda
- Live full-stack blockchain development in Hyperledger and Ethereum
Articles and Tutorials on Blockchain Technology
If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:
- History and Evolution of Blockchain Technology from Bitcoin
- Overview of Blockchain evolution and phases from Ethereum to Hyperledger
- Comprehensive overview and analysis of blockchain use cases in many industries
- Blockchain Crowdfunding Security Token or Initial Coin Offerings
- A beginner Guide to Blockchain Technology
- How Decentralized Peer-To-Peer Network Works
- How blocks are added to the blockchain
- How Public and Private Keys of Cryptography Work
- What Is A Cryptographic Hash Function
- How Digital Signature Works In Blockchain
- The role and types of consensus mechanism in blockchain
- How Proof-of-Work Consensus Works in Blockchain
- How Proof of Stake Consensus works in Blockchain
Articles and Tutorials on Ethereum and Solidity
If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:
- Review of Architecture and Components of Ethereum
- Comprehensive Blockchain Ethereum Developer Guide from Beginner to Advance Level
- How to Write Ethereum Smart Contracts with Solidity in 1 hour
- Review of Architecture and Components of Ethereum
- How Ethereum Manages Accounts
- How Ethereum Manages Transactions
- How Smart Contracts Work in Ethereum
- How Ether and Gas Work in Ethereum
- How Ethereum Virtual Machine works
- How address and wallet work in Ethereum
- How mining works in Ethereum
- List of Tools and Technologies in Ethereum Ecosystem
- Review of challenges in distributed systems
- Review of Cap Theorem in Distributed Systems
- Horizontal Scaling versus Vertical Scaling in Distributed Systems
- How to Scale up Ethereum Blockchain Applications
- Review of scaling solutions for Ethereum
- How to Manage Ethereum State Channel with Raiden
- How Plasma Chains Work in Ethereum
- How Sharding and Gasper work in Ethereum
- How Proof-of-Stack Consensus Works in Ethereum
- A roadmap for Implementing Ethereum 2.0
- How to work with Decentralized Data and Content Storage in Ethereum
- How Decentralized Messaging with Whisper Works in Ethereum
- Review of Infura for Ethereum Development
- Review of Infura Ethereum API
- How to Use Remix with Infura for Ethereum Development
- How Ethereum Client API Works
- How Ethereum IPFS Storage Works
- How to Install and Start Ethereum IPFS Storage
- How to Run Ethereum IPFS Storage
- How to Work with Ethereum Swarm Storage
- How to Install Ethereum Swarm Storage
- How to Handle Ethereum Messages with Whisper
- Review of Popular Ethereum Smart Contract Libraries
- Review of Private and Permissioned blockchain
- How to Set up a Local Private Ethereum Blockchain
- How to Run Geth on a Local Private Ethereum Blockchain
- How to Build a Local Private Ethereum Blockchain with Mining
- How to Run Geth on a Local Private Ethereum Blockchain with Mining
- How to Create an Account on a Local Private Ethereum Blockchain
- How to Use Ethereum Optional Flags with New Chains
- Review of Ethereum Options for Development and Testing
- Review of Ethereum Developer Chain Options
- Review of Ethereum API and Console Options
- Review of Ethereum Networking Options
- Review of Ethereum Transaction Pool Options
Articles and Tutorials on Hyperledger Family
If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:
- Introduction to Hyperledger Architecture, Projects, Tools and Libraries
- Complete Review of Hyperledger Fabric Architecture and Components
- Hyperledger Fabric for System Administers versus Developers
- How to use Prometheus and Grafana to monitor Hyperledger Fabric
- Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS
- Blockchain Developer Guide- How to Install and work with Hyperledger Sawtooth
- Blockchain Developer Guide- How to Install Hyperledger Burrow on AWS
- Blockchain Developer Guide- How to Install Hyperledger Iroha on AWS
- Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS
- Blockchain Developer Guide- How to Install Hyperledger Seth and Docker on AWS
- Blockchain Developer Guide- How to Configure Hyperledger Sawtooth Validator and REST API on AWS
- Blockchain Developer Guide- How to Build Transaction Processor as a Service and Python Egg for Hyperledger Sawtooth
- Blockchain Developer Guide- How to Deploy Ethereum Smart Contracts with Hyperledger Burrow
- Blockchain Developer Guide- How to Create Cryptocurrency Using Hyperledger Iroha CLI
- Blockchain Developer Guide- How to Explore Hyperledger Indy Command Line Interface
- Blockchain Developer Guide- Comprehensive Blockchain Hyperledger Developer Guide from Beginner to Advance Level
- Introduction to Hyperledger Sawtooth Blockchain Development
Articles and Tutorials on R3 Corda
If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:
Articles and Tutorials on Other Blockchain Platforms
If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: