This project demonstrates how to create and deploy a simple ERC20 token using Foundry, a powerful toolkit for Ethereum application development.
This project includes:
- An ERC20 token contract
- A deployment script for easy token deployment
- Configuration for multiple networks (including Ethereum testnets)
Before you begin, ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/your-username/erc20foundry.git cd erc20foundry
-
Install dependencies:
forge install
-
Create a
.env
file in the root directory with the following contents:PRIVATE_KEY=your_private_key_here_without_0x_prefix TOKEN_RECEIVER=0x_address_to_receive_initial_tokens RPC_URL=https://your-rpc-url ETHERSCAN_API_KEY=your-etherscan-api-key
Replace the values with your actual private key, token receiver address, and RPC URL.
-
Load the environment variables:
source .env
Compile the contracts:
forge build
Run the tests:
forge test -vvv
To deploy the ERC20 token:
forge script script/DeployErc20.sol:DeployERC20 --rpc-url $RPC_URL --private-key $PRIVATE_KEY --etherscan-api-key $ETHERSCAN_API_KEY --broadcast --verify -vvvv
This command will:
- Deploy the ERC20 token contract
- Transfer the initial supply to the specified receiver address
- Verify the contract on Etherscan (if supported by the network)
- Token Name: "TokenName"
- Token Symbol: "MyToken"
- Initial Supply: 1,000,000 tokens
You can modify these details in the ERC20Token.sol
file.
This project is configured to work with multiple networks, including Ethereum testnets like Sepolia. Ensure you have the correct RPC URL in your .env
file for the network you want to deploy to.
- Never commit your
.env
file or expose your private keys. - Ensure you're using a dedicated testnet account for development and testing.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.