If you're new to blockchain development and wondering where to begin, this guide walks you through creating and deploying a simple smart contract on the Ethereum Goerli test network. We'll use common tools like MetaMask, Solidity, Hardhat, and Alchemy—all explained in simple terms.
What You'll Need
Before starting, ensure you have:
- A basic understanding of command-line operations
- Node.js and npm installed on your system
- Approximately 15 minutes of free time
Step 1: Set Up Your Alchemy Account
Alchemy provides a developer platform and API that lets you interact with the Ethereum blockchain without running your own node. It offers monitoring and analytics tools useful for understanding smart contract deployments.
👉 Create a free developer account here
Step 2: Create an Application and API Key
After signing up, generate an API key by creating a new app. This key allows requests to the Goerli test network.
- Navigate to your Alchemy Dashboard
- Hover over "Apps" and click "Create App"
- Name it "Hello World," add a short description, choose "Staging" environment, and select "Goerli" network
- Click "Create app" to generate your API key
Step 3: Set Up MetaMask Wallet
MetaMask is a browser-based wallet that manages Ethereum addresses. You'll need it to handle transactions.
- Download and install MetaMask
- Create a new account or use an existing one
- Switch to the Goerli Test Network (upper-right corner)
- Secure your seed phrase and private key
Step 4: Acquire Test ETH
Since we're using a test network, you'll need fake ETH from a faucet:
- Visit the Goerli faucet
- Enter your Goerli account address from MetaMask
- Click "Send Me ETH"
- Wait for transaction confirmation (may take several minutes)
Step 5: Verify Your Balance
Confirm you received test ETH using Alchemy's composer tool:
- Input your MetaMask address
- Use the eth_getBalance method
- Check the response contains your balance in wei (1 ETH = 10^18 wei)
Step 6: Initialize Your Project
Create your project directory and initialize it with npm:
mkdir hello-world
cd hello-world
npm initAnswer the configuration questions or use npm init --yes for default settings.
Step 7: Install Hardhat
Hardhat is a development environment for compiling, testing, and debugging Ethereum software:
npm install --save-dev hardhatStep 8: Create Hardhat Configuration
Initialize Hardhat in your project:
npx hardhatSelect "Create an empty hardhat.config.js" when prompted.
Step 9: Create Project Structure
Organize your project with two directories:
mkdir contracts
mkdir scriptsThe contracts folder will hold your Solidity code, while scripts will contain deployment and interaction scripts.
Step 10: Write Your Smart Contract
Create HelloWorld.sol in the contracts directory:
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.7.3;
contract HelloWorld {
event UpdatedMessages(string oldStr, string newStr);
string public message;
constructor(string memory initMessage) {
message = initMessage;
}
function update(string memory newMessage) public {
string memory oldMsg = message;
message = newMessage;
emit UpdatedMessages(oldMsg, newMessage);
}
}This contract stores a message that can be updated through the update function.
Step 11: Configure Environment Variables
Install dotenv to manage sensitive information:
npm install dotenv --saveCreate a .env file with your Alchemy API URL and MetaMask private key:
API_URL = "https://eth-goerli.alchemyapi.io/v2/your-api-key"
PRIVATE_KEY = "your-metamask-private-key"Step 12: Install Ethers.js
Ethers.js simplifies interactions with Ethereum:
npm install --save-dev @nomiclabs/hardhat-ethers "ethers@^5.0.0"Step 13: Update Hardhat Configuration
Modify hardhat.config.js to include your network settings:
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY } = process.env;
module.exports = {
solidity: "0.7.3",
defaultNetwork: "goerli",
networks: {
hardhat: {},
goerli: {
url: API_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
}
};Step 14: Compile Your Contract
Verify everything works by compiling:
npx hardhat compileAddress any warnings or errors before proceeding.
Step 15: Create Deployment Script
In the scripts folder, create deploy.js:
async function main() {
const HelloWorld = await ethers.getContractFactory("HelloWorld");
const hello_world = await HelloWorld.deploy("Hello World!");
console.log("Contract deployed to address:", hello_world.address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});Step 16: Deploy Your Contract
Run the deployment script:
npx hardhat run scripts/deploy.js --network goerliSave the deployed contract address displayed in the output.
Step 17: Verify Deployment
Check your contract on Goerli Etherscan by searching for your contract address. You should see:
- Contract creation transaction
- Your MetaMask address as the sender
- Successful deployment status
Understanding the Process
Behind the scenes, Hardhat and Ethers.js made several JSON-RPC calls:
- eth_sendRawTransaction to write your contract to the blockchain
- eth_getTransactionByHash to check transaction status
👉 Explore advanced deployment strategies
Frequently Asked Questions
What is a smart contract?
A smart contract is self-executing code deployed on a blockchain that automatically executes terms when predetermined conditions are met. They enable trustless transactions without intermediaries.
Why use a test network?
Test networks provide fake cryptocurrency for development and testing without financial risk. They mimic mainnet behavior while allowing developers to experiment freely.
How much does it cost to deploy a smart contract?
Deployment costs gas fees, which vary based on network congestion and contract complexity. On test networks, you use fake ETH, while mainnet deployment requires real ETH.
What can I do with my deployed contract?
You can interact with it through Web3 applications, call its functions, read its state, and build user interfaces that connect to your contract address.
How do I update my contract after deployment?
Smart contracts are immutable by design. You cannot change deployed code, but can design upgrade patterns using proxy contracts or deploy new versions with migration capabilities.
What's the difference between Hardhat and Truffle?
Both are development frameworks, but Hardhat offers more advanced debugging features and built-in network support, while Truffle has a more established ecosystem with additional tools.
Next Steps
After successful deployment, consider:
- Adding more complex functionality to your contract
- Writing tests to verify contract behavior
- Building a frontend interface to interact with your contract
- Learning about security best practices for smart contracts
Remember that practice and experimentation are key to mastering smart contract development. Start with simple contracts and gradually increase complexity as you become more comfortable with the development process.