Last active
June 2, 2023 15:29
-
-
Save daltyboy11/81c6a55da4f887bbfd7e02b912288976 to your computer and use it in GitHub Desktop.
Toy contract with an internal and external library
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
// 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