Git Product home page Git Product logo

foundry-simple-storage-f23's Introduction

Foundry Simple Storage

This is part of the Cyfrin Updraft Solidity Blockchain Course.

Updraft | Foundry Simple Storage

⭐️ YouTube (6:23:59) | Section 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
  • 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)
    • You should also be able to run anvil --version and see a response like anvil 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. Setup your anvil chain by running the following in your terminal:
anvil

You'll get a large output where the ending looks something like:

==================

31337

Base Fee
==================

1000000000

Gas Limit
==================

30000000

Genesis Timestamp
==================

1717267365

Listening on 127.0.0.1:8545
  1. Copy the number at the end of Listening on XXX and place it into your .env file similar to what's in .env.example, and add an http:// to it.

.env Example:

RPC_URL=http://127.0.0.1:8545
  1. Scroll up in the anvil output, and you'll see a section that looks like this:
Private Keys
==================

(0) 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
(1) 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
(2) 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
(3) 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
(4) 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
(5) 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
(6) 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
(7) 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
(8) 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
(9) 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6

Wallet
==================
Mnemonic:          test test test test test test test test test test test junk
Derivation path:   m/44'/60'/0'/0/

Grab the top key and place it into your .env.

.env Example:

PRIVATE_KEY=11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a

  1. Compile your code

Run

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

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. DO NOT USE A KEY ASSOCIATED WITH REAL FUNDS. If you plan to, follow the instructions laid out in this section:
    1. Never use a .env again
    2. Or this one
  2. Go to Alchemy and create a new project on the testnet of choice (ie, Sepolia)
  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, Sepolia)
  5. Run
forge create SimpleStorage --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>

zkSync instructions

Prerequisites

  • foundry-zksync
    • You'll know you've done it right if you can run forge-zksync --version and you see a response like forge-zksync 0.0.2 (816e00b 2023-03-16T00:05:26.396218Z)
  • docker
    • You'll know you've done it right if you can run docker --version and you see a response like Docker version 20.10.7, build f0df350
  • nodejs & npm
    • You'll know you've done it right if you can run node --version and you see a response like v14.17.0
    • Additionally, you'll know you've done it right if you can run npm --version and you see a response like 6.14.13

Run a local zkSync test node

  1. Setup the config
npx zksync-cli dev config 

Select in-memory node and no additional plugins.

  1. Run the node
npx zksync-cli dev start

If you get an error like: Command exited with code 1: Error response from daemon: dial unix docker.raw.sock: connect: connection refused, this means docker is not running.

Deploy to zkSync

forge create src/SimpleStorage.sol:SimpleStorage --rpc-url  http://127.0.0.1:8011 --private-key xxx --legacy --zksync

or

forge script script/DeploySimpleStorage.s.sol --private-key xxx --rpc-url http://127.0.0.1:8011 --legacy --zksync --broadcast

Thank you!

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

ETH/zkSync/Arbitrum/Optimism/etc Address: cyfrin1.eth: 0x3846c3A30E62075Fa916216b35EF04B8F53931f6 (Confirm the ENS matches the address!)

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

foundry-simple-storage-f23's People

Contributors

patrickalphac avatar robocrypter avatar vengateshs avatar yyy20119 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

foundry-simple-storage-f23's Issues

I can't initiate forge directories

Hello
I was following the tutorial but when I reached the initiation of forge I typed
forge init
nothing created but instead I got this
`FORGE - training program for SNAP (version 2006-07-28)

usage: forge [options] [options]
options:
-help
-verbose
-pseudocount [1] (absolute number for all models)
-pseudoCoding [0.0] (eg. 0.05)
-pseudoIntron [0.0]
-pseudoInter [0.0]
-min-counts [0]
-lcmask [-fragmentN]
-utr5-length [50]
-utr5-offset [10]
-utr3-length [50]
-utr3-offset [10]
-explicit [250]
-min-intron [30]
-boost (file of ID )`
Kindly feedback me whats the issue

How to connect WSL Anvil to Windows Chrome Metamask?

It kind of bugs me that Windows is second class here, and you have to run CLI tools in WSL (like Foundry) but interacting with the blockchain is Metamask and that's in (actual)Windows Chome/Firefox/Brave.

Metamask is not accepting either the Ganache or the Anvil RPC. I can only assume it's because one is in WSL and one is in actual Windows.

