Created
May 14, 2018 21:49
-
-
Save critesjosh/38eaa0168049ce1ce58f2cd5e72f4d6b to your computer and use it in GitHub Desktop.
Two greeter contracts. One referencing a library, the other not.
This file contains hidden or 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
| pragma solidity ^0.4.0; | |
| contract GreeterA { | |
| string greeting; | |
| uint count; | |
| address[] greeted; | |
| function GreeterA(string _greeting) { | |
| greeting = _greeting; | |
| } | |
| function greet() public returns (string) { | |
| count += 1; | |
| greeted.push(msg.sender); | |
| return greeting; | |
| } | |
| } | |
| library GreeterLib { | |
| struct Greeting { | |
| string greeting; | |
| uint count; | |
| address[] greeted; | |
| } | |
| function greet(Greeting storage self, address who) public returns (string) { | |
| self.count += 1; | |
| self.greeted.push(who); | |
| return self.greeting; | |
| } | |
| } | |
| contract Greeter { | |
| GreeterLib.Greeting greeting; | |
| function Greeter(string _greeting) { | |
| greeting.greeting = _greeting; | |
| } | |
| function greet() public returns (string) { | |
| return GreeterLib.greet(greeting, msg.sender); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment