Can somebody explain what is the magic msg.value
? I came across this code:
https://learnxinyminutes.com/docs/solidity/
/// @return The balance of the user after the deposit is made
function deposit() public payable returns (uint) {
// Use 'require' to test user inputs, 'assert' for internal invariants
// Here we are making sure that there isn't an overflow issue
require((balances[msg.sender] + msg.value) >= balances[msg.sender]);
balances[msg.sender] += msg.value;
// no "this." or "self." required with state variable
// all values set to data type's initial value by default
LogDepositMade(msg.sender, msg.value); // fire event
return balances[msg.sender];
}
I do not see where the msg.value coming from, when a user deposit eth, does he or she needs to pass in the amount from the deposit function? Thanks and sorry for newbie question.
Edit:
From the following contract, I do not see anywhere passing in msg.value, so how this msg.value has been assigned? by the way you link of cryptozombie is very interesting, thanks.
pragma solidity ^0.4.0;
contract ClientReceipt {
event Deposit(
address indexed _from,
bytes32 indexed _id,
uint _value
);
function deposit(bytes32 _id) public payable {
// Events are emitted using `emit`, followed by
// the name of the event and the arguments
// (if any) in parentheses. Any such invocation
// (even deeply nested) can be detected from
// the JavaScript API by filtering for `Deposit`.
emit Deposit(msg.sender, _id, msg.value);
}
}
http://solidity.readthedocs.io/en/develop/contracts.html#function-modifiers