qinpeng2 / foundry-simple-storage-f23

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Foundry Simple Storage

This is part of the Cyfrin Solidity Blockchain Course.

⭐️ (6:23:59) | Lesson 6 | Foundry Simple Storage

Getting Started

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • ganache
    • You'll know you did it right if you can run the application and see:
      ganache
    • You can alternatively use ganache-cli or hardhat
  • foundry
    • You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)

Optional Gitpod

If you can't or don't want to run and install locally, you can work with this repo in Gitpod. If you do this, you can skip the clone this repo part.

Open in Gitpod

Setup

Clone this repo

git clone https://github.com/Cyfrin/foundry-simple-storage-f23
cd foundry-simple-storage-f23

Usage

  1. Run your ganache local chain, by hitting quickstart on your ganache application

Save the workspace. This way, next time you open ganache you can start the workspace you've created, otherwise you'll have to redo all the steps below.

  1. Copy the RPC SERVER sting in your ganache CLI, and place it into your .env file similar to what's in .env.example.

ganache

.env Example:

RPC_URL=http://0.0.0.0:8545
  1. Hit the key on one of the accounts, and copy the key you see and place it into your .env file, similar to what you see in .env.example.

ganache

ganache

.env Example:

PRIVATE_KEY=11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a

  1. Compile your code

Run

forge compile
  1. Deploy your contract
forge create --private-key <PRIVATE_KEY>

Windows, WSL, & Ganache

If you're using WSL, for the ganache UI you'll have to use a different endpoint. You have 4 options to fix this:

  1. Use the WSL endpoint on the ganache UI (this sometimes doesn't work)
  2. Use anvil (We will move to anvil at some point anyways...)

Deploying to a testnet

Make sure you have a metamask or other wallet, and export the private key.

IMPORTANT

USE A METAMASK THAT DOESNT HAVE ANY REAL FUNDS IN IT. Just in case you accidentally push your private key to a public place. I highly recommend you use a different metamask or wallet when developing.

  1. Export your private key and place it in your .env file, as done above.

  2. Go to Alchemy and create a new project on the testnet of choice (ie, Goerli)

  3. Grab your URL associated with the testnet, and place it into your .env file.

  4. Make sure you have testnet ETH in your account. You can get some here. You should get testnet ETH for the same testnet that you made a project in Alchemy (ie, Goerli)

  5. Run

forge create --private-key <PRIVATE_KEY> --rpc-url <ALCHEMY_URL>

Or, you can use a deploy script!

forge script script/DeploySimpleStorage.s.sol --private-key <PRIVATE_KEY> --rpc-url <ALCHEMY_URL>

Thank you!

If you appreciated this, feel free to follow me or donate!

ETH/Arbitrum/Optimism/Polygon/etc Address: 0x9680201d9c93d65a3603d2088d125e955c73BD65

Patrick Collins Twitter Patrick Collins YouTube Patrick Collins Linkedin Patrick Collins Medium

About


Languages

Language:Solidity 100.0%