Well I am trying to understand this code

pragma solidity ^0.4.11;

contract hello {
uint public totalTickets; 
uint constant price = 1 ether ; 
address owner ;
address hacked = 0x583031d1113ad414f02576bd6afabfb302140225; 

mapping (address => uint) public buyers ;

function hello () {
    totalTickets = 5 ; 
    owner = msg.sender ;


function buyTickets(uint amount, address _from) payable{
    if(msg.value != (price * amount) || amount > totalTickets){

    buyers[msg.sender] += amount ; 
    totalTickets -= amount; 



my issue is that in mapping key is msg.sender, and as per my understanding msg.sender is the one who creates the contract, now on the other hand when we use some-other address to pay for tickets it successfully gets mapped (why is that? cause they havent created the contract and they should by accessed by some other way) and then can be viewed latter against that address but on the other hand when selfdestruct(owner) is executed all the funds go back to the actual creator of contact. So how this msg.sender is behaving why it does not send all the funds back to last updated address.

1 Answer 1


There are special variables and functions which always exist in the global namespace and are mainly used to provide information about the blockchain. from the docs http://solidity.readthedocsio/en/develop/units-and-global-variables.html

msg.sender is one of these variables and can be accessed globally.

msg.sender is the sender of the message to the contract (current call).

When you deploy the contract msg.sender is the owner of the contract.

Now when the contract is deployed, the owner variable will always have the address of the person who initially deployed the contract.


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.