Skip to content

Instantly share code, notes, and snippets.

@critesjosh
Created May 14, 2018 21:49
Show Gist options
  • Select an option

  • Save critesjosh/38eaa0168049ce1ce58f2cd5e72f4d6b to your computer and use it in GitHub Desktop.

Select an option

Save critesjosh/38eaa0168049ce1ce58f2cd5e72f4d6b to your computer and use it in GitHub Desktop.
Two greeter contracts. One referencing a library, the other not.
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