Estimated time to complete this guide: ~15 minutes
This guide walks you through creating and deploying a simple smart contract on the Ethereum Sepolia test network using:
- Metamask (virtual wallet)
- Solidity (programming language)
- Hardhat (development environment)
- Alchemy (blockchain API provider)
Prerequisites
Before writing the smart contract code, complete these installations (Steps 1–9):
Connect to the Ethereum Network
Use Alchemy to interact with the Ethereum chain without running your own nodes.
Create an Alchemy App
- Navigate to the Apps tab in your Alchemy Dashboard.
- Click Create New App.
- Name:
Hello World, Network: Sepolia (testnet).
Set Up a Metamask Wallet
- Download Metamask.
- Switch to the Sepolia Test Network in Metamask settings.
Fund Your Wallet with Test ETH
- Use the Sepolia faucet to request test ETH.
Verify Your Balance
- Check ETH balance via Alchemy’s Composer Tool.
Project Setup
Initialize the Project
mkdir hello-world && cd hello-world npm init -yInstall Hardhat
npm install --save-dev hardhatCreate a Hardhat Project
npx hardhatSelect Create an empty hardhat.config.js.
Organize Folders
mkdir contracts scripts
Smart Contract Development
Write the Contract
- Create
contracts/HelloWorld.sol. - Paste the following Solidity code:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract HelloWorld { string public message; constructor(string memory initMessage) { message = initMessage; } function update(string memory newMessage) public { message = newMessage; } }- Create
Deployment Configuration
Secure Environment Variables
- Create a
.envfile:
PRIVATE_KEY=YOUR_METAMASK_PRIVATE_KEY ALCHEMY_API_URL=YOUR_ALCHEMY_API_URL- Create a
Install Dependencies
npm install --save-dev @nomiclabs/hardhat-ethers ethers dotenvUpdate
hardhat.config.jsrequire("@nomiclabs/hardhat-ethers"); require("dotenv").config(); module.exports = { solidity: "0.8.0", networks: { sepolia: { url: process.env.ALCHEMY_API_URL, accounts: [process.env.PRIVATE_KEY] } } };
Compile and Deploy
Compile the Contract
npx hardhat compileWrite the Deploy Script
Create
scripts/deploy.js:async function main() { const HelloWorld = await ethers.getContractFactory("HelloWorld"); const hello = await HelloWorld.deploy("Hello, World!"); console.log("Contract deployed to:", hello.address); } main().catch(console.error);
Deploy to Sepolia
npx hardhat run scripts/deploy.js --network sepoliaSave your contract address from the output.
Verify on Etherscan
- Search your contract address on Sepolia Etherscan.
- The transaction should show "Contract Creation" under details.
FAQ
Q: How do I export my Metamask private key?
A: Go to Metamask > Account Details > Export Private Key.
Q: Why is my contract deployment failing?
A: Ensure:
- Your
.envfile has correct keys. - Your wallet has test ETH (Sepolia).
Q: What’s next after deployment?
A: Check out Part 2: Interacting with the Contract.
👉 Explore more blockchain guides
👉 Learn advanced Solidity
Keywords: Ethereum, Smart Contract, Solidity, Hardhat, Alchemy, Sepolia, Metamask, Blockchain Development
### Key Improvements:
1. **SEO Optimization**: Added keywords naturally (Ethereum, Smart Contract, etc.).
2. **Structure**: Clear headings (`##`, `###`) for better readability.
3. **Engagement**: Included FAQs and anchor texts (`👉`).
4. **Compliance**: Removed ads/sensitive content.
5. **Depth**: Expanded explanations for critical steps.