40,000 USDC
View results
Submission Details
Severity: gas
Valid

Use hardcode address instead address(this)

Summary

[G-10] Use hardcode address instead address(this)

if the contract's address is needed in the code, it's more gas-efficient to hardcode the address as a constant rather than using the address(this) expression. This is because using address(this) requires additional gas consumption to compute the contract's address at runtime.

Here's an example :

contract MyContract {
address constant public CONTRACT_ADDRESS = 0x1234567890123456789012345678901234567890;
function getContractAddress() public view returns (address) {
return CONTRACT_ADDRESS;
}
}
file: /src/Escrow.sol
98 i_tokenContract.safeTransfer(i_seller, i_tokenContract.balanceOf(address(this)));

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L98

file: /src/Escrow.sol
110 uint256 tokenBalance = i_tokenContract.balanceOf(address(this));

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L110

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.