From Idea to Deployment: Building, Testing, and Deploying Smart Contracts with Hardhat and Foundry

Building, testing, and deploying smart contracts with Hardhat and Foundry has become the dominant workflow for modern Ethereum engineering. Hardhat remains a widely adopted, TypeScript-friendly environment with a rich plugin ecosystem and strong deployment tooling. Foundry, written in Rust, has rapidly become a preferred choice for Solidity-native development, high-performance testing, and security-oriented workflows. For many teams, the most effective approach is not choosing one tool exclusively, but combining both across the lifecycle from initial design to mainnet deployment.
Why Hardhat and Foundry Matter in Smart Contract Engineering
Smart contract development now demands repeatable builds, fast test feedback, realistic simulations using forked state, and deployment pipelines that hold up through audits and production operations. Hardhat and Foundry address these needs, each emphasizing different strengths.

Hardhat is often the default for full-stack Web3 teams because it integrates naturally with Node.js, TypeScript, Ethers.js, and front-end workflows. Its flexibility, plugin system, and interactive console make it practical for debugging and deployments across complex stacks.
Foundry is optimized for Solidity-first teams, protocol engineers, and security researchers. It centers on forge (build and test), anvil (local node), and cast (chain interaction). Multiple independent comparisons report materially faster compilation and test execution compared to typical Hardhat setups.
For production-grade systems, treating these tools as complementary is often more effective than selecting one: Foundry for fast contract iteration and hardening, Hardhat for integration-heavy development and structured deployment operations.
Tooling Overview: What You Actually Get
Hardhat in Practice
Hardhat is a general-purpose Ethereum development environment that fits naturally into JavaScript and TypeScript repositories. Its value comes from an opinionated but extensible workflow:
Hardhat Network for local execution, snapshots, account impersonation, and mainnet forking.
Task runner and scripts for automating compile, test, verification, and deployment steps.
Large plugin ecosystem spanning Ethers.js integration, OpenZeppelin upgrades, gas reporting, contract verification, monitoring, and deployment tooling.
Hardhat Ignition for declarative, reproducible deployments with explicitly modeled dependencies, including Ledger hardware wallet integration for secure deployment flows.
Hardhat 3 introduced unified compilation of contracts and Solidity tests, which reduces compilation time and artifact size in many pipelines. An opt-out option is available when legacy plugin behavior requires separate artifacts.
Foundry in Practice
Foundry is a Solidity-centric toolkit that keeps the entire development loop close to the EVM. It is CLI-first and designed to minimize overhead:
forge for building, testing, fuzzing, scripting, and deployments.
anvil as a local Ethereum node for development and simulations.
cast for interacting with contracts and RPC endpoints directly from the terminal.
Cheatcodes exposed through a vm interface for manipulating time, block number, balances, and caller identity during tests.
Benchmarks and hands-on comparisons consistently report Foundry compiling and running tests faster than Hardhat. Chainstack measured a 26-contract project compiling in 14.56 seconds with Hardhat versus 8.53 seconds with Foundry. Three Sigma has reported Foundry tests running 2-5x faster in many configurations, attributing the gains to its Rust implementation and reduced Node.js overhead.
From Idea to Specification: The Tool-Agnostic Phase
Before selecting a framework, establish the fundamentals:
Requirements and threat model: define what the contract must do, and what must never happen.
Standards: select proven interfaces such as ERC-20, ERC-721, ERC-1155, ERC-4626, or established governance patterns where applicable.
Non-functional constraints: upgradeability strategy (proxy, UUPS, diamond), target chains (mainnet, L2s), gas budget, and auditability goals.
Tool selection often follows team composition. Front-end and Node.js teams commonly start in Hardhat, while protocol and security teams increasingly start in Foundry for iteration speed and Solidity-native testing.
Project Setup: Quick Starts That Match Real-World Repos
Hardhat Setup (Node.js and Plugins)
Hardhat fits naturally into monorepos and dapp stacks. A typical setup involves these steps:
Create a project and install Hardhat.
Choose a template and enable TypeScript if needed.
Add plugins as the workflow matures.
Common plugin choices include tool bundles for testing and Ethers.js, OpenZeppelin upgrades for proxy patterns, and deployment or verification helpers. Hardhat's configuration model supports multiple named networks (testnets, mainnet, local forks) inside a single config file, which simplifies multi-environment workflows.
Foundry Setup (Solidity-First)
Foundry initializes quickly and stays consistent across machines:
Install via foundryup.
Run forge init to generate a new repository structure.
Set compiler versions, remappings, and directories in foundry.toml.
This minimal configuration suits contract-focused repositories well. Some comparisons note that multi-network configuration is less centralized than Hardhat and is typically handled through scripts and environment variables.
Development and Local Testing: Choosing the Right Inner Loop
Hardhat Testing Workflows
Hardhat projects commonly place Solidity in contracts/ and tests in JavaScript or TypeScript using Mocha and Chai. This makes it straightforward to share fixtures and helpers with front-end code that already uses Ethers.js. Hardhat Network provides advanced local behavior that is practical for integration testing:
Snapshots and reverts for fast test isolation.
Account impersonation to simulate privileged roles or whale behavior.
Mainnet forking to test against real deployed contracts and realistic state at a chosen block height.
Hardhat's interactive console and debugging-friendly local network are consistently cited as key advantages in day-to-day development.
Foundry Testing Workflows
Foundry keeps tests in Solidity, typically in a test/ directory, and runs them with forge test. Direct EVM state control through cheatcodes is a core differentiator. Examples include:
Time and block control: warp timestamps and roll block numbers.
Identity control: impersonate callers to validate access control logic.
Balance and state control: fund accounts, snapshot, and revert quickly.
This approach reduces boilerplate and makes security scenarios easier to express clearly. Because compilation and testing run natively, many teams report a noticeably tighter feedback loop for core protocol development.
Advanced Testing and Security: Pre-Audit Hardening
As contracts move from prototype to production, testing needs shift from happy-path unit tests to adversarial validation. This is where many teams rely heavily on Foundry:
Fuzz testing to explore large input spaces and uncover edge cases.
Invariant testing to ensure system-level properties hold across sequences of actions.
Cheatcode-driven simulation for unusual state transitions, timing issues, or attacker behavior.
Hardhat remains important in this phase for end-to-end validation: testing a front-end against a forked chain, validating integrations with off-chain services, or using plugins that connect to external analysis and monitoring platforms. Many practitioner guides recommend a blended strategy - Foundry for rapid unit, fuzz, and invariant tests, followed by Hardhat for integration testing and deployment orchestration.
Deployment Strategies: Reproducibility and Operational Safety
Deploying with Hardhat (Scripts and Ignition)
Hardhat supports classic script-based deployments in TypeScript or JavaScript, which is useful when integrating with environment configuration, multisig flows, or CI/CD secrets management. For teams prioritizing reproducibility, Hardhat Ignition provides a declarative deployment model where dependencies are explicit and the process is straightforward to re-run and audit. Ignition also supports secure deployments with Ledger hardware wallet integration.
Hardhat's network configuration model is a practical advantage for multi-environment deployment pipelines, particularly when managing several testnets, L2s, and production settings within a single codebase.
Deploying with Foundry (forge script and broadcast)
Foundry deployment is lean and CLI-driven. A common workflow uses forge script to define deployment logic and broadcasts transactions to a configured RPC endpoint. This approach suits teams that want:
Solidity-centric scripting kept close to contract code.
Minimal moving parts with fast, deterministic CLI execution.
Easy terminal-based interaction using tools like cast.
This approach is particularly effective in protocol repositories where deployment logic is tightly coupled to the contracts themselves.
How to Choose: A Practical Decision Matrix
When standardizing a team workflow, these heuristics apply:
Choose Hardhat first if your project is dapp-heavy, TypeScript-first, plugin-dependent, or requires complex multi-network configuration and deployment graphs.
Choose Foundry first if your work is protocol-heavy, audit-driven, or you need fast compile-test cycles with Solidity-native fuzzing, invariant testing, and cheatcodes.
Use both when building production systems: Foundry for core contracts and security testing, Hardhat for integration tests, deployment pipelines, and application-layer tooling.
Future Direction: Convergence, Specialization, and CI/CD Maturity
The ecosystem is trending toward feature convergence. Hardhat has expanded Solidity test support and improved compilation behavior in Hardhat 3. Foundry has been expanding scripting and deployment ergonomics, narrowing the gap for end-to-end workflows. At the same time, role-based specialization is likely to persist: integration engineers gravitate toward Hardhat, while protocol and security engineers gravitate toward Foundry.
Both toolchains are increasingly embedded in CI/CD pipelines, including containerized test runners and GitHub Actions workflows that execute forge test and hardhat test. For enterprise teams, this trend supports more predictable builds, better audit trails, and safer deployment practices.
Conclusion: Build a Repeatable Pipeline from Idea to Mainnet
Building, testing, and deploying smart contracts with Hardhat and Foundry is now a core competency for Ethereum engineering teams. Foundry excels at high-speed Solidity development, fuzzing, invariant testing, and security simulation. Hardhat excels at integration-heavy workflows, plugin-based tooling, multi-network configuration, and structured deployments with Ignition. For professional teams, the strongest approach is dual-tool fluency: use Foundry to harden the protocol, and use Hardhat to validate integrations and ship reproducible deployments.
Formalizing these skills across a team benefits from structured learning paths aligned to specific responsibilities, such as Solidity development, secure smart contract engineering, and Ethereum deployment operations. Blockchain Council certifications including Certified Solidity Developer, Certified Smart Contract Auditor, and Certified Blockchain Developer provide structured learning frameworks aligned to these workflows.
Related Articles
View AllSmart Contracts
Solidity vs Rust for Smart Contracts: Choosing Between Ethereum and Solana Development
Compare Solidity vs Rust for smart contracts across Ethereum and Solana: ecosystem fit, tooling, security, performance, and practical guidance on which to learn first.
Smart Contracts
Smart Contracts for Real-World Assets (RWA): Tokenization, Compliance, and On-Chain Settlement
Learn how smart contracts for real-world assets (RWA) enable tokenization, compliance-by-design, and on-chain settlement for Treasuries, credit, funds, and real estate.
Smart Contracts
Cross-Chain Smart Contracts: Designing Interoperable dApps with Bridges, Oracles, and Messaging Protocols
Learn how cross-chain smart contracts enable interoperable dApps using bridges, oracle networks, and messaging protocols, plus key security patterns and design best practices.
Trending Articles
The Role of Blockchain in Ethical AI Development
How blockchain technology is being used to promote transparency and accountability in artificial intelligence systems.
AWS Career Roadmap
A step-by-step guide to building a successful career in Amazon Web Services cloud computing.
What is AWS? A Beginner's Guide to Cloud Computing
Everything you need to know about Amazon Web Services, cloud computing fundamentals, and career opportunities.