Estimated completion time: ~15 minutes
If you're new to blockchain development or simply want to learn how to deploy and interact with smart contracts, this guide is for you. We'll walk you through creating and deploying a simple smart contract on the Sepolia test network using tools like Metamask, Solidity, Hardhat, and Alchemy.
Prerequisites
Before diving into the smart contract code, ensure you complete these installations (Steps 1โ9):
- Alchemy Account: Sign up for a free Alchemy account to interact with the Ethereum blockchain.
- Virtual Wallet: Install Metamask to manage your Ethereum address.
- Test ETH: Use the Sepolia faucet to fund your wallet with test ETH.
Step-by-Step Deployment
Step 1: Set Up Your Alchemy App
- Navigate to your Alchemy Dashboard and create a new app.
- Name it Hello World, select Ethereum as the chain, and choose Sepolia as the network.
Step 2: Initialize Your Project
Create a project folder and run:
npm init -yInstall Hardhat:
npm install --save-dev hardhatStep 3: Write the Smart Contract
- Create a file
HelloWorld.solin thecontracts/folder. Use this 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; } }
Step 4: Configure Environment Variables
Create a .env file with:
- Metamask Private Key
- Alchemy HTTP API URL
Example:
PRIVATE_KEY="YOUR_PRIVATE_KEY"
API_URL="https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY"Step 5: Deploy the Contract
- Run
npx hardhat compileto ensure your code works. Execute the deploy script:
npx hardhat run scripts/deploy.js --network sepolia
FAQs
Q1: How do I get test ETH for Sepolia?
A: Use the Sepolia faucet while connected to the Sepolia network in Metamask.
Q2: Why is my contract deployment failing?
A: Verify your .env file has the correct private key and API URL. Also, ensure you have sufficient test ETH.
Q3: Whatโs the difference between Sepolia and Mainnet?
A: Sepolia is a test network for developers, while Mainnet is the live Ethereum blockchain.
๐ Explore advanced smart contract interactions
Next Steps
- Interact with Your Contract: Call the
updatefunction to change the stored message. - Publish to Etherscan: Verify your contract for public transparency.
For feedback or questions, reach out via Alchemy Support.
Happy coding! ๐
### Key SEO Keywords
- Smart contract deployment
- Ethereum Sepolia testnet
- Hardhat tutorial
- Solidity Hello World