// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.1 <0.9.0;
contract test{
    uint public myBalance1=msg.sender.balance;
    uint public myBalance2=address(this).balance;

The output in myBalance1=99 ether
The output in myBalance2=0 ether

What is the difference between msg.sender and address(this)

2 Answers 2


address(this) is the address of the contract

msg.sender is the address of the caller of the executing code, in this case the deployer of the contract.

there's no payable function in the contract so it can't receive value


I'm assuming you just want to understand the main difference between address(this) and msg.sender

Consider you want the address of the caller who is calling the smart contract function, in that case you will use global variable of solidity msg.sender within your function which will return the caller's public address.

At the same time if you want to access smart contract's address than you can use address(this) which will return the existing contract's address.

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.