1

I keep gettting a "Gas exceeds limit" on a simple function trying to transfer ERC20 Tokens from one wallet to another. My first question is what is the most efficient way to debug such an error ? Second would be does anyone see anything wrong with my function as it is ?

Here is the error:

Transact to browser/SmartLoan.sol:Loan.sendFunds errored: Gas required exceeds limit: 3000000.  An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation). 

And here is the function that errors when it is called:

    function sendFunds(address dest, uint amount) public {
        if(totalPayments < loanStatics.totalAmount){

            address addressToken = 0xfef45491b96af14c98b81325cbb7a3fbb83bb7a0;
            abstractToken Token = abstractToken(addressToken);
            Token.transferFrom(msg.sender, dest, amount);

            totalPayments = totalPayments.add(amount);
            payments[msg.sender] = payments[msg.sender].add(amount);
            company = dest;
        }

        if(totalPayments == loanStatics.totalAmount){
            status = Status.funded;
        } else {
            status = Status.partially_funded;
        }
        LoanFunded(status, amount);
    }

Here is how I create the contract abstract:

contract abstractToken {
   function transferFrom(address _from, address _to, uint256 _value) public returns (bool);
}

UPDATE

Here is a print screen of the console, seems like my transaction doensn't even get created, or at least I don't know how to get the hash for it and therefore I am not sure how to debug it...

enter image description here

  • Does it work if you just bump up the gas limit? Try adding a zero to the end of that number and let us know if it works (some big contracts of mine have that problem at early stages). – thefett Nov 6 '17 at 13:08
  • I have tried, it still doesn't work I get the exact same message, I therefore suspect that there is an error in my contract somewhere. But I am not sure how to debug. – Rémi Nov 9 '17 at 5:54
  • Have you solved this issue? – Rexcirus Feb 8 '18 at 12:54
1

You'd have to post a little more of your code (the current stuff doesn't compile) or my usual strategy is just to comment out various lines and then you can narrow it down. But my guess is that its when you call the abstractToken contract. Try this one out:

abstractToken Token;

function sendFunds(address dest, uint amount) public {
    if(totalPayments < loanStatics.totalAmount){

        address addressToken = 0xfef45491b96af14c98b81325cbb7a3fbb83bb7a0;
        Token = abstractToken(addressToken);
        Token.transferFrom(msg.sender, dest, amount);

        totalPayments = totalPayments.add(amount);
        payments[msg.sender] = payments[msg.sender].add(amount);
        company = dest;
    }

    if(totalPayments == loanStatics.totalAmount){
        status = Status.funded;
    } else {
        status = Status.partially_funded;
    }
    LoanFunded(status, amount);
}
0

For your first question, the easiest way to test this would be on Remix. If you debug it over there you can review each step and see how much gas is remaining.

Now, the problem here doesn't actually seem to have to do with gas running out since you are not doing any loops or intensive computation.

I would debug it on Remix to see where it is actually stopping. A few things to check:

  • Are you sure the addressToken is correct? Is there a ERC20 token deployed to that address on the network you are currently using?
  • Before doing TransferFrom you would need to call approve() on the token to set an allowance for msg.sender. Have you done this?
  • The address Token is OK, I forgot about approve, just tried and I still get the same error. I have also tried to call transferFrom function "manually" from remix it self, and I get the same issue. I am really confused on how to deal with this. – Rémi Nov 9 '17 at 6:02
  • About debugging, It seems like you can only debug a transaction, but no transaction is created. It doesn't even get to that point. Updated my post with a print screen – Rémi Nov 9 '17 at 6:08

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.