5

I'd like to accept regular transactions to a contract and record a mapping address -> value. Is it possible to achieve it?

Igor Barinov
  • 2,138
  • 1
  • 16
  • 25

2 Answers2

5
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.

Thomas Jay Rush
  • 9,943
  • 4
  • 31
  • 72
  • 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. – Jossie Calderon Jun 14 '17 at 07:36
2

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;
}
Jossie Calderon
  • 792
  • 1
  • 8
  • 14