I have learned solidity. And I have one question.
How does contract detect that Ether has been sent from one address to the other address?
I have learned solidity. And I have one question.
How does contract detect that Ether has been sent from one address to the other address?
Each contract has an implicit 'default function' function ()
. If this function is modified as payable
then the contract can receive fund through that function from a trivial send transaction.
If the default function implements code, then that code will be also be run. However the default amount of gas in a send transaction can do little more that trigger an event. Anything more and the sender needs to be aware of the higher amount of gas required.
contract SimplySend {
event Paid(uint);
function () payable {
Paid(msg.value);
}
}
contract NeedExtraGas {
event Paid(uint);
uint total;
function () payable {
total += msg.send;
Paid(msg.value);
}
}