1

I have a external method declared. At some point I realized that I need to call that external method from one of the another method within a contract and which is not possible. There are options to call an external method within a contract by using

  1. this.methodName()
  2. Change visibility of my external method to public

But I want to know which way is better.

2

There is no one way which is absolutely better.

By using an external visibility modifier, you declare intention that the function should only be used by external parties. In my opinion, using that internally with this.function() is a hack and goes against the original intention.

By changing it to public, you declare intention that the function may be used by both external parties and internal functions. You're then basically saying that the function may be used by any party (including the contract itself).

So if you wish to use the function from inside the same contract, I would simply make it public since then it conforms to your declared intentions.

1
  • Thanks for the response. That is what I was thinking of. I support your response.
    – NinjaMAN
    Aug 2 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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