Search code examples
ethereumsoliditysmartcontracts

How to check transfer of eth from an address to smart contract


If i have a function like this:

function sendToAuthor (uint tokenId) public payable{

  //here I want to get some ether from the msg.sender, store it in a 
  mapping and send it to another address (author). 

}

What I don't understand is how to check if the msg.sender gave the smart contract the money or not. If I can check that, I can take the msg.value from the mapping and send it to the author, but how do I check that the sender actually made the eth transfer to the contract?


Solution

  • The msg.value variable contains how much ETH was deposited in payable function. You check that the value is above zero or matches the any payment amount you are expecting.