I want to deploy a new contract. I have another contract with kill() function. Can I call selfdestruct on my new contract constructor and pay less gas fees? How?
Asked
Active
Viewed 296 times
0
M M
- 57
- 7
1 Answers
1
A selfdestruct refunds 24000 gas (https://ethereum.stackexchange.com/a/859/31933). I'm not sure how much gas is used by creating a reference to the other contract and calling its kill function, but probably you'll end up paying less.
This of course means that the contract to be self destroyed needs to first exist. Deploying such a contract will definitely cost more than 24000 gas - my very rough estimate is maybe 100000.
So, if you have in advance deployed a contract which can be self destroyed by you, you will possibly save a bit of gas by destroying the contract while deploying another contract (inside the constructor).
Lauri Peltonen
- 29,391
- 3
- 20
- 57
-
Thanks Lauri for your quick and complete answer – M M Aug 02 '21 at 17:41