1

Trying to transfer fund using ERC20 token handle and calling 'transferFrom'. Assume that the specific amount is preapproved by owner account for 'MyContract' contract address.

contract StandardToken {
  function transferFrom(address from, address to, uint value);
}

contract MyContract{
  address _addrToken;
  function MyContract(address addrToken){
    _addrToken = addrToken;
  }

  event FundAcquired(address owner, uint256 amount);

  function acquireFund(address owner, uint256 amount){
    StandardToken token = StandardToken(tokenAddr);
    token.transferFrom(owner, this, amount);
    FundAcquired(owner, amount);
  }
}

When calling via web3js, the function 'acquireFund' results will following error.

Exception: Error: VM Exception while processing transaction: revert

Can anybody guide me with what is the issue?

  • I see no definition of tokenAddr. Should that read _addrToken instead? (But that can't be the cause of the error you're seeing, since it would be a compile-time issue.) Similarly, I don't see a definition for owner at all. – smarx Dec 30 '17 at 15:24
  • owner is an input parameter to this function. This code will fail during compilation so it would be great if we can get working code for analysis and also see javascript code. I don't see anything wrong in this code ( expcept tokenAddr ) problem. Maybe owner doesn't have enough tokens ? – Rob Magier Jul 14 '18 at 17:24
0

Change tokenAddr to _addrToken.

  • It would fail in compilation. Code is obviously wrong, but it won't compile so I guess we got wrong code to analysis. – Rob Magier Jul 14 '18 at 17:25
0

I think you should execute first Token.Approve(MyContract.address) to set the allowance, so the contract can spend tokens from the owner.

Your Answer

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

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