How to Fork The Ethereum Blockchain

So much has been said about Ethereum Fork. Through this article, you will learn beyond the verbal meaning of the Ethereum fork to how to fork an Ethereum blockchain. However, it is still necessary to intimate our readers on the basics of the Ethereum fork to get them abreast with the subject.

What is an Ethereum Fork?

Ethereum fork is the product of copying, updating, and building on an Ethereum blockchain. This process sometimes results in two cryptocurrencies. However, it is often not the intention of forking. Rather, it is meant to upgrade an existing blockchain. Ethereum fork like others can be soft or hard fork; it is left for the developers to know which fork to perform. 

If the developer intends a backward compatible and a non-consensual fork, they should consider soft forking, but if it is a non-backward compatible and consensus fork, the best approach should be a hard fork. 

Before going deeper to learn how to fork the Ethereum blockchain, note that a fork can be unintentional or accidental. When two or more miners find a block at the same time, it is an accidental fork. On the other hand, an intentional fork refers to a deliberate move to modify the rules of the blockchain. 

Why Fork a Blockchain

Blockchain could be forked for several reasons. Meanwhile, the onus of forking a blockchain is to improve the scalability, decentralization, cost of the transaction, security, and affect other changes worthwhile on the existing chain instead of building a new one. For instance, the Ethereum blockchain even from its frontier stage up till the awaiting serenity stage has proven to be sturdy, robust, and has many untapped potentials. Therefore, forking is the best since it will take more resources, time, and effort to create a similar blockchain. 

Requirements to Forking a Blockchain

If you ever considered forking an Ethereum blockchain, there are prerequisites you must meet. The requirement for forking a blockchain ranges from software to hardware requirements. Below are the prerequisites; 

Step 1; Basic knowledge of the blockchain

It will be difficult to fork a blockchain you know nothing about. Every developer must know how the blockchain works to enable him/her to fork the blockchain. Particularly for the Ethereum blockchain, the developer has to know how the Ethereum development environment works as well as how it interacts with other environments beyond the local environment.

Step 2; Basic development skills including JavaScript, Linux command, etc

Every blockchain has its compliant programming tools and language. However, JavaScript, Python, and Linux command lines are the basic language of most blockchains including Ethereum.

Step 3; Windows, Linux, or a Mac OS

Various blockchain forking tools are designed for various operating systems. It is expected that you run on either Linux, Windows, or Mac OS. That way, you simply download and install the operating system version of the tool you use. However, Linux and its distros are more in demand and a must-have for the best development experience. 

Step 4; Ethereum client for instance; Ganache GUI or Ganache CLI, RPC, Ruffle, etc. 

An 'Ethereum client' is just a term that refers to any node able to parse and verify the blockchain, its smart contracts, and everything related. It also allows you to provide interfaces to create transactions and mine blocks which is the key for any blockchain interaction. To fork an Ethereum blockchain, we will be using Ganache-Cli

Step 5; Ethereum nodes include Infura, QuikNode, Geth, Nethermind, etc. 

Ethereum Nodes allows you to run your own nodes which helps you to run a private, trustless, and self-sufficient application. However, it's somewhat costly and tasking. Instead of going through the hassle of using Geth, Open Ethereum, etc., you can simply use third-party APIs like Infura, quikNode, and the likes. 

Steps to Forking an Ethereum Blockchain

Having got the requirements to forking the Ethereum blockchain, it is time to get started. Here is a step-by-step guide on how to fork an Ethereum blockchain. It is expected that after going through this guide, you'd be akin to having your first Ethereum fork. Read on; 

Create an Ethereum Endpoint

Let's start by choosing the Ethereum client that will help us in creating an Ethereum endpoint. There are varieties of Ethereum nodes such as Geth, Nethermind, Open Ethereum, Infura, QuikNode, and so on. You can run your node, but that requires more resources and technicalities. Therefore, you can use third-party APIs like Infura, QuikNode, Alchemy to run your node. 

For the sake of this article, we will choose to create our Ethereum endpoint using Infura or QuikNode. To create the Ethereum endpoint, sign up on any of the third-party APIs; Infura or QuikNode and follow the process. 

QuikNode

Login and verify your account to create a node. Make sure you verify the email before choosing a subscription that suits the node you want to deploy. 

Once you have access to your account, endpoint details will be generated for your node. Head to node and copy the HTTP protocol as follows;

Infura

If you prefer to create your endpoint using Infura, you can do the following; 

  1. Signup on Infura.io and verify your mail.
  2. Head to create a project. In this article, I named the project "NewFork." 
  3. Copy the endpoint as shown on the figure below. 

