0

transact to FpsCrowdsale.buyTokens errored: VM error: revert.

revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

function buyTokens() public payable {
require(publicBuyActivated == true);
address payable transaction_sender = msg.sender;
uint256 weiAmount = msg.value;
_preValidatePurchase(transaction_sender, weiAmount);

// calculate token amount to be created
uint256 tokens = msg.value / _rate;

_processPurchase(transaction_sender, tokens);
emit TokensPurchased(transaction_sender, address(this), weiAmount, tokens);

if (firstBuyTime[transaction_sender] == 0) {
    firstBuyTime[transaction_sender] = block.timestamp;
}

//dai.transferFrom(msg.sender, __wallet, msg.value);

__wallet.transfer(msg.value);

}

5
  • How do you compile your contract? Oct 11 '21 at 10:46
  • Is __wallet a contract? Also maybe the problem is in _preValidatePurchase or _processPurchase?
    – Foxxxey
    Oct 11 '21 at 11:24
  • i use remix compiler Oct 11 '21 at 21:23
  • __wallet is not the contract no Oct 11 '21 at 21:24
  • Unless you provide more details it is gust guessing. What's publicBuyActivated value? What is __wallet? EOA, contract. What does _processPurchase do? Remix has a debugger where you can execute transaction step by step until the line that fail is determined.
    – Ismael
    Oct 14 '21 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.