Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 1021 Bytes

libraries.md

File metadata and controls

55 lines (36 loc) · 1021 Bytes

Libraries

Changing contract storage from inside of the Library

library CounterLib {
    struct Counter { uint i; }

    function incremented(Counter storage self) returns (uint) {
        return ++self.i;
    }
}

contract CounterContract {
    using CounterLib for CounterLib.Counter;

    CounterLib.Counter counter;

    function increment() returns (uint) {
        return counter.incremented();
    }
}

more details on it here: Library driven development


Emitting events from the Library

library EventEmitterLib {
    function emit(string s) {
        Emit(s);
    }
    
    event Emit(string s);
}

contract EventEmitterContract {
    using EventEmitterLib for string;
    
    function emit(string s) {
        s.emit();
    }
    
    event Emit(string s);
}

more details on it here: Library driven development