Skip to content

Instantly share code, notes, and snippets.

@nodlAndHodl
Last active February 4, 2022 05:29
Show Gist options
  • Save nodlAndHodl/0572c9a9f9c8f7d8ebf96cea643e9f4c to your computer and use it in GitHub Desktop.
Save nodlAndHodl/0572c9a9f9c8f7d8ebf96cea643e9f4c to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.11+commit.d7f03943.js&optimize=false&runs=200&gist=
pragma solidity >=0.8.10;
contract FunctionsContract {
string ownerName;
uint8 ownerAge;
// Constructor
constructor (string memory name, uint8 age) public {
ownerName = name;
ownerAge = age;
}
// We are changing the owner name and age
function setOwnerInfo(string memory name, uint8 age) public {
ownerName = name;
ownerAge = age;
}
function secretFunction() private pure {
// Not available outside this contract
}
// Get owner name and age
function getOwnerInfo() public view returns (string memory name, uint8 age){
name = ownerName;
age = ownerAge;
}
// Get the name
// 2 ways to return values from a function
function getOwnerName() public view returns (string memory) {
return ownerName;
}
// Get the age
function getOwnerAge() public view returns (uint8 age){
age = ownerAge;
}
}
@nodlAndHodl
Copy link
Author

access modifiers

  • public
  • private
  • view/constant - returns data but does not modify data
  • pure - function will not modify or read data
  • payable - can send ether to

@nodlAndHodl
Copy link
Author

visibility

  • public - visible outside the contract
  • private - visible with contracnt
  • internal - can only be accessed within contract (almost like static)
  • external - cannot be called internally (does not apply to storage)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment