0

For a smart contract function to receive Ether, it is marked payable.

Is there a specific point in the execution of the code where the sent value is "claimed" or "taken" from the msg.sender by the contract?

If the payable function calls another internal function, can that function still "see" and check for the value sent in the call?

Does the answer have implications on how we should write interrelated functions securely when they deal with Ether values?

To illustrate: would the require check in internalFunc() pass or fail when first() is called with a non-zero value? (Sure you could check in the first() function, but just for illustration :) )

function first() public payable {
  _internalFunc();
}

function _internalFunc() internal {
  require(msg.value > 0, "send more than zero");
  //do something else
}

Thanks!

1 Answer 1

1

msg.value can be accessed globally, so yes check will be performed. In other words, require check will fail if you do not pass non-zero value when you call first() function.

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.