1

I am having a ERC20 token contract and another test contract which will trigger transfer function on token contract. I am getting a transaction receipt but transfer is not happening in the token contract. This my code

import "./ERC20Token.sol";
Contract Test {
  function Test() {
  }

  function triggerTransfer(address tokenAddress, address to, uint value) {
      ERC20Token tok = ERC20Token(tokenAddress);
      tok.transfer(to, value);
  }

}

3
  • 2
    In the receipt, does gasUsed equal the gas provided? If so, you're running Out of Gas and increasing the transaction's gas will usually help when the code and logic are correct. EDIT: But not in this case since it is a logic error as answered by @Ismael.
    – eth
    Commented Oct 12, 2017 at 9:43
  • Yes the gas equals to the gas provided. If increased also same thing happens if I increased more getting an error exceeds block gas limit.
    – Jazz
    Commented Oct 12, 2017 at 10:07
  • 1
    There's a good chance that this is due to a modifier / conditional statement failing. Check to make sure that the address that you are trying to transfer the tokens from does have the balance you expect.
    – SteveJaxon
    Commented Oct 12, 2017 at 21:06

1 Answer 1

3

The issue is because you are making the transfer from a solidity Test contract, and the token will see Test as the msg.sender and not your user.

In order to make the test work, you have to assign some tokens to the Test contract before the it is run.

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.