I am going through the solidity docs and I have seen that:

    // Functions can
    // be accessed directly or through `this.f`,
    // but the latter provides an external view
    // to the function. Especially in the constructor,
    // you should not access functions externally,
    // because the function does not exist yet.

At what circumstances should you use this in a constructor?

1 Answer 1


You can do this:

constructor() {

function foo() public {

but you cannot do this:

constructor() {
  this.foo(); // external call to non-existant function

function foo() external {

foo() is indeed available as an external function from functions but the constructor doesn't "write" the code until the end, so foo() does not exist until the constructor is finished.

Hope it helps.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.