1

I have a mapping that maps addresses to uints:

mapping (address => uint256) mapAddress;

A function then assigns a counter to the address:

mapAddress[msg.sender] ++;

This gives me 1.

The problem is that I'm getting an error when trying to set the counter back to 0:

function resetCounter() public payable returns(bool) {
    if (mapAddress[msg.sender] > 0) {
        mapAddress[msg.sender] = 0;
        return true;
    } else {
        return false;
    }
}

the function above gives me this error:

transact to Contract.resetCounter errored: Error: Error: [ethjs-query] while 
formatting outputs from RPC 'undefined' for method 'sendRawTransaction' 
Error: [ethjs-format] hex string 'undefined' must be an alphanumeric 66 utf8 
byte hex (chars: a-fA-F) string, is 0 bytes

What could be wrong here?

  • What is the development environment? It can appear a problem related to RPC interface, not to the code shown, that is correct but for the “payable” attribution to the resetCounter, apparently not justified. – Rick Park Jan 11 at 21:58
  • I am using Remix IDE with Ganache (injected Web3). – Ruham Jan 11 at 22:01
  • Try the same in JavaScript VM – Rick Park Jan 11 at 22:01
  • It worked in JavaScript VM. I have also removed the "payable" attribute. How to make it work with Injected Web3? I am confused. – Ruham Jan 11 at 22:04
  • The problem is on your RPC. If you are using ganache, may be that without the “payable” it works now (there is a bug about that at the moment). – Rick Park Jan 11 at 22:13
0

The answer is that you hit a known bug of the current versions of ganache (at least from 1.21 they all suffer this).

According to ganache developers it is related to the gas estimation phase, to be fixed, popping up for payable attribution (functions for sure and may be addresses)

If your code works on JavaScript VM, it shall works on testnets and on mainnet without problems at all.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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