From ea86588dba275c86f399a9e3c60bf7ce63dae827 Mon Sep 17 00:00:00 2001 From: Jonathan Le Brun <42697488+icyfry@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:34:19 +0200 Subject: [PATCH] Config and scripts --- .env.template | 10 ++++++---- .gitignore | 3 +++ README.md | 8 +++++--- Taskfile.yml | 41 +++++++++++++++++++++++++++++++++++++---- contracts/.gitignore | 1 + contracts/foundry.toml | 7 +++++++ 6 files changed, 59 insertions(+), 11 deletions(-) diff --git a/.env.template b/.env.template index 9957070..b59300d 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,6 @@ -# 0x.... -PUBLIC_KEY_LOCAL= -# Anvil -RPC_URL=http://127.0.0.1:8545 +PUBLIC_KEY= +RPC_URL= +ETHERSCAN_API_KEY= +# Contracts +FUNDME_ADDRESS= +CRYPTOZOMBIES_ADDRESS= diff --git a/.gitignore b/.gitignore index ed41fc1..b26bdd1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # Dotenv file .env +.env.local +.env.mainnet +.env.sepolia .password diff --git a/README.md b/README.md index 1ca5e49..259b97f 100644 --- a/README.md +++ b/README.md @@ -62,17 +62,19 @@ Test call with cast for Cryptozombies cast call 0x... "getZombiesByOwner(address _owner)" "0x..." ``` +### Gas + +Create a gas usage snapshot file `.gas-snapshot` with `forge snapshot` + ## Run Contracts and Frontend Launch a local testnet node, see [Anvil doc](https://book.getfoundry.sh/reference/anvil/) ``` anvil ``` -Build and deploy contracts on local testnet +Build and deploy contracts ``` task contracts-build contracts-deploy-script -or -task contracts-build contracts-deploy ``` Launch frontend ``` diff --git a/Taskfile.yml b/Taskfile.yml index b982228..f05a21d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,6 +1,9 @@ version: '3' -dotenv: ['.env'] +env: + ENV: local + +dotenv: ['.env', '.env.{{.ENV}}'] tasks: @@ -19,15 +22,26 @@ tasks: cmds: - forge test -vvv --gas-report + contracts-gas: + dir: contracts + cmds: + - forge snapshot + contracts-deploy-script: dir: contracts/script cmds: - forge script --rpc-url {{.RPC_URL}} --account defaultKey - --sender {{.PUBLIC_KEY_LOCAL}} + --sender {{.PUBLIC_KEY}} --broadcast --password-file "../.password" DeployZombieOwnership + - forge script --rpc-url {{.RPC_URL}} + --account defaultKey + --sender {{.PUBLIC_KEY}} + --broadcast + --password-file "../.password" + DeployFundMe contracts-deploy: dir: contracts @@ -36,8 +50,27 @@ tasks: --account defaultKey --password-file ".password" src/cryptozombies/zombieownership.sol:ZombieOwnership - # --interactive - # --private-key {{.PRIVATE_KEY_LOCAL}} + + fundme-FundFundMe: + dir: contracts/script + cmds: + - forge script --rpc-url {{.RPC_URL}} + --account defaultKey + --sender {{.PUBLIC_KEY}} + --broadcast + --password-file "../.password" + InteractionsFundMe.s.sol:FundFundMe + + fundme-WithdrawFundMe: + dir: contracts/script + cmds: + - forge script --rpc-url {{.RPC_URL}} + --account defaultKey + --sender {{.PUBLIC_KEY}} + --broadcast + --password-file "../.password" + InteractionsFundMe.s.sol:WithdrawFundMe + frontend-build: dir: dapp cmds: diff --git a/contracts/.gitignore b/contracts/.gitignore index 93ca55a..df91897 100644 --- a/contracts/.gitignore +++ b/contracts/.gitignore @@ -3,6 +3,7 @@ cache/ out/ bin/ broadcast/ +.gas-snapshot # Ignores development broadcast logs !/broadcast diff --git a/contracts/foundry.toml b/contracts/foundry.toml index efd6832..ee97df6 100644 --- a/contracts/foundry.toml +++ b/contracts/foundry.toml @@ -5,3 +5,10 @@ libs = ["lib"] solc = "0.8.20" # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options + +[etherscan] +mainnet = { key = "${ETHERSCAN_API_KEY}" } +sepolia = { key = "${ETHERSCAN_API_KEY}" } + +[rpc_endpoints] +sepolia = "${SEPOLIA_RPC_URL}"