Deploy a Smart Contract local on Anvil with Foundry in 2 min

Published: 31 December 2023
on channel: Raza Zaidi
1,073
21

🚀 In today's quick tutorial, I'll show you how to deploy a smart contract using Foundry's forge CLI - all in just 2 minutes! This video is perfect for anyone looking to enhance their Foundry skills in a short, digestible format. Whether you're a beginner or an experienced developer, these steps will guide you through the process seamlessly.

👇 Steps to Follow:

Initialize Foundry: Start by setting up your environment with forge init.
Existing Git Projects: For already initialized Git projects, use forge init —no-commit.
Start Anvil: Open your code editor's terminal and type anvil.
Prepare Your Workspace: Clear the src, script, and test directories.
Add Your Contract: Place your smart contract in the src folder. (I'm using the EtherWallet contract from Solidity by Example.)
Build Your Contract: In a new terminal, run forge build to compile your contract.
Deploy with Forge: Execute forge create CONTRACTNAME —interactive to deploy.
Use Anvil's Private Key: Copy a private key from the Anvil terminal and paste it into the deployment terminal.
Deployment Complete: Your contract is now deployed to Anvil!
Note on Anvil: Forge create defaults to Anvil if it's running; otherwise, you'll encounter an error.
🌟 Want to level up your Foundry skills even further? Check out the challenge below and don't forget to share your progress!

🔗 Socials:

Twitter: @razacodes
Website: www.razacodes.com
Instagram: @razacodes
TikTok: @razacodes