0

This question already has an answer here:

I have a simple method where I count how many times certain address has called method of smart contract. Here is code:

mapping (address => uint) countTotal;

function countSends() public returns(uint retClicks) {
    clicksTotal[msg.sender]++;
    return countTotal[msg.sender];
}

Obviously I expect that on first send I'll get 1, then 2, then 3...

But for some reason what I get back through web3js is hexadecimal value like 0xea6166fd3f8249c3dd3ed1dcbb3af9989aebdcf9f5eb079fc6d570296e6f4509. How can I get regular unsigned integer?

EDIT: Duplicate nannies linked to theoretical discussion... this much better explains what you need to do: How to get values returned by non constant transaction functions?

marked as duplicate by Ismael, Achala Dissanayake, eth Mar 17 '18 at 4:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please share your code. But my guess: that's a transaction hash. Transactions don't really have return values... if you want to mutate state and "return" a value, you're probably going to end up using an event or a call after the transaction. – smarx Mar 17 '18 at 2:04
  • @smarx Yeah, just looking into it... seems that I need to wait for transaction to be confirmed in order for correct count to be returned. – nikib3ro Mar 17 '18 at 2:07
  • 1
    Well, you need to wait for the transaction to be mined before the change has taken place, but there still won't be a return value. – smarx Mar 17 '18 at 2:08
  • 1
    Simple example of using an event to get the return value: ethereum.stackexchange.com/questions/6380/… – eth Mar 17 '18 at 4:33
0

I guess, you got a typographic error. Instead of clicksTotal[msg.sender]++; change it to countTotal[msg.sender]++;

Try this.

mapping (address => uint) countTotal;

function countSends() public returns(uint retClicks) {
    countTotal[msg.sender]++;
    return countTotal[msg.sender];
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.