Testing your contract on a local Hardhat network is fine during development. When you’re ready for the real testnet, you need real accounts, real ETH (testnet ETH), and a node provider like Infura to broadcast your transactions.
TL;DR: Deploy a Solidity smart contract to Sepolia testnet using Hardhat and Infura.
Stack: Hardhat, Solidity, Infura, Sepolia, dotenv
Level: Intermediate
Reading time: ~8 min
Get Infura project URL
Create an Infura account at infura.io, create a new project, and copy the Sepolia endpoint URL. It looks like https://sepolia.infura.io/v3/YOUR_PROJECT_ID.
Configure .env
INFURA_URL=https://sepolia.infura.io/v3/YOUR_PROJECT_ID
SECRET=your twelve word mnemonic phrase here
Configure hardhat.config.ts
import dotenv from "dotenv";
dotenv.config();
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
const config: HardhatUserConfig = {
solidity: "0.8.24",
defaultNetwork: "local",
networks: {
local: {
url: "http://127.0.0.1:8545",
chainId: 31337,
accounts: { mnemonic: "test test test test test test test test test test test junk" }
},
sepolia: {
url: process.env.INFURA_URL,
chainId: 11155111,
accounts: { mnemonic: process.env.SECRET }
}
}
};
export default config;
Deploy to Sepolia
# Add to package.json scripts:
# "deploy:sepolia": "npx hardhat ignition deploy ignition/modules/YourContract.ts --network sepolia"
npm run deploy:sepolia
What you’ve built
A smart contract deployed to Sepolia testnet via Infura. The contract address is now publicly accessible on the Sepolia network and you can interact with it from any web3 frontend.
Next steps
- Verify the contract on Etherscan Sepolia so others can read the source code.
- Never commit your mnemonic or private key. Add .env to .gitignore before the first commit.
- After testing on Sepolia, the mainnet deployment uses the same process with a mainnet network config and real ETH.
Questions or feedback? Find me on LinkedIn or GitHub.