Ganache was installed properly for WSL, at least it seems so. Followed Microsoft's instructions to install in WSL and it launched.
But it doesn't have a GUI - that's WINDOWS (again). So I also installed the Windows Ganache so I access the GUI. Tried pointing Ganache to both the WSL ethernet and also "all" (0.0.0.0) but Metamask doesn't see an RPC on either of those methods.

Metamask also doesn't seem to see the Anvil RPC.

Any tips here on what to do?
Why is blockchain development seemingly Mac/Linux only and zero care for anyone on Windows? I thought blockheads wanted mass adoption.... I'm sorry but you're not going to get "mass" with Mac/Linux only!

NB: I do have a Mac and was tinkering some time back, but the Mac is 10.13.6 and not updated for reasons. Sadly this means Foundry won't install on it. And the tools I was tinkering with (Brownie etc) are either deprecated or on their way out. Road closed to any non-current Mac/Unix people.

Don't have lib & forge-std in my folder

Dear all,

I was doing the learning Solidity video but I encountered an error where I am unable to

import "forge-std/Script.sol"

because I dont have lib folder & script in my folder

Furthermore, running

forge install foundry-rs/forge-std

returns me an error

The target directory is a part of or on its own an already initialized git repository,
and it requires clean working and staging areas, including no untracked files.

I apologize in advance if my formatting for this question is bad. This is my first time asking/writing something on Github

Cast Call for interacting with deployed contract

I'm trying to interact with a deployed contract using terminal in VS code. I can successfully deploy a contract. cast send command also works fine with store() function. but when I try to use cast call for retrieve() function, I get 0x everytime.below is my code:

cast call 0x90193C961A926261B756D1E5bb255e67ff9498A1 "retrieve()"

but all I get is:

0x

I have also tried to store different values and then retrieve them, but nothings changed.
I also check the retrieve() spelling and copy the exact function name from the main contract.

Any help would be appreciated.

Foundry setup in vs code

Hi People,
when I typed "curl -L https://foundry.paradigm.xyz | bash" in my terminal to install foundry i am facing the following error

...
curl -L https://foundry.paradigm.xyz | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:02:11 --:--:-- 0
curl: (28) Failed to connect to raw.githubusercontent.com port 443 after 130511 ms: Connection timed out
...

Kindly help

Compiler version must be fixed

Hello guys, awesome course!

  • Currently at lesson 6. Foundry ran properly.
  • Forge, Anvil, Cast and Chisel are installed.
  • The issue occur when I copy paste SimpleStorage.sol in src:
4:1: SyntaxError: Source file requires different compiler version (current compiler is 0.4.17+commit.bdeb9e52.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version\npragma solidity 0.8.19;\n^---------------------^\n",
	"startLineNumber": 4,
	"startColumn": 2,
	"endLineNumber": 4,
	"endColumn": 2
}]

I also have compiler version must be fixed.

It's been a couple of hours that I'm stuck on this and can't seems to find what I must do.

Tried to reinstalled solc but everytime I do so and look for the version I receive: command not found.

Not sure but since Foundry seems to have an integrated compiler (I'm beginning guys) I think that might be the reason why. I'm also running the code on a MacBook Pro High Sierra which I think might be the issue.

Any suggestions?

Anvil doesn't compile on Windows due to IPC

Hey guys!

Just in case, if anyone ran into this error while installing foundry components directly from their Github simply use this command and you'll be fine (i'm sharing this cuz it took me 2 hours to find the reason):

$ cargo install --git https://github.com/foundry-rs/foundry --locked anvil --features ethers/ipc

This command will fetch the latest dependencies from the master branch of foundry github and simply be adequate to handle the error. Then after the command succeeded you can foundryup and/or follow along.

Thanks everyone and enjoy the lovely course!

Deploy script doesn't deploy. Is there some update to Foundry since recording?

Doing EXACTLY what Patrick says
forge script script/DeploySimpleStorage.s.sol
gives

Error: 
contract source info format must be `<path>:<contractname>` or `<contractname>`

Instead you should just do
forge script DeploySimpleStorage
So I assume there was some kind of update with Forge and syntax for deployement.

NB the error also isn't so helpful. I wasn't sure if the error was with my command in bash, or with one of the imports paths in the deploy script. As both (in this example at least) are a very simple path/filename.sol format, so to me it could have been either, IMO at least. This has been true of my experience with Foundry so far - the errors are all kind of vague.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.