1

I have two contract. I call function placeBid in other contract and i have warning gas estimation. help me. thanks. Can i call function which use gas in loop through other contract? How i can get around this warning(gas estimate)?

Auction contract:

function placeBid(uint amount)  public notOwner returns(bool) {
    require(auctionState == State.Running);
    require(count>=amount);          
    trc20.transferFrom(msg.sender, address(this), startPrice);
    return true;
}

other contract:

function placeBidBox(address[] memory _addresses, uint[] memory _amounts)public{


   for(uint i=0; i<_addresses.length; i++){
       a = Auction(address(_addresses[i]));
       a.placeBid(_amounts[i]);
   }

}

update: i resolved this problem with address of sender. i need send address of sender in arguments of function such as i call other contract and contract dont know sender.

  • Is your error "gas estimation failed"? It's not an error, it's a warning. The system has no way of estimating gas usage due to the calls to another contract. But yes, you can call external contracts in a a loop – Lauri Peltonen Mar 17 at 5:28
  • thanks for fast answer, How i can get around this warning? – malysh Mar 17 at 5:38
  • Added an answer. So you can probably just ignore the warning. – Lauri Peltonen Mar 17 at 6:13
0

The error about gas estimation failed is not actually an error but a warning. It means exactly what it says: the system is unable to estimate the required gas amount.

This is mostly due to the calls to external contracts. There is no way to know what functionality happens inside the external contracts and therefore there is no way to estimate the required gas usage.

You can pretty safely just ignore this warning if you know how much gas (gas limit) you are supposed to provide. If unsure just provide a big amount, for example 5 million - you will get the unused gas back.

So there is no problem per se in calling external contracts in a loop. The estimation would fail even if you performed the same call only once. Furthermore only having a loop without external calls will also result in the same problem as the system can't know for certain how many loops it has to execute.

| improve this answer | |
  • thanks, i have gas required exceeds allowance (8000029) or always failing transaction error after just ignore – malysh Mar 17 at 6:25
  • oh well then the transaction probably requires more gas than is possible to give. – Lauri Peltonen Mar 17 at 6:44
  • @malysh: OR (continuing the comment above)... the transaction is always failing. In fact, with the error that you've specified, this is mostly the case (I'd say - 1% of such errors are due to gas, and the other 99% are due to always failing). In your case, the always failing is probably the result of one of the require statements in your code. Another option, though less likely, is that for some value of i, the value of _addresses[i] is not an address of a properly deployed Auction contract. – goodvibration Mar 17 at 7:06
  • Lastly, it could fail as a result of a require statement in your trc20.transferFrom function, whose code you haven't provided in your question. I would take the liberty to guess that trc20.approve should be called prior to calling that funcction. – goodvibration Mar 17 at 7:11
  • @goodvibration thanks for answer, if i call function placeBid singly, function is work. But if i call through loop , i have warning. i think that if problem was in require then why i dont have warning when i call function singly? thanks, where i wrong? – malysh Mar 17 at 8:24

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.