官术网_书友最值得收藏!

Environment setup

Let's get started with building our blockchain project. The first thing we're going to do is open our terminal and create our blockchain directory by typing commands into the terminal, as seen in the following screenshot: 

Let's begin by creating a folder called programs. Inside this folder, let's create a directory called blockchain. This directory is currently empty.  Inside of this blockchain directory is where we're going to be doing all of our programming. We are going to be building our entire blockchain inside of this blockchain directory.

Now our blockchain directory is ready, and the first thing that we need to do is to add some folders and files into it. The first folder that we want to put into the directory will be called dev, so we want to make sure that we are inside of the blockchain directory, and then let's type the following command into the terminal: 

mkdir dev

Inside this dev directory is where we are going to be doing most of our coding. This is where we're going to build our blockchain data structure and create our API to interact with our blockchain, test it, and fulfill other similar tasks. Next, inside this dev folder, let's create two files: blockchain.js and test.js.  To do this, enter the following command:

cd dev
touch blockchain.js test.js

The touch term in the preceding command line will help us in creating the mentioned files. The blockchain.js file is where we will type our code to create the blockchain and the test.js file is where we will write code to test our blockchain.

Next, let's return back to our blockchain directory by typing the following command in the terminal:

cd .. 

In the blockchain directory, let's run the following command to create the npm project: 

npm init 

After running the preceding command, you will get some options on your terminal. To set up the project, you can just press Enter through those options.

So, this is pretty much all we need to do in order to set up our project folder structure. Now, if you go to our blockchain directory and open it with a text editor such as Sublime or Atom (or whatever you would like), you will get to see the file structure, as seen in the following screenshot:

The blockchain directory consists of the dev folder that we just created. Inside the dev folder, we can observe our blockchain.js and test.js files. Also, when we run the npm init command, it creates the package.json file for us. This .json file will keep track of our project and any dependencies that we need, allowing us to run scripts. We'll be working more inside of this package.json file in further chapters, so you'll become more familiar with it as we progress through the book.

主站蜘蛛池模板: 大冶市| 大埔县| 南城县| 成武县| 惠安县| 长汀县| 濮阳县| 山东省| 安阳市| 霍邱县| 淮北市| 额敏县| 沾益县| 尉氏县| 康平县| 舟山市| 西贡区| 商河县| 岱山县| 华亭县| 云和县| 天等县| 安平县| 平果县| 拜城县| 鄢陵县| 武乡县| 富宁县| 崇州市| 长武县| 文水县| 济阳县| 万安县| 莱西市| 福州市| 正安县| 白沙| 辽阳市| 林口县| 开鲁县| 大厂|