I have been learning solidity from yesterday.

One thing is so confusing to me.

address someone = msg.sender;

If you look at the code above. It is too ambiguous.

someone send 10 ether to X, who is X? It's not specified in the code.

address someone = msg.sender;

msg.sender refers to the sender of the transaction/call.

address someone = msg.sender; Means that we store the sender address in the someone variable

someone.transfer(10); This is the equivalent of msg.sender.transfer(10) This function allows to send 10 ether from the smart contract to the sender address.

EDIT for explanations:

A smart contract is not very different from a "normal" address. It just can do more stuff (what you allowed it to do in the code). As a consequence, smart contracts can own ether (to be more precise, their address can), and they can behave like normal addresses. So a smart contract can send Ether to an address and receive ether too. However, you can tell the smart contract to do more stuff when it receives ether, check the keyword payable for more information.

To answer the question in the comment: no, this does not mean the smart contract owner(1) sends ether, but the contract itself, from its own ether balance.

(1) If this makes sense. A contract does not nativaly has an owner. This concept is only in the code of the contract.

Personal note: However, I don't understand why you would duplicate the msg.sender address storing it into a variable. Optimisation is very important in solidity, so use msg.sender and don't store it anywhere as it already is :)

  • Can you add more detail about "send 10 ether from smart contract to the sender address"?
    – Notice
    Jan 26 '18 at 2:38
  • Does It mean that the smart contract owner send 10 ether from his wallet to sender's wallet?
    – Notice
    Jan 26 '18 at 2:39
  • I edited my answer, hope it will help you! Jan 26 '18 at 2:45
  • You might accept the answer then, your welcome! Jan 26 '18 at 4:28

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.