Created
February 23, 2024 21:24
-
-
Save bthaile/0fe1cb6b2d72e87d171fbdbe8fa2adb8 to your computer and use it in GitHub Desktop.
HelloWorld.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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