11

While developing a Smart Contract with Solidity on Remix , after creating the contract I'm trying to query a public mapping:

mapping (address => uint256) public balanceOf;

but when I call balanceOf for address 0x9b9731b07b9b5f982289bab87097eade6a4bc25d it throws the following error:

Error encoding arguments: SyntaxError: Unexpected token x in JSON at position 2

Any idea how can I properly call balanceOf?

1
  • It works ok when input is an integer such as 0, 1, 2, ... and response is ok too, giving the right balance. Problem is input cannot be an address and this is what it should be. Commented Oct 31, 2016 at 14:58

3 Answers 3

16

The address needs be surrounded with quotes. "0xca35b7d915458ef540ade6068dfe2f44e8fa733c" should work.

2

The address has to be provided with quotes. Just like huafu said. Must be double qutoes "". It is not going to work with single qutoes. In Javascript it doesn't matter and I was trying to figure out what I was doing wrong.

This works: "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"

This doesn't work. '0xca35b7d915458ef540ade6068dfe2f44e8fa733c'

1
contract MyToken
    mapping (address => uint256) public balances;

    function balanceOf(address _owner) constant returns (uint256 balance) {
        return balances[_owner];
    }

    ...
}

Reference - The DAO, version 1.0 with the $50 million bug.

4
  • Thx, using a query function, but what is the point of defining the mapping as public? I thought, beeing public meant anyone could ask for its values directly, right? Commented Oct 31, 2016 at 14:14
  • After creating balanceOf function, same error appears: Error encoding arguments: SyntaxError: Unexpected token... Commented Oct 31, 2016 at 14:59
  • 1
    Have you put quotes around the address? Commented Oct 31, 2016 at 15:06
  • 1
    Thanks! Now it works: "0xca35b7d915458ef540ade6068dfe2f44e8fa733c" Commented Oct 31, 2016 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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