Skip to content

Instantly share code, notes, and snippets.

@bthaile
Created February 23, 2024 21:24
Show Gist options
  • Save bthaile/0fe1cb6b2d72e87d171fbdbe8fa2adb8 to your computer and use it in GitHub Desktop.
Save bthaile/0fe1cb6b2d72e87d171fbdbe8fa2adb8 to your computer and use it in GitHub Desktop.
HelloWorld.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HelloWorld {
// Declare a public field of type string.
string public greeting;
// Constructor to initialize the greeting.
// In Solidity, the constructor is defined with the "constructor" keyword.
constructor() {
greeting = "Hello, World!";
}
// Public function to change the greeting.
// The "public" keyword makes the function accessible from outside the contract.
function changeGreeting(string memory newGreeting) public {
greeting = newGreeting;
}
// Public function that returns the greeting.
// In Solidity, explicit return types are declared.
function hello() public view returns (string memory) {
return greeting;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment