Remix behaves differently when running Javascript VM and web3 provider mode.

I have two contracts:

contract ERC20Basic {

  function totalSupply() public view returns (uint256){}
  function balanceOf(address who) public view returns (uint256){}
  function transfer(address to, uint256 value) public returns (bool){}
  event Transfer(address indexed from, address indexed to, uint256 value);

and AegisMarketing contract which is calling functions from ERC20Basic.

I have a problem calling AegisMarketing GetBalanceTest function.

function GetBalanceTest() public constant returns (uint256)
      return token.balanceOf(address(this));

which in ERC20Basic is defined as follows:

  function balanceOf(address _owner) public view returns (uint256 balance) {
    return balances[_owner];

If I compile and deploy those contract in Remix in Javascript VM mode then everything works fine. I get correct value running both AegisMarketing.GetBalanceTest() and also ERC20Basic.balanceOf() function.

When I deploy in my truffle to local geth or via Remix Web3 provider to my local geth AegisMarketing.GetBalanceTest always returns 0,but when I check balance of AegisMarketing contract in ERC20Basic itself I get correct value.

General idea is that AegisMarketing contract is using ERC20Basic token contract to airdrop tokens to some accounts. AegisMarketing contract must have some positive balance in ERC20Basic contract to be able to aidrop those tokens and this is what I am trying to check.

The whole project is here: https://github.com/robertmagier/AegisMarketing

AegisMarketing contract is in contracts/AegisMarketing.sol

ERC20Basic token is in contracts/Token.sol

This is how it looks in Remix. I checked many times that I am checking correct Contract address in balanceOf function. And it works in Javascript VM mode in Remix.

enter image description here

  • Are you sure you are using the correct token address? Plus, as a note, you don't need to create the getter GetBalanceTest() since the balanceOf function of the ERC20 token is public. May 1 '18 at 17:11
  • I am sure I am using correct token address. I checked many many times. And it works in Javascript VM mode. Of course in this scenario I don't need to use GetBalanceTest function, but I need to be able to check balanceOf from AegisMarketing contract to make sure I have enough tokens to make a drop.
    – Rob Magier
    May 1 '18 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.