2

As per my understanding contract`s own address is the address which we assign to owner of contract using msg.sender. But I saw this question on SE where it was described that a contract can access its own address using address(this) , but when i compiled following script

 address owner; 
function test (string _name)public view returns(bool){

    owner = msg.sender; 
    return owner == address(this);
}

i get boolean result as false.

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

3

this refers to the instance of the contract where the call is made (you can have multiple instances of the same contract).

address(this) refers to the address of the instance of the contract where the call is being made.

msg.sender refers to the address where the contract is being called from.

Therefore, address(this) and msg.sender are two unique addresses, the first referring to the address of the contract instance and the second referring to the address where the contract call originated from.

2

this is refers contract address. Contracts are non managable accounts which will not have any private key. That means if you created contract you don't have private key for contract A. msg.sender = Contract caller (Who is calling your contract) tx.origin = Transaction initiator

Refer bellow link for more details:

http://solidity.readthedocs.io/en/develop/units-and-global-variables.html

  • this, not this.address – user19510 Feb 17 '18 at 20:46
  • 2
    Also, this has been deprecated in favor of address(this). – GViz May 29 '18 at 22:59
0

Every account in Ethereum has an address. Contracts are special kinds of accounts and have their own addresses different from msg.sender and this.owner.

The contract's address is determined by the account that created it and its nonce. So if you create a new contract from address1 you can know in advance what’s the address of your new contract e.g. with this Solidity code: address(keccak256(0xd6, 0x94, address1, currentNonce)). You can find more details in this answer How is the address of an Ethereum contract computed?

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.