The HelloWorld contract is the classic starting point for BitGov. It stores a single greeting string on-chain and exposes functions to read and update it.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
contract HelloWorld {
string private _message;
event MessageChanged(string newMessage);
constructor(string memory initialMessage) {
_message = initialMessage;
}
function getMessage() external view returns (string memory) {
return _message;
}
function setMessage(string memory newMessage) external {
_message = newMessage;
emit MessageChanged(newMessage);
}
}| Concept | Meaning |
|---|---|
pragma solidity ^0.8.28 |
Specifies the minimum compiler version |
string private _message |
A state variable — stored permanently on-chain |
constructor(...) |
Runs once at deployment |
external view |
Read-only function; no gas cost when called off-chain |
emit MessageChanged(...) |
Fires an event — cheap, indexable log entry on the blockchain |
npx hardhat ignition deploy ignition/modules/intro/HelloWorld.ts --network localhostThe deployment module passes "Hello, World!" as the initial message. Note the address printed at the end of the output — you will need it for the console session below.
npx hardhat nodenpx hardhat ignition deploy ignition/modules/intro/HelloWorld.ts --network localhost
# Deployed HelloWorldModule#HelloWorld at 0x5FbDB2315678afecb367f032d93F642f64180aa3npx hardhat console --network localhostIn Hardhat v3, ethers is accessed via the network global that the console provides.
const { ethers } = await network.connect();const hw = await ethers.getContractAt("HelloWorld", "0x5FbDB2315678afecb367f032d93F642f64180aa3");await hw.getMessage();
// 'Hello, World!'await hw.setMessage("Hello, BitGov!");
await hw.getMessage();
// 'Hello, BitGov!'