I'd like to accept regular transactions to a contract and record a mapping address -> value. Is it possible to achieve it?
2 Answers
mapping (address => uint) data;
function () payable {
data[msg.sender] = msg.value;
}
I think that would do it, but someone else should verify. The function without a name is the default function and handles any call that is not called on a named function.
-
The comma in the
mapping
should be replaced by an arrow=>
. Also, for the OP to store it he would need to create an associative array. Commented Jun 14, 2017 at 7:36
Improving on Thomas Jay Rush's code (it's now missing the payable modifier as of 09/2016):
mapping (address => uint) data
function () payable {
data[msg.sender] = msg.value;
}