0

I created a contract which mints tokens when the msg.value is higher or equal to the token(ticket) price. Unfortunately when I send a transaction to the contract fallback it gets reverted. It's my fallback:

function() public payable {
    require(now < ticketExpiryDateTimestamp, "This sale has been completed");
    require(emitedTickets < maxTicketsSupply, "Sold out");
    uint _ticketsAmount = msg.value / ticketPrice;
    require(_ticketsAmount < maxTicketsSupply, "You can't buy more tickets than the emitted number");
    require(_ticketsAmount > 0, "You did not pay enough to buy any ticket");
    transfer(msg.sender, msg.value - _ticketsAmount * ticketPrice);
    mint(msg.sender, _ticketsAmount);
    emitedTickets += _ticketsAmount;
}

Thanks in advance

  • Probably easiest is to comment out the require statements one by one and see which one causes the revert. This way you'll find out which value is problematic. – Lauri Peltonen Jan 14 at 9:20
  • Comment one line at a time, until you find which line is causing the problem. Since we don't have the rest of your contract, we cannot do it ourselves (and you should be the one to do it in any case). – goodvibration Jan 14 at 9:28
  • My contract is not secret. pastebin.com/kYSCsB4s. ropsten.etherscan.io/address/… – Marcello Bardus Jan 14 at 9:33
  • 1
    Simply identify the require which revert. You can do that both inserting a label to be returned by the require as in: require (a>0, “error 1”); OR commenting them all out and reintroducing each of them one by one. After this please update the question – Rick Park Jan 14 at 10:02
0

This could be due to one of the require statements . try removing these require statements one by one and check which one is causing this

  • I checked it, the reason is gas estimation inside the fallback – Marcello Bardus Jan 14 at 15:44
0

You should use _mint rather than mint. Function mint is public and requires caller to be authorized minter, while _mint is internal, thus it may be called only from within the same smart contract, and it does not perform any authorization checks.

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.