I am just learning solidity and am getting confused by certain applications of the this keyword in functions. The general form of the functions that confuse me is below and the onlyowner modifier only allows the owner of the contract to call the function:

func myfunc() onlyowner {


  • Can this.balance only reference the owner's address's balance?
  • Or can the owner call this function and references another party's address (IE: this == other party's address)?
  • If yes can they do so selectively or only for all addresses associated with the contract?

this refers to the contract. So this.balance means the balance of the contract. It never means any other address.

  • Does this have the same effect as setting the contract owner's address in the constructor? – Vignesh Karthikeyan Jun 7 '18 at 15:07
  • I'm not sure what you mean. The this keyword refers to the contract. It's unrelated to any concept like "ownership." – smarx Jun 7 '18 at 15:08
  • I misunderstood. My bad. – Vignesh Karthikeyan Jun 7 '18 at 15:29

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.