Skip to content

Instantly share code, notes, and snippets.

@alexroan
Created June 10, 2018 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexroan/2e107b05735c197e579a9e4042f9ea9c to your computer and use it in GitHub Desktop.
Save alexroan/2e107b05735c197e579a9e4042f9ea9c to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.0;
//keyword library
library IntExtended{
function increment(uint _base) returns(uint){
return _base+1;
}
function decrement(uint _base) returns(uint){
return _base-1;
}
function incrementByValue(uint _base, uint _value) returns(uint){
return _base+_value;
}
function decrementByValue(uint _base, uint _value) returns(uint){
return _base-_value;
}
}
pragma solidity ^0.4.0;
//import statement
import "browser/library.sol";
contract testLibrary{
// use <libraryName> for <extendedClass>
using IntExtended for uint;
function testIncrement(uint _base) returns(uint){
//Because it's a library functon for uint the first parameter
//is used as the base object here.
//It could be written like this also:
//reutrn IntExtended.increment(_base);
return _base.increment();
}
function testIncrementByValue(uint _base, uint _value) returns(uint){
return _base.incrementByValue(_value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment