The this keyword
The this keyword in Solidity is pretty similar to this in OOP, and represents a pointer to the current contract, which is explicitly convertible to an address. Moreover, all contracts inherit the members of address, thus it is possible to query the balance of the current contract using address(this).balance (you'll find this.balance in old code).
As this returns the address of the current contract, we can use it as follows: address ContractAddress = this;.
this is also used to access internally a method declared as external, otherwise the compiler won’t recognize it. In that case, the function will be called through a call message instead of being called directly via jumps.
Great, at this level, we’re nearly done with the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access