Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. pragma solidity 0.5.1; //specifies version of solidity
  2.  
  3. contract SimpleCounter {//Doesn't have to match file name
  4. int counter;// State variable gets stored in a node in Blockchain
  5. //or: int public counter;
  6. //public here automatically creates a getter function like the function below
  7. //initialize variable with constructor
  8. constructor() public{//Public means anyone can invoke this contract
  9. counter = 0;
  10. }
  11.  
  12. function getCounter() view public returns (int){//View is like constant keyword. Function does not modify state
  13. //returns integer
  14. return counter;
  15. }
  16.  
  17. function increment() public{
  18. counter += 1;
  19. }
  20.  
  21. function decrement() public{
  22. counter -= 1;
  23. }
  24.  
  25. //Gas is a unit of computation used to change the state of the contract. Gas translates to ether you
  26. //need to pay when somene invokes a function
  27. }
  28. //Etherum stores the entire state of your program on the Blockchain
  29. //Smart contracts are programs that you can interact switch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement