Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 2. 🧱Building the Smart Contract.md #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,63 +1,24 @@
# Getting Started
Getting Started
===============

## **🧱Building the Smart Contract**
##### 🧱Building the Smart Contract

## Setting Up The Environment
Setting Up The Environment
--------------------------

So first things first, let’s create a directory for our project.
Go to your command line and enter these commands
(WSL is recommended for easier installation in Windows)

```bash
mkdir nft-collection
cd nft-collection
```
`mkdir nft-collection cd nft-collection`

Time to set up npm in our project. We will use the node package manager to easily download and manage our dependencies.

```bash
npm init
```
`npm init`

Just use the default values for all the installation questions and press enter.

```
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (nft-collection)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /mnt/d/Blockchain Development/Metaschool Gig/nft-collection/package.json:

{
"name": "nft-collection",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC"
}


Is this OK? (yes)
```
![](https://metaschool.s3-ap-southeast-1.amazonaws.com/images/5acNyl08tQkyUa9tHWF3ety8yIBGORi2vNtZjN6x.gif)

Once you have completed installation, you should see a package.json file in your nft-collection directory.

Expand All @@ -73,87 +34,42 @@ Blockchain is like a public database and our smart contracts live on that databa

Publishing a contract directly on blockchain for learning purposes will be an expensive deal. Every time we create a new contract, edit the contract or publish it on the blockchain, we incur some cost in the form of ETH, or MATIC. In order to avoid that and test the contracts properly, we will create a test environment which pretty much replicates the production environment, is free to use, and easy to access.

For this purpose, we will use [HardHat](https://hardhat.org/). Hardhat gives you a local Ethereum network designed for rapid development. It allows you to deploy your contracts, run your tests and debug your code without spending a dime. How cool is that? 😊
For this purpose, we will use [HardHat](https://hardhat.org/). Hardhat gives you a local Ethereum network designed for rapid development. It allows you to deploy your contracts, run your tests and debug your code without spending a dime. How cool is that? 😊

So let’s install it using this command

```bash
npm install --save-dev hardhat
```
`npm install --save-dev hardhat`

You can check out the [hardhat documentation](https://hardhat.org/getting-started/) for any help with installation.
You can check out the [hardhat documentation](https://hardhat.org/getting-started/) for any help with installation.

Awesome, now let’s set up hardhat by running this command inside our project folder.

```bash
npx hardhat
```
`npx hardhat`

Since we will be constructing this project from scratch. Just create an **empty hardhat config** file during installation.
Since we will be constructing this project from scratch. Just create an **empty hardhat config** file during installation.

```
888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 "88b 888P" d88" 888 888 "88b "88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888

👷 Welcome to Hardhat v2.11.2 👷‍

? What do you want to do? - Create an empty hardhat.config.js
✨ Config file created ✨
```
`888 888 888 888 888 888 888 888 888 888 888 888 888 888 888 8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888 888 888 "88b 888P" d88" 888 888 "88b "88b 888 888 888 .d888888 888 888 888 888 888 .d888888 888 888 888 888 888 888 Y88b 888 888 888 888 888 Y88b. 888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888 👷 Welcome to Hardhat v2.11.2 👷‍ ? What do you want to do? - Create an empty hardhat.config.js ✨ Config file created ✨`

Once you have installed hardhat, quickly create 2 new directories - contracts and scripts in your root directory using these commands. The contracts directory will have all your smart contracts and the scripts directory will have all the scripts related to deployment of the contract.

```bash
mkdir contracts
mkdir scripts
```
`mkdir contracts mkdir scripts`

## Installing OpenZeppelin
Installing OpenZeppelin
-----------------------

And this might be the most important thing yet - [OPENZEPPELIN](https://www.openzeppelin.com/)
And this might be the most important thing yet - OPENZEPPELIN
Openzeppelin is a library used for secure and efficient smart contract development.

It is very time consuming to code the ERC721 contract from scratch. So we use already completed and security audited smart contracts from openzeppelin

So quickly download openzeppelin using this command

```bash
npm install @openzeppelin/contracts
```
`npm install @openzeppelin/contracts`

👏👏 Well done! we have done so much in such a small time.

This is how your project folder will look like now.

```
NFT-collection
-> cache
-> contracts
-> node_modules
-> scripts
- hardhat.config.js
- package-lock.json
- package.json
```

We will come back to hardhat soon, but before that we need to answer a question.

I can write, compile and test my smart contract all day on my own computer but how do I connect to the ethereum network?

Do I have to set up my own ethereum node on my server?

Won’t that be too complicated?

### Assignment

#### 🚨 Progress Report

Share screenshot of HardHat installation
`NFT-collection -> cache -> contracts -> node_modules -> scripts - hardhat.config.js - package-lock.json - package.json`

**Your response is**
Are you excited for the next lesson?