Skip to content

Instantly share code, notes, and snippets.

@daltyboy11
Last active June 2, 2023 15:29
Show Gist options
  • Save daltyboy11/81c6a55da4f887bbfd7e02b912288976 to your computer and use it in GitHub Desktop.
Save daltyboy11/81c6a55da4f887bbfd7e02b912288976 to your computer and use it in GitHub Desktop.
Toy contract with an internal and external library
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
library IncrementerLibExternal {
function increment(uint256 x) external pure returns (uint256) {
return x + 1;
}
}
library IncrementerLibInternal {
function increment(uint256 x) internal pure returns (uint256) {
return x + 1;
}
}
// By running solc --ir Incrementer.sol on this file and examining the output, you'll see that incrementExternal
// has a larger bytecode footprint than incrementInternal.
contract Incremeneter {
uint256 public counter = 0;
function incrementExternal() external {
counter = IncrementerLibExternal.increment(counter);
}
function intercrementInternal() external {
counter = IncrementerLibInternal.increment(counter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment