0

I try to simply check a users DAI token balance on Kovan testnet (ContractAddress: 0xC4375B7De8af5a38a93548eb8453a498222C4fF2) with the following code:

pragma solidity ^0.4.16;

contract ERC20 {
  function balanceOf(address who) constant returns (uint256);
}

contract myTest {

  ERC20 myToken;

  function setToken(address tokenAddress) {
    myToken = ERC20(tokenAddress);
  }

  function getTokenBalanceOf(address h0dler) constant returns (uint balance) {
    return myToken.balanceOf(h0dler);
  }
}

When exucting the getTokenBalanceOf function Remix throughs an error:

"call to myTest.getTokenBalanceOf errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information. "

enter image description here

6
  • can you share more details on issue you are facing? Oct 11, 2019 at 6:52
  • I get the following error message when executing gtTokenBalanceOf function: ""call to myTest.getTokenBalanceOf errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information. ". Also added a screenshot to post
    – Nico E
    Oct 11, 2019 at 6:53
  • Your code could not possibly compile, since function balanceOf is not implemented! Also note that in function getTokenBalanceOf, you're not doing anything with variable balance, so you may as well remove it. Oct 11, 2019 at 7:01
  • @goodvibration what do you mean by balanceOf is not implemented?
    – Nico E
    Oct 11, 2019 at 7:08
  • I mean: function balanceOf(address who) constant returns (uint256); is not implemented. But I apologize, it actually will compile and can run correctly if that function is implemented by the contract deployed at 0xC4375B7De8af5a38a93548eb8453a498222C4fF2. I suggest that you verify that this function is actually implemented there, and that it doesn't revert for some other reason. Oct 11, 2019 at 7:11

1 Answer 1

0

Make Sure that you are calling function getTokenBalanceOf() after the call setToken() function. hope this will help you.

4
  • Thats how I did it, and just tried again. Same error message
    – Nico E
    Oct 11, 2019 at 7:07
  • I write this answer because it is perfectly run well without any error. Oct 11, 2019 at 7:08
  • Just tested it with the old Remix UI and was working there. Really strange
    – Nico E
    Oct 11, 2019 at 7:12
  • yup, also me too. Oct 11, 2019 at 7:15

Your Answer

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

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