Skip to content

Instantly share code, notes, and snippets.

@sepisoltani
Created October 6, 2021 15:43
Show Gist options
  • Save sepisoltani/883d638a3bde231f3a7687aeddf0e869 to your computer and use it in GitHub Desktop.
Save sepisoltani/883d638a3bde231f3a7687aeddf0e869 to your computer and use it in GitHub Desktop.
contract Example{
function sayHiToVitalik(string memory _name) public returns (string memory) {
// Compares if _name equals "Vitalik". Throws an error and exits if not true.
// (Side note: Solidity doesn't have native string comparison, so we
// compare their keccak256 hashes to see if the strings are equal)
require(keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("Vitalik")));
// If it's true, proceed with the function:
return "Hi!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment