I am facing a strange issue. Please read the below case craefully and assit me to geth this issue resolved.

I have ERC20Token created by Zeppling templates.

[Please ignore syntaxes, I am just trying to expling my use case:]

Here is a protoype of token code:

Contract 1:



    transfer(to, amount)
        balance[msg.sender]///// Here is the issue.


    _erc20TokenObject.transfer(newTokenHolderadress, 10000);



In Truffile test case I am deploying
SampleErc20Token and DummyContarcts from accounts[0]

In SampleErc20Token Constructor I am passing the address of DummyContarcts .

Now with the instance of DummyContarcts I call method DoSomething, which internally calls _erc20TokenObject.transfer. In this case msg.sender in transfer methid should be DummyContarcts onject. But its picking some random address. Can any one help me to solve this puzzle please.

  • Can you provide a MCVE? The concept looks right, so it is likely an implementation detail – Raghav Sood Sep 4 '18 at 16:59
  • Sure. Let me see what best I can do in MCVE – Amit Modi Sep 4 '18 at 17:01
  • contract MyToken is StandardToken { constructor (address addr) public { totalSupply_= 10000; balances[addr] = totalSupply_; } function transfer(address _to, uint256 _value) public { require(_value <= balances[msg.sender]);}} contract D { function doTransfer(address newTokenHolder,MyToken erc20Toekn) external wasNotReplaced adminsVotingApproved { erc20Toekn.transfer(newTokenHolder, 20); } } =============================== Now if I call D.doTransfer then erc20Toekn.transfer is called and there balances[msg.sender] is different than D address. – Amit Modi Sep 4 '18 at 17:15
  • 1
    With some small modifications, your code works fine for me: gist.github.com/RaghavSood/a1c27edaf189576174f8718085a13697. It sounds like something in the way you are doing your truffle tests is incorrect, or your actual code does something different. – Raghav Sood Sep 4 '18 at 17:35

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.