Solidity
回退函式呼叫被還原
我創建了一個合約,當
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
函式是內部的,因此只能在同一個智能合約內呼叫,並且不進行任何授權檢查。