Ultimate magazine theme for WordPress.

How to fork the Ethereum blockchain

So much has been said about Ethereum Fork. Through this article, beyond the verbal meaning of Ethereum fork, you will learn how to fork an Ethereum blockchain. However, it is still necessary to acquaint our readers with the basics of the Ethereum fork in order to keep them current on the topic.

What is an Ethereum fork?

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

If the developer intends a backwards compatible and a non-consensual fork, he should consider a soft fork, but if it is a non-backwards compatible and a 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. If two or more miners find a block at the same time, it is an accidental fork. On the other hand, a deliberate fork refers to a deliberate move to change the rules of the blockchain.

Why fork a blockchain

Blockchain can be forked for several reasons. Meanwhile, the duty of forking a blockchain is to improve scalability, decentralization, transaction costs, security, and other meaningful changes to the existing chain rather than building a new one. For example, the Ethereum blockchain itself has proven robust and robust from its borderline phase to the awaiting serenity phase and has a lot of untapped potential. Hence, forking is the best as it takes more resources, time and effort to create a similar blockchain.

Requirements for forking a blockchain

If you have ever thought about forking an Ethereum blockchain, you must meet certain requirements. The requirements for forking a blockchain range from software to hardware requirements. Below are the requirements;

Step 1; Basic knowledge of blockchain

It will be difficult to fork a blockchain you don’t know about. Every developer needs to know how the blockchain works so that he/she can fork the blockchain. For the Ethereum blockchain in particular, the developer needs to know how the Ethereum development environment works and how it interacts with other environments beyond the local environment.

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

Each blockchain has its compatible programming tools and languages. However, JavaScript, Python, and Linux command lines are the base language of most blockchains, including Ethereum.

Step 3; Windows, Linux or a Mac OS

Different blockchain forking tools are designed for different operating systems. You are expected to run on either Linux, Windows, or Mac OS. This way, you just download and install the OS version of the tool you are using. However, Linux and its distributions are more in demand and a must for the best development experience.

step 4; Ethereum client for example; Ganache GUI or Ganache CLI, RPC, Ruffle, etc.

An “Ethereum client” is just a term that refers to any node capable of analyzing and verifying the blockchain, its smart contracts, and everything related to it. It also allows you to provide interfaces to create transactions and mine blocks, which is key for any blockchain interaction. To fork an Ethereum blockchain, we will use Ganache-Cli.

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

Ethereum nodes allow you to run your own nodes, which helps you run a private, trusted, and self-sufficient application. However, it is somewhat expensive and labor intensive. Instead of going through the trouble of using Geth, Open Ethereum, etc., you can just use third-party APIs like Infura, quikNode, and the like.

Steps to fork an Ethereum blockchain

Now that you’ve met the requirements to fork the Ethereum blockchain, it’s time to get started. Here is a step-by-step guide on how to fork an Ethereum blockchain. You are expected to have something like your first Ethereum fork after working through this guide. Continue reading;

Create an Ethereum endpoint

Let’s start by choosing the Ethereum client that will help us create an Ethereum endpoint. There are different Ethereum nodes like Geth, Nethermind, Open Ethereum, Infura, QuikNode and so on. You can run your node, but that requires more resources and technical details. Therefore you can use 3rd party APIs like Infura, QuikNode, Alchemy to run your node.

For this article, we choose to build our Ethereum endpoint using Infura or QuikNode. To create the Ethereum endpoint, login to one of the third-party APIs; Infura or QuikNode and follow the process.

QuikNode

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

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

Fat

If you prefer to build your endpoint with Infura you can do the following;

  1. Sign up on Infura.io and confirm your email.
  2. Head to create a project. In this article I called the project “NewFork”.
  3. Copy the endpoint as shown in the image below.

Remember to set the endpoint to mainnet before copying the HTTP protocol.

note; Whether you’re using QuikNode or Infura, don’t forget to save the copied HTTP provider endpoint, as you’ll use it after setting up the Ganache CLI.

Download and install the Ganache CLI

Ganache CLI is one of the main components of the Turtle client. It is the Ganache Ethereum client command line interface that allows you to connect to a local blockchain to test your decentralized application. Instead of forking the mainnet 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 more secure. If you want to fork the Ethereum blockchain, you can connect to a local Ethereum blockchain. For simplicity, we’ll use 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 with 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;

Add $ yarn global ganache-cli

Fork the Ethereum mainnet

After installing Ganache-Cli, it’s time to fork the mainnet. Open your terminal/cmd and copy the following:

$ ganache-cli –fork

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

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

Branch a specific block

Make a note of the specific block in the blockchain that you want to fork. Branch it by appending “@” followed by the block number as shown below:

$ ganache-cli –fork @

Suppose we want to copy and modify a specific xDai chain that is on the Ethereum blockchain network and use xDai for gas. Go to ETHExplorer and scroll down to the owner’s section. View the largest dai holders, copy the address and run:

$ ganache-cli –fork -u

The command line above allows Ganache to fork the Ethereum blockchain and unlock the attached Dai account for the local Ganache environment (-u). Implicitly we used ganache-cli to mimic a specific account address that is normally blocked for use, which also helps us transact on the simulated blockchain from that account address.

How to query the forked coin

Impressive! You have forked a particular Dai account and will be happy to query the forked chain. By querying the forked chain, you can get specific information about the forked chain, such as: B. Transactions, gas used in the block, timestamp, address of the miner, etc.

You can do this by making an eth_getBlockByNumber call, which will return information about the block where we forked the chain.

The command should look like this;

$ curl –data ‘{“method”:”eth_getBlockByNumber”,”params”:[“0xBA29D2″,false],”id”:1,”jsonrpc”:”2.0″}’ -H “Content type: application/json” -X POST localhost:8545

After running the code shown above, your terminal should look like this;

Diploma

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

Also read; Defi 2.0: An upgrade to the first generation of Defi

Learn Crypto Trading, Yield Farms, Income strategies and more at CrytoAnswers
https://nov.link/cryptoanswers

Comments are closed.

%d bloggers like this: