Is it safe to hardcode an Ethereum address in a smart contract for access control purposes? #210
Answered
by
marceontech
joanthecoder
asked this question in
General
-
Is it safe to hardcode an Ethereum address in a smart contract for access control purposes? |
Beta Was this translation helpful? Give feedback.
Answered by
marceontech
Jul 30, 2025
Replies: 1 comment
-
It’s not recommended to hardcode an Ethereum address in a smart contract for access control. While technically is valid, this approach is inflexible and unsafe in a real-world use. so if the wallet is lost or compromised, there is no way to change the address without redeploying the contract (unless using upgradeable patterns). A better practice would be:
address public owner;
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}
function transferOwnership(address newOwner) external onlyOwner {
owner = newOwner;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
joanthecoder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It’s not recommended to hardcode an Ethereum address in a smart contract for access control.
While technically is valid, this approach is inflexible and unsafe in a real-world use.
so if the wallet is lost or compromised, there is no way to change the address without redeploying the contract (unless using upgradeable patterns).
And it also breaks maintainability and limits decentralization or governance.
A better practice would be:
owner
and protect sensitive functions withonlyOwner
.transferOwnership()
.Ownable
for secure patterns.