Last active
May 10, 2021 16:02
-
-
Save TomiOhl/b16a2c8b06c5ac8134d08e9253dba113 to your computer and use it in GitHub Desktop.
An experiment to see how much do gas costs differ for the same action via different approaches
This file contains 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.4; | |
interface IUniSwapRouter02 { | |
function WETH() external pure returns (address); | |
} | |
contract ExternalPureTest { | |
address internal uniAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; | |
address public addr = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; | |
// Set variable to an address given in place | |
// Gas usage: 23475 | |
function getFromInline() external { | |
addr = 0xc778417E063141139Fce010982780140Aa0cD5Ab; | |
} | |
// Set variable to an address from an external call | |
// Gas usage: 26902 | |
function getFromExternal() external { | |
addr = IUniSwapRouter02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D).WETH(); | |
} | |
// Set variable to an address from an external call, whose address is read from a storage variable | |
// Gas usage: 29101 | |
function getFromExternalWithStorageVar() external { | |
addr = IUniSwapRouter02(uniAddress).WETH(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment