I'd like to accept regular transactions to a contract and record a mapping address -> value. Is it possible to achieve it?
Asked
Active
Viewed 518 times
2 Answers
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
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
mappingshould 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