This Project is a section of Cyfrin Solidity Course.
It was build to learn and understand foundry under the guidance of Patrick Collins, (Smart Contract Engineer, Auditor and Educator)
For more information, visit Cyfrin Solidity Course or
Lesson 10: Foundry Our Token for enlightment
Table of Contents
- LocalToken | F24 Project
- Introduction
- Getting Started
- Usage
- Deploying to a testnet or mainnet
- Thank you!
Welcome to LocalToken | Foundry 24 This is an educational project designed to explore the intricacies of blockchain technology and smart contract development. Created as a learning experiment, LocalToken adheres to the ERC20 standard in Foundry, a powerful tool for developing smart contracts.
The README provides detailed instructions for getting started, deploying, testing, and interacting with smart contracts on various networks. This hands-on project is a great opportunity to master Foundry and its applications in real-world scenarios as part of the Cyfrin Solidity Course.
- git
- run
git --versionin the terminal and you see a response likegit version x.x.xyou have git installed. else, click on git to get full on instructions.
- run
- foundry
- similarly run
forge --versionand if you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)yo got foundry down. else, click on foundry.
- similarly run
In order to deploy the Lott contract, we deploy the script that we created by runing the following command:
forge script script/Deploy.s.sol
or you can use the following command if you are using included Makefile.
note: to display all shorcuts in the
Makefileyou can usemake helpcommand.
make deploy
In this project we cover the following testing strategies:
- Unit
- Staged
foundry has a built in test runner that we can use to run our tests. which can be done using the following command:
- to run all tests
forge test
- to run a specific test
forge test --match-test testFunctionName
dont forget to add test at the beginning of the test function name.like for example
function testFunctionName() public {}
function test_functionName() public {}
both ways works.
to run the test in a diffrent network, we can use the following command:
forge test --fork-url $SEPOLIA_RPC_URL
note : we are conducting tests in a sepollia test network. and
$SEPOLIA_RPC_URLis an environment variable that we set in the.envfile which contains the url of the sepollia test network.
this is more like a grading for our contract and we can run the command to check coverage.
forge coverage
we run it see how much the tests we done is 'enough' but (0 % is bad).
additionally, we can use the following command to get a report on the coverage. which will be useful to write test for the contract.
forge coverage --report debug > coverage.txt
-
Seting up environment variables
set up your
SEPOLIA_RPC_URLandPRIVATE_KEYas environment variables. You can add them to a.envfile in the root of the project. for example:SEPOLIA_RPC_URL=https://eth-mainnet.alchemyapi.io/v2/your-api-key PRIVATE_KEY=your-private-key
-
PRIVATE_KEY: The private key of your account (like from metamask).note : dont be a dum_dum, please create a test account with test ETH and use it.
-
SEPOLIA_RPC_URL: This is url of the sepolia testnet node you're working with. You can get setup with one for free from AlchemyOptionally : add your
ETHERSCAN_API_KEYif you want to verify and interact with your contract on Etherscan.
-
Get testnet ETH
go to faucets.chain.link and get some testnet ETH. You should see the ETH show up in your metamask account. if you are having difficulty in metamask watch this vedio from Patrick Collins.
dont be like mr crabs and hoard test ETH, use them sparingly.
-
Deploy
here we deploy the contract to a sepolia testnet by running the following command:
forge script script/Deploy.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY
You can estimate how much gas things cost by running:
forge snapshot
And you'll see an output file called .gas-snapshot in your project directory.
peace and blessing be upon you friend. I would take this opportunity to sing praises to my mentor but i want you to see it for you self. If you appreciated this project,dont give me any credits. all i want you to do is to check out sir Patrick Collins foundry course f23.
link to his bio