Skip to content

Storing and reading contract address uses more gas#

Informational

The contract address is stored to ds.contractInfo.canvasStorage. It is then read from storage multiple times in libraries. Reading from storage costs 2100 gas, whereas using address(this) uses just 2 gas. It is stated, that the address is stored, so libraries can use it. Since calls to libraries are essentially executed as delegateCall, using address(this) in a library contract will give the address of the contract which is executing the code. That address is the same as ds.contractInfo.canvasStorage.

Recommendation#

Remove the ds.contractInfo.canvasStorage state variable and use address(this) where you need the contract address instead.