When is a contract constructor called?
Asked Answered
T

1

5

From this solidity doc I know that the constructor is called once when the contract is created. But are there other instances that the constructor is called?

I am looking for all possible cases that the constructor of a contract will be called to better understand the use of a constructor in smart contracts and the consequences of not having a constructor.

Torose answered 2/9, 2018 at 17:28 Comment(0)
E
7

No. As it say in the docs, constructor is called only once.

When a contract is created, its constructor (a function declared with the constructor keyword) is executed once.

It would be a huge security breach if it could be called more than once, since constructor usually sets up contract ownership and other important variables.

Parity hack happened exactly because it was possible to call the "constructor" multiple times using delegatecall.

Eolian answered 2/9, 2018 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.