Solidity

回退函式呼叫被還原

  • December 29, 2021

我創建了一個合約,當msg.value價格高於或等於代幣(門票)價格時會鑄造代幣。不幸的是,當我將交易發送到合約備份時,它會被還原。這是我的備份:

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;
}

提前致謝

這可能是由於 require 語句之一。嘗試一一刪除這些要求語句並檢查是哪一個導致了這種情況

您應該使用_mint而不是mint. 函式mint是公開的,要求呼叫者是授權的鑄幣者,而_mint函式是內部的,因此只能在同一個智能合約內呼叫,並且不進行任何授權檢查。

引用自:https://ethereum.stackexchange.com/questions/65521