0

I'm using solidity compiler ^0.4.23, I added logs to the function at exception points like this:

function firstSaleDelivery(address _beneficiary, uint256 rate) public onlyOwner{
  require(!presaleOpen && !firstsaleOpen, "First Sale is NOT CLOSE");
  if(preSaleTokens >= 0){
      saleTokens = saleTokens.add(preSaleTokens);
      preSaleTokens = 0;
  }
  uint256 ethers = firstSaleFunds[_beneficiary];
  uint256 tokens = ethers.mul(rate);    // <u>
  require(saleTokens >= tokens, "NO Sale Tokens Available");
  if(ethers >= 5 && ethers <= 9 ){
    tokens.add((tokens.mul(10)).div(100));            // <u>
  }
  else if(ethers >= 10 && ethers <= 200 ){
    tokens.add((tokens.mul(25)).div(100));            // <u>
  }
  token.transfer(_beneficiary,tokens);
  saleTokens = saleTokens.sub(tokens);

}

When I invoke the function, and if I face any exception, I can't see these Logs, where I can see them?

  • you can use remix to debug your code – Badr Bellaj Apr 26 '18 at 11:19
  • I don't want it for debugging purpose, I want my users of contract know why their transaction has failed. – Fariha Abbasi Apr 26 '18 at 11:38
  • so make it a bool function which returns false when it fails!! – Badr Bellaj Apr 26 '18 at 11:40
  • Returning a false doesn't really say anything about why it failed.. – Lauri Peltonen Apr 26 '18 at 11:53
  • Yes, my purpose is to let users know about WHY it failed, – Fariha Abbasi Apr 26 '18 at 11:59
1

Logs are not produced if the transaction reverts (see this answer: Is it possible to retrieve an event log from a reverted transaction?).

  • Despite the misleading title, the question is not about events. – smarx Apr 26 '18 at 13:27
  • Oh. Should I remove the answer? I don’t know the etiquette. – Thomas Jay Rush Apr 26 '18 at 14:51
1

The reason string is a very new addition to revert and require (about one week old). I believe that Geth's DebugTrace exposes the reason string, but otherwise I'm not sure there's tooling support yet.

I imagine that soon enough Etherscan will just surface them, but at the moment, reason strings are not particularly accessible to end users.

  • As I understand, if there is an exceptition, the TX is never mined and so it will never be present on Etherscan. Is that correct? – earizon Jun 11 '18 at 13:05
  • 1
    No, that's incorrect. Transactions that revert are still mined and still cost gas. – smarx Jun 11 '18 at 13:06
  • 1
    Here's a recent transaction that reverted: etherscan.io/tx/…. – smarx Jun 11 '18 at 13:07

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.