Remember to set the endpoint to the Mainnet before copying the HTTP Protocol. 

Note; whether you use QuikNode or Infura, don't forget to save the HTTP Provider Endpoint you copied because you will use it after setting up Ganache CLI. 

Download and Install Ganache CLI

Ganache-CLI is one of the major components of the Turtle client. It is the command-line interface of the Ganache Ethereum client that allows you to connect to a local blockchain for testing your decentralized application. Instead of forking the main-net directly, the ganache CLI allows you to have a local environment for your developments.

Ganache CLI uses ethereumjs to simulate full client behavior making development on Ethereum faster, easier, and safer. If you want to fork the Ethereum blockchain, it allows you to connect to a local Ethereum blockchain. For simplicity of illustration, we will be using Ganache-CLI to create a local blockchain on localhost:8545.

Linux users can download, install and run Ganache-Cli in two ways:

  1. Ganache CLI using npm (Node Package Manager). Open your terminal and run the command; 

$ npm install -g ganache-cli. 

  1. yarn package manager. Run theses for yarn package manager; 

$ yarn global add ganache-cli

Fork the Ethereum Main-net

Now you have installed Ganache-Cli, it is time to fork the mainnet.  Open your terminal/cmd and copy-paste the following:

$ ganache-cli --fork <ADD_YOUR_QUICKNODE_URL_HERE>

Remember to replace ADD_YOUR_QUICKNODE_URL_HERE with the QuickNode or Infura HTTP URL you got earlier and run the command; you should see something similar to the figure below; 

What happened is that it forked the mainnet at the blockchain’s latest block, 12200647. To find out, you can query the forked chain by pinging localhost:8545 as will be shown later.

Fork a Specific Block

Note the specific block in the blockchain you would like to fork. Fork it by appending "@" followed by the block number as shown below:

$ ganache-cli --fork <ADD_YOUR_QUICKNODE_URL_HERE>@<block_number>

Assuming we want to copy and make changes to a certain say xDai chain residing on the Ethereum blockchain network and use xDai for gas. Proceed to ETHExplorer and scroll to the holder's section. View the biggest Dai holders copy the address and run the following:

$ ganache-cli --fork <ADD_YOUR_QUICKNODE_URL_HERE> -u <address of token holder>

The above command line allows ganache to fork the Ethereum blockchain and unlock (-u) the attached Dai account for the local ganache environment. By implication, we used ganache-cli to impersonate a particular account address which is usually locked for the use which also helps us to make transactions on the simulated blockchain from that account address.

How to Query the Forked Coin

Impressive! You have forked a certain Dai account and will be happy to query the forked chain. Querying the forked chain allows you to get certain information about the forked chain such as transactions, gas used in the block, timestamp, miner’s address, etc.

You can do that by making an eth_getBlockByNumber call that will return information about the block at which we forked the chain. 

The command should look as follows;

$ curl --data '{"method":"eth_getBlockByNumber","params":["0xBA29D2",false],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545

After you have run the code shown above, your terminal should look like these;

Conclusion

After going through this guide, it is expected that you know how to use  Ganache-Cli to fork a blockchain. You can deploy and fork a blockchain on a local environment using Ganache-Cli. To do that, you need to master basic command lines and understand the Ethereum development environment.

Also Read; Defi 2.0: An Upgrade to The First Generation of Defi

EIP-1559: An Upgrade To Ethereum Fee Model

The Ethereum 1.0 fee model is a win to miners to the detriment of the users. However, EIP-1559, launched on 5th August 2021, is a core proposal to improve the efficiency of the Ethereum transactions, said to be investor-friendly. In the current Ethereum network, users sometimes overpay to be included in a block while miners profit. Not only that, users overpay, but there are also occasions where the network gets congested, resulting in confirmation delays. Besides that, the network is somewhat volatile and leads to losses and less predictable transactions. For example, fees can be as low as 2gwei. Other times it could be ranging from 20-50gwei, while there are occasions when it hits 200gwei, taken 10^9 =1ETH.

The above limitations of the Ethereum network often turn off users. Hence, they go for faster and cheaper transaction fee networks like Binance Smart Chain and others. To address the issues ahead of the Ethereum 2.0 launch in 2022, the Ethereum community is coming up with some proposals called Ethereum Improvement Proposals, EIP. One of such proposals is EIP-1559.


EIP-1559 is an Ethereum improvement proposal positioned to address confirmation delays and less predictable fees structure and introduce a burning mechanism to Ethereum's native token. This article is necessarily discussing in detail the EIP-1559, the benefits, and the implications to users, miners, and the network. Meanwhile, it is important to start with the current Ethereum fee model before the emergence of EIP-1559.

The Current Ethereum Fee Model

The current transaction fee mechanism of Ethereum 1.0 is the auction fee model. Better preferred is the first price auction fee model. The first price auction model is an unpredictable fee mechanism where users bid to make transactions on the Ethereum network. Sometimes, other users might have bid higher before transactions could be processed, making the user's transaction pending until the network stabilizes or drops to the bidding price.
For instance, user A bid to swap on Uniswap. On The other hand, a new token is launched, or other Ethereum network activity increases, making other users push for aggressive buying to make transactions. For those user's transactions to get processed, they need to bid higher and thus get their transactions confirmed faster. Notice that User A, who bid first but with a lower fee, kept waiting for confirmation while others with higher bids have been processed. To reduce the unpredictability of the auction fee model, wallets and exchanges are currently setting estimated fees that are often overpriced. A close look at the auction fee model shows that miners take up the transaction fees, including block rewards and uncle rewards, without feedback to the network.

However, EIP-1559 is promising to do things differently. Some will ask if other auction fee models aren't efficient enough. For instance, the second price auction, also called truthful or kth price auction, where everyone pays a gas price equal to the lowest gas price included in the block, although efficient in the traditional economic model, often results in collusion flaws in a blockchain or distributed network. 

The EIP-1559 is designed to solve the following problems of the auction fee model: 

To solve the problems above, the Ethereum community has agreed to deploy a complex economic model and real-time blockchain usage, which further provides more transparency to the fees and volatility of the network.

Changing The Game With EIP-1559

EIP-1559, unlike other EIPs, has been debated mainly since Buterin Vitalik announced it in 2019. It brought mixed reactions: miners are against it while users and investors are happy to welcome it. The question lies on why the debate and what is EIP-1559 offering to the Ethereum network?
The bone of contention here is that EIP-1559 changes the way network fee is made on the Ethereum Blockchain and increases the network capacity. Below are how EIP-1559 is changing the game of Ethereum transactions:

Base Fee

This is the algorithmically determined network fee proposed by the EIP-1559. It is also the minimum fee a user pays to include a transaction on the next block. Unlike the auction fee model, it is determined by the network and not the wallets and exchanges. That way, users know the price of the transaction beforehand. However, it does not necessarily make Ethereum network transactions cheaper as they can be adjusted up or down depending on network activities. But it makes the network more user-friendly and more predictable because users will know what they are paying beforehand.
The base fee is charged from users and further burnt, helping to prevent miners from colluding and inflating the network.

Miners Tip

Traditionally, wallets have categories of fees they charge users. Some categorize their estimated network fees as regular, priority, and custom, while others categorize theirs as small, medium, and high. What that means is that users can pay more for faster transactions. The miner's tip, also known as priority tip, is paid to miners to confirm transactions faster. Ideally, miners verify and process transactions in the order of their profitability. This way, miners earn for securing, validating, and processing transactions on the network. However, the EIP-1559 includes a refund mechanism that refunds excesses once they exceed a particular block's maximum fee.

Fee Cap

This is a custom kind of transaction fee that allows users to pay a certain amount of fee they want but is at the mercy of the network activity often. Let's say the network is high and requires over 50% of the gas limit. The transaction takes so long to confirm, waiting for the transaction fee to come close to the capped fee to be included in a block.

Ethereum Capacity

The EIP-1559 comes with a block size improvement. It expands the block size from 12.5M to 25M. With this, the base fee rises and falls depending on the utilization of the block space. The base fee rises when utilization is near 25M and reduces when it nears 12.5M gas demand. By implication, this helps wallets automatically adjust transaction fees, unlike the random estimates of the current network.

Benefits Of EIP-1559

EIP-1559 comes with several benefits to the Ethereum network performance and transactions. It proffers both security, monetary policy and user experience benefits as explained below; 

Increase Security On Ethereum

Through a tweet, Evan Van Ness, author of the week in Ethereum, explained that the EIP-1559 upgrade is an important, long-term step against denial of service (DOS) attacks, an attack that denies legitimate users access to services and computer networks. 

According to him, "Want to spam the chain while shoplifting ETH in hopes of profiting? Well, with the EIP-1559, that's exponentially more expensive."

As the block space increases to almost 200%, the base fee keeps rising, making it costlier for attackers to afford sufficient block space to launch an attack. 

Also, as the block space increases, the base fee rises and is burnt. For that reason, miners, who don't share in the base fee, have weaker incentives to perform near-head reorgs. Find more details about near-reorg and transaction fees effects here

Better User Experience

EIP-1559 makes fee estimation more predictable, hence, proffers a better user experience for users, unlike struggling to predict possible fees for transactions, say on Uniswap. The EIP allows users to consider three fee categories -base fee, fee cap, and priority tip to predict the possible transaction fee, unlike the legacy method where users bid and the highest is chosen. With EIP, a maximum fee is set for priority tips, and a base fee is set. The user sets a Fee cap which is compared with the base fee. When the Cap is in excess, the difference is returned to the user. 

Unlike the current fee model, the EIP fee model helps a better estimation and user experience since the above-stated fees are known beforehand. For a better understanding of what EIP-1559 affects user experience in these fee models, refer here

Economic Benefits

A term called “preventing economic abstraction of ETH” explains that users should pay with ETH and how healthy it is for the network. Unlike the current fee method, all fees, base, tip, and fee cap, are required to pay using ETH, the native token of the Ethereum network, instead of other assets. Doing that will help to increase the utility of ETH.


Under EIP-1559, all base fees are burnt and thus help reduce Ether's supply, which directly increases the valuation of the token. Hence, people suggest that it will make Ether deflationary.


As stated above that Base fees are burnt for every transaction. It also rises as the block space increases. The increase is thus burnt also, creating deflationary pressure on the supply of ETH. Better explained, more network activity (block space) is equal to more ETH burn equal less ETH supply, invariably more valuation of the native token. By implication, higher block space from 12.5m to 25m creates deflationary pressure.

Implications And Risk

Hard To Debug

The current EIP-1559 code specifications return a user’s maximum FEE CAP value as the gas price before the transaction is mined into a block. After the block has been mined, the gas price field changes to be the base fee. These changes on time and the state of blockchain possess a new challenge for decentralized app developers. Usually, a developer trying to debug their code runs into issues if the behaviour of the blockchain changes. To that effect, the changes associated with EIP-1559 code specifications comes a new debugging challenge.

According to Micah Zoltu, an independent developer, during an All Core Developers meeting said

“Any time you’re debugging an issue and the behavior changes based on when you look at it, that becomes a very, very hard bug to debug. I suspect that most users and Dapp developers and library authors and whatnot probably are not watching closely on these things and they will not realize that there’s a change in behavior and the gas price field,” 

Monopoly Pricing And Miners Attack

The base fees are burnt while the miner's tips are sent to miners to include transactions in a block. Miners can sometimes monopolize pricing. This is a case where they set a minimum tip to receive. They can agree to refuse, including transactions with a certain tip on the block. Meanwhile, a good percentage of miners may not be interested in such a strategy.

EIP-1559 And Miners

The EIP-1559 has some effects on miners. Before explaining further, let's understand that, unlike the current Ethereum network where miners receive block rewards and gas fees for every block mined, the EIP-1559 only rewards miners for particular tips. That means that with the current block capacity of 12.5M, the miners will be losing more. Still, when the block space increases to complete 200% and the base fee rises and is burnt, thereby reducing the supply and increasing the value of ETH, the miner's tip will compensate for other losses.

EIP-1559 And Users

One of the prevailing myths about EIP-1559 is that it will reduce transaction fees. The fact is that it may or may not. Still, the primary aim of EIP-1559 is to deploy a complex economic model to solve the unpredictability of the current transaction model. Besides that, it aims to provide a better monetary policy for users and the network. This way, it reduces the supply of ETH, the native token of the protocol, such that it becomes more attractive to investors.
Since the network's capacity is increased from 12.5M to 25M, the network has more block space. The more utilized the block space is, the higher the base fee to be burnt. This goes a long way to help improve monetary policy.
Simply put, EIP-1559 helps make a more predictable transaction fee possible, unlike the current transaction model where users bid. It ensures a refund if the Fee Cap is more than the Maximum fee and gives feedback to the network when the base fee is burnt.

Conclusion

EIP-1559 is a widely debated Ethereum improvement proposal. It comes with so many advancements and improvements to the Ethereum protocol. They include deploying a more complex economic model and real-time blockchain usage to allow DApps and wallets algorithmically determine fees using the base fee, Fee cap, and priority tip benchmarks. It also increases the network capacity and monetary policy because it makes ETH more attractive to investors and positions it for better market competition in the long run.

You may also read on our latest publication Nexus Mutual.