0

Is there anyway to figure out what was the address used at construction time and find it in the bytecode? For example I know that for libraries they are storing it in the contract in order to be able later to compare this stored address to the address upcode and revert the transaction if some non pure/view function are directly called (instead of delegatecalled). Can it be done in a normal contract without having to manually store the contract address?

2
  • No, the way I showed you here (ethereum.stackexchange.com/a/128931/84305) is the only practical way. Decompiling a library contract shows that this is exactly what they do to ensure a revert on a direct call. They just have an implicit constructor doing that immutable variable logic. But it's the only practical way for now. You could pre-compute your contract address and hard code it, but that serves the same purpose and is just much less convenient...
    – hroussille
    Commented May 28, 2022 at 12:56
  • Great thank you hroussille (btw I upvoted you but it doesnt show because I dont have enough reputation)
    – maxime
    Commented May 29, 2022 at 4:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.