Hello World Smart Contract for Beginners – Full Guide

·

Creating your first smart contract can feel like stepping into uncharted territory. But with the right tools and guidance, deploying and interacting with a blockchain-based application is not only achievable—it's empowering. This comprehensive tutorial walks you through building, deploying, and integrating a "Hello World" smart contract on Ethereum’s Goerli test network using Solidity, Hardhat, Alchemy, and a frontend powered by React.

Whether you're a complete beginner or transitioning from traditional web development, this guide breaks down every step—from setting up your wallet to connecting your dApp’s frontend—so you gain hands-on experience in full-stack blockchain development.

Setting Up Your Development Environment

Before writing any code, ensure your development environment is ready. You’ll need:

👉 Get started with blockchain development tools and APIs today.

Create an Alchemy App and API Key

  1. Sign up at Alchemy (free tier available).
  2. From the dashboard, click Apps > Create App.
  3. Name it Hello World, select Staging and Goerli as the network.
  4. Confirm Goerli is selected—this ensures compatibility with test ETH and MetaMask.

Your app will generate an HTTP API URL. Save this—you'll use it later in your configuration file.

Set Up MetaMask with Test ETH

  1. Install the MetaMask extension if you haven't already.
  2. Switch to the Goerli Test Network (top-right menu).
  3. Visit a Goerli faucet and enter your wallet address to receive test ETH.
  4. Wait a moment—the faucet may be slow due to network congestion.

To verify your balance:

Now that your tools are ready, let’s initialize the project.

Building and Deploying Your Smart Contract

Smart contracts are self-executing programs on the blockchain. We'll use Solidity—the most popular language for Ethereum—to write one.

Initialize Project and Install Hardhat

In your terminal:

mkdir hello-world
cd hello-world
npm init -y
npm install --save-dev hardhat
npx hardhat

Select "Create an empty hardhat.config.js" when prompted. This creates the base configuration file.

Organize Project Structure

Create two folders:

mkdir contracts scripts

Write the Hello World Smart Contract

In contracts/HelloWorld.sol, paste the following Solidity code:

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:

Configure Hardhat and Connect Wallet

Install dependencies:

npm install dotenv --save
npm install --save-dev @nomiclabs/hardhat-ethers ethers@^5.0.0

Create a .env file in the root:

API_URL="https://eth-goerli.alchemyapi.io/v2/YOUR_API_KEY"
PRIVATE_KEY="YOUR_METAMASK_PRIVATE_KEY"

⚠️ Never commit .env files to version control.

Update hardhat.config.js:

require("dotenv").config();
require("@nomiclabs/hardhat-ethers");

const { API_URL, PRIVATE_KEY } = process.env;

module.exports = {
  solidity: "0.7.3",
  defaultNetwork: "goerli",
  networks: {
    goerli: {
      url: API_URL,
      accounts: [`0x${PRIVATE_KEY}`],
    },
  },
};

Compile and Deploy the Contract

Compile the contract:

npx hardhat compile

Create scripts/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);
  });

Deploy:

npx hardhat run scripts/deploy.js --network goerli

Save the output address—you’ll use it later.

Check deployment on Goerli Etherscan by searching the contract address.

Interacting with Your Deployed Smart Contract

Now that your contract lives on-chain, let’s interact with it programmatically.

Read and Update the Message

Install Ethers.js:

npm install --save-dev @nomiclabs/hardhat-ethers ethers@^5.0.0

Create scripts/interact.js:

const { API_URL, PRIVATE_KEY, CONTRACT_ADDRESS } = process.env;
const contract = require("../artifacts/contracts/HelloWorld.sol/HelloWorld.json");

const alchemyProvider = new ethers.providers.AlchemyProvider("goerli", API_URL);
const signer = new ethers.Wallet(PRIVATE_KEY, alchemyProvider);
const helloWorldContract = new ethers.Contract(CONTRACT_ADDRESS, contract.abi, signer);

async function main() {
  const message = await helloWorldContract.message();
  console.log("The message is:", message);

  console.log("Updating the message...");
  const tx = await helloWorldContract.update("This is the new message.");
  await tx.wait();

  const newMessage = await helloWorldContract.message();
  console.log("The new message is:", newMessage);
}

main();

Run it:

npx hardhat run scripts/interact.js --network goerli

You’ll see:

The message is: Hello World!
Updating the message...
The new message is: This is the new message.

Verifying Your Contract on Etherscan

Verification allows others to view your source code and trust your dApp.

Generate Etherscan API Key

  1. Sign up at Etherscan.io.
  2. Go to Profile > API Keys > Add, name it hello-world, and copy the key.
  3. Add it to .env:
ETHERSCAN_API_KEY="YOUR_ETHERSCAN_KEY"

Install Hardhat Etherscan plugin:

npm install --save-dev @nomiclabs/hardhat-etherscan

Update hardhat.config.js:

require("@nomiclabs/hardhat-etherscan");

// Inside module.exports:
etherscan: {
  apiKey: ETHERSCAN_API_KEY,
}

Verify:

npx hardhat verify --network goerli DEPLOYED_CONTRACT_ADDRESS "Hello World!"

Once verified, anyone can inspect your contract on Etherscan.

Integrating with a Frontend Using React

Let’s build a simple dApp UI where users can read and update the message.

Set Up React Project

Clone starter files:

git clone https://github.com/alchemyplatform/hello-world-part-four-tutorial.git
cd hello-world-part-four-tutorial/starter-files
npm install

Start dev server:

npm start

Open http://localhost:3000.

Connect Wallet and Read Data

In src/util/interact.js, set up Alchemy Web3:

require("dotenv").config();
const alchemyKey = process.env.REACT_APP_ALCHEMY_KEY;
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(alchemyKey);

const contractABI = require("../contract-abi.json");
const contractAddress = "YOUR_DEPLOYED_CONTRACT_ADDRESS";

export const helloWorldContract = new web3.eth.Contract(contractABI, contractAddress);

Add functions for interaction:

export const loadCurrentMessage = async () => {
  const message = await helloWorldContract.methods.message().call();
  return message;
};

export const connectWallet = async () => {
  if (window.ethereum) {
    try {
      const addressArray = await window.ethereum.request({ method: "eth_requestAccounts" });
      return { address: addressArray[0], status: "Write a message above." };
    } catch (err) {
      return { address: "", status: err.message };
    }
  } else {
    return { address: "", status: "Install MetaMask." };
  }
};

In HelloWorld.js, update useEffect:

useEffect(async () => {
  const message = await loadCurrentMessage();
  setMessage(message);
}, []);

👉 Explore more dApp development tools and resources here.

Frequently Asked Questions

What is a smart contract?

A smart contract is a self-executing program stored on a blockchain that runs when predefined conditions are met. It enables trustless, transparent interactions without intermediaries.

Why use Goerli testnet?

Goerli is a proof-of-authority Ethereum test network used for testing dApps before deployment to mainnet. It uses free test ETH, reducing risk during development.

How do I get test ETH?

Visit faucets like FaucETH or Alchemy Faucet. Enter your Goerli wallet address to receive test tokens.

What is Hardhat?

Hardhat is a development environment for compiling, testing, and deploying Ethereum software. It includes built-in tasks and debugging tools ideal for local development.

Can I deploy to Ethereum mainnet?

Yes—after testing, switch configurations in hardhat.config.js to use mainnet RPC URLs and unlock accounts with real ETH. Always audit code before mainnet deployment.

How do I fix “insufficient funds” errors?

Ensure your MetaMask wallet has enough test ETH on Goerli. Double-check that your private key in .env matches the funded account.


By following this guide, you've built, deployed, and connected a full-stack blockchain application—from Solidity logic to interactive frontend. With these foundational skills, you're ready to explore DeFi, NFTs, DAOs, and beyond.

Keep building—and remember, every expert was once a beginner.

👉 Continue learning advanced blockchain concepts with real-world tools.