msg.value & payable functions

Payable functions

Say you want to make a call to another contract's payable function and transfer ETH:

targetAddress.someFunction{ value: amount }(arg1, arg2, arg3)
  • calls someFunction on targetAddress contract

  • sends amount of ETH

  • this works if someFunction is a payable function

Calling payable functions

function deposit() public payable {
    balanceOf[msg.sender] += msg.value;
    emit Deposit(msg.sender, msg.value);
}

Last updated