Skip to content

Commit

Permalink
wip day-4
Browse files Browse the repository at this point in the history
  • Loading branch information
LeTamanoir committed Dec 31, 2023
1 parent 873707c commit 031f5e1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 85 deletions.
52 changes: 16 additions & 36 deletions P2P/day04/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

**Day purposes**

✔ Create a hardhat project to setup your ethereum development environment
✔ Create a foundry project to setup your ethereum development environment

✔ Create an ERC 721 smart contract

✔ Build your application to interact with your contract


## Introduction

**What is Hardhat ?**

[Hardhat](https://hardhat.org) is a tool that will help you build your decentralized apps on an ethereum environment. Hardhat helps you compile, deploy your smart contracts and many other useful things. It is also helpful in the development phase to use local networks.
Decentralized applications are applications that interact with the blockchain. For example when you want to swap some tokens on uniswap, you are using a decentralized application. The goal of this day is to create your own decentralized application that will interact with your ERC 721 smart contract.

## Step 0 - Setup

Please refer to [SETUP.md](SETUP.md) file.



## Step 1 - Connecting your wallet to your web application

### 📑 **Description**:
Expand All @@ -29,20 +24,18 @@ The goal of this task is to connnect your wallet to your web application and be

### 📌 **Tasks**:

- Create a button that will ask you to connect your metamask wallet to the website
- Create a button that will ask you to connect your wallet to the website
- Display your account's balance
- Display your account's address

### 📚 **Documentation**:

Check out the [documentation](https://docs.ethers.org/v5/getting-started/#getting-started--connecting) of ethersjs to connect your wallet.
Check out the [documentation](https://viem.sh/docs/getting-started.html) of viem and their [examples](https://github.com/wevm/viem/tree/main/examples) to connect your wallet.

### ✔️ **Validation**:

You can now ask to the user to connect their wallet and display information about it on the page !



## Step 2 - Smart Contract

### 📑 **Description**:
Expand All @@ -63,8 +56,6 @@ Refer to this [page](https://www.openzeppelin.com/contracts) to create your smar

Your smart contract is created and deployed on the goerli testnet !



## Step 3 - Calling your smart contract's functions from your application

### 📑 **Description**:
Expand All @@ -78,13 +69,11 @@ The first one we are going to call is the `mint` function, which will let us cre

### 📚 **Documentation**:

Quick tip: You can pass an additional object when calling your smart contract's function and a `value` property. 😉
Get the ABI of your smart contract and use it with `viem` to call the `mint` function on your smart contract.

### ✔️ **Validation**:

You minted your first NFT and can now see it in your collection in your [opensea testnet](https://testnets.opensea.io/account) account. <!-- markdown-link-check-disable-line -->


You minted your first NFT and can now see it in your collection in your [opensea testnet](https://testnets.opensea.io/account) account.

## Step 4 - Let's see our NFTs

Expand All @@ -100,14 +89,12 @@ Minting NFTs is fun, but we want to see them now right ? Let's do it !

### 📚 **Documentation**:

To display react components from a list, check out the [map() function](https://reactjs.org/docs/lists-and-keys.html#embedding-map-in-jsx) to iterate through an array and display elements out of it.
Check out the [sveltkit docs](https://kit.svelte.dev/docs/routing) to learn more about routing.

### ✔️ **Validation**:

You can now see all your NFTs on a new `/collection` page.



## Step 5 - Transferring NFTs

### 📑 **Description**:
Expand All @@ -120,39 +107,32 @@ Let's send an NFT to your friends !

### 📚 **Documentation**:

Check out the [ERC721 OpenZeppelin doc](https://docs.openzeppelin.com/contracts/2.x/api/token/erc721) and find the
Check out the [ERC721 OpenZeppelin doc](https://docs.openzeppelin.com/contracts/2.x/api/token/erc721) and find the transfer function.

### ✔️ **Validation**:

You can now send an NFT to another address ! Well done !!




## Bonus - Styling

Your application might not look really good. Use some stylesheets to make it beautiful !

There are a lot of ways to add style with react. Feel free to try one of the following :
[Standard CSS](https://developer.mozilla.org/en-US/docs/Web/CSS)
[Chakra UI](https://chakra-ui.com/)
[Styled Components](https://styled-components.com/)

Your application might not look really good. Use some styles to make it beautiful !
If you don't use tailwind, I will look for you, I will find you, and ... I will kill you !

## Conclusion

Well done ! You've accomplished a lot today, and there is so much more to discover.
Refer to the official documentations to deep-dive into these technologies :
- [React](https://reactjs.org/docs/getting-started.html)
- [Ethersjs](https://docs.ethers.org/v5/)
- [Solidity](https://docs.soliditylang.org/en/v0.8.17/)

- [Svelte](https://svelte.dev/docs/)
- [Viem](https://viem.sh/docs/getting-started.html)
- [Solidity](https://docs.soliditylang.org/en/v0.8.23/) (you should despise this website as it is made with chakra UI and we all know chakra UI is dog poop)

Hope you enjoyed this day !

## Authors

| [<img src="https://github.com/alexandregrare.png?size=85" width=85><br><sub>Alexandre Grare</sub>](https://github.com/alexandregrare) | [<img src="https://github.com/Toumi-Elyes.png?size=85" width=85><br><sub>Elyes Toumi</sub>](https://github.com/Toumi-Elyes) | [<img src="https://github.com/tonida-rodda.png?size=85" width=85><br><sub>Toni Da-Rodda</sub>](https://github.com/tonida-rodda) |
| :---: | :---: | :---: |
| [<img src="https://github.com/letamanoir.png?size=85" width=85><br><sub>Martin Saldinger</sub>](https://github.com/letamanoir) | [<img src="https://github.com/alexandregrare.png?size=85" width=85><br><sub>Alexandre Grare</sub>](https://github.com/alexandregrare) | [<img src="https://github.com/Toumi-Elyes.png?size=85" width=85><br><sub>Elyes Toumi</sub>](https://github.com/Toumi-Elyes) | [<img src="https://github.com/tonida-rodda.png?size=85" width=85><br><sub>Toni Da-Rodda</sub>](https://github.com/tonida-rodda) |
| :----------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------: |

<h2 align=center>
Organization
Expand Down
112 changes: 63 additions & 49 deletions P2P/day04/SETUP.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,92 @@
## Create your web application with react
```sh
npx create-react-app my-dapp
```
### This installation will take a while, do not worry.
# Setup - Foundry & VSCode extension & Svelte setup

```sh
cd my-app
npm install --save-dev hardhat # Install hardhat in your project
npx hardhat # Press enter and accept everything, this will create your hardhat project
npm install @openzeppelin/contracts # OpenZeppelin is a great tool and a standard for blockchain development. It makes creating smart contracts very easy with their blueprints smart contracts
```
[Foundry](https://book.getfoundry.sh/) is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. We will need it throughout the pool.

## Download foundry

- Open your terminal and type

```sh
npm install react-router-dom # This will be helpful to build multiple pages in your app
npm install @chakra-ui/react @emotion/react @emotion/styled framer-motion #For the style of your website
```bash
curl -L https://foundry.paradigm.xyz | bash
```

## Infura
This will download foundryup.

Infura is a powerful tool that helps you interact with blockchain. In our case, it will make it easy to call functions on the ethereum blockchain.
- Then, you can download foundry by running `foundryup`
- If everything went fine you should be able to use `forge`, `anvil`, `chisel` and `cast`.
- If you are on macos you will need to install `libusb` with

## Installation
```bash
brew install libusb
```

After the installation, run the following command to ensure it has been properly installed on your computer:

```bash
forge --version
```

Go on [Infura](https://www.infura.io/), login and create a project
It should print your current version.

Create new key
If you have some troubles during the installation, you can refer to the [official documentation](https://book.getfoundry.sh/getting-started/installation).

Select network : Web3 API
## Create a foundry project

Give it a name and you're ready to go !
Once everything is done, you can create a new project using

You're on the dashboard
```bash
forge init new_project
cd new_project
```

Under Ethereum, click on mainnet and select Görli
This should create a new directory with a brand new foundry project

Copy the link and paste it in the hardhat.config.js
If you already have a repository, you might need to add

```bash
--no-commit
```

The first thing you wants to do is set the solidity version of this project in the `foundry.toml` file wich is the configuration file of foundry.

hardhat.config.js:
```js
require("@nomicfoundation/hardhat-toolbox");
You can do this by adding in the "[profile.default]" section:

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.9",
defaultNetwork: "goerli",
etherscan: {
apiKey: "FILL-IN-ETHERSCAN-API-KEY"
},
networks: {
goerli: {
url: "https://goerli.infura.io/v3/FILL-IN-INFURA-PROJECT-URL",
accounts: ["FILL-IN-INFURA-API-KEY"]
}
}
};
```toml
solc_version = "0.8.20"
```

## VSCode Integration

I recommand you to install [solidity vscode extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity), it is an extension that simplifies development in Solidity.

## Metamask
Also, I recommand you to use the extension formatter. It will format your code on save, which allows you to have a clean codebase. To do so:

Download [Metamask extension](https://metamask.io/)
- Create a `.vscode/settings.json` file with this content

Copy your private key under the 3 dots menu > account details > export private key
```json
{
"editor.formatOnSave": true,
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
}
}
```

Paste it in the hardhat.config.js file.
## Create a sveltekit application

Assuming you already have `nodejs` and `pnpm` installed, create a new sveltekit application.
Checkout the [svelte and sveltekit tutotial](https://learn.svelte.dev/tutorial/welcome-to-svelte) if tou are a noob.

## Faucets
```bash
pnpm create svelte@latest if_you_copy_paste_this_you_are_a_sheep
```

### What are faucets ?
Install the packages we will need

Faucets let you earn fake money that can be used on testnet networks. They will be very useful since you need money to pay the transaction fees on the blockchain.
```bash
pnpm add viem
```

Get some ether on [Goerli Faucet](https://goerlifaucet.com/). They will appear shortly on your account (on the goerli test network) <!-- markdown-link-check-disable-line -->
## Back to the workshop

[Jump !](./README.md)

0 comments on commit 031f5e1

Please sign in to comment.