Guest User

Untitled

a guest
Jan 20th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. pragma solidity ^0.4.17;
  2. // specify the version of Solidity that our code is written with
  3.  
  4. contract Inbox {
  5. // define a new contract (almost identical to a class) that will
  6. // have some number of methods and variables
  7.  
  8. string public message;
  9. // - storage variables:
  10. // declares all of the instance variables (and their types)
  11. // that will exist in this contract
  12. // - public defines who have access to that variable
  13. // - message is the name of the variable --> the value of the variable will be
  14. // stored in the ethereum blockchain for ethernity
  15. // IN CONTRAST WITH STORAGE VARIABLES WE HAVE LOCAL VARIABLES WHICH ARE NEVER STORED IN THE BLOCKCHAIN
  16.  
  17.  
  18. function Inbox(string initialMessage) public {
  19. // this function is called constructor function since it has the same
  20. // name as the contract.
  21. // A constructor function is automatically called one time when the
  22. // contract is created. Invoked automatically when the contract is deployed
  23. message = initialMessage;
  24.  
  25. }
  26.  
  27. function setMessage(string newMessage) public {
  28. // this functions with a different name from the contract's one can be called
  29. // once the contract has been deployed on the blockchain
  30. message = newMessage;
  31. // we are modifying the message variable here so we can't use either constant and view in the function type
  32. }
  33.  
  34. // this function is unuseful since the message variable is public so solidity will
  35. // create a function for use to return the message variable's value
  36. function getMessage() public view returns (string) {
  37. // public and view are the function type declaration
  38. // most common function types --> [public, private, view, constant, pure, payable]
  39. return message;
  40. // we are just accessing data not modifying. This is why we use the view function type
  41. // so the compiler knows we only access data.
  42. // - returns (with return's type) can only be specified with functions that have
  43. // view and constant aas function type.
  44. }
  45. }
Add Comment
Please, Sign In to add comment