0
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

// Import the OpenZeppelin library for security.
import "@openzeppelin/contracts/access/Ownable.sol";

interface IERC20Token {
  function transfer(address, uint256) external returns (bool);
  function approve(address, uint256) external returns (bool);
  function transferFrom(address, address, uint256) external returns (bool);
  function totalSupply() external view returns (uint256);
  function balanceOf(address) external view returns (uint256);
  function allowance(address, address) external view returns (uint256);

  event Transfer(address indexed from, address indexed to, uint256 value);
  event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract Eavesdrop {
    address internal BusdTokenAddress = 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56;
     uint256 public serviceCost; // Cost in payment token for service.
    address payable public owner;    //contract deployer

    // Event to log successful analysis requests.
    event PaymentMade(address indexed user, uint256 timestamp);

    modifier onlyOwner() {
    require(msg.sender == payable(owner), "Only the owner can call this function");
    _;
}

    constructor() {
        owner = payable(msg.sender);
    }
  
    // Function to set the cost of service (only the owner can do this).
     function setServiceCost(uint _newCost) public  onlyOwner  {
        serviceCost = _newCost;
    }

    // Function to request service and make payment in the chosen token.
    function payForService(uint256 _serviceCost) public  payable {
        require(
            IERC20Token(BusdTokenAddress).balanceOf(msg.sender) >= _serviceCost, "Insufficient balance");
        require(
            IERC20Token(BusdTokenAddress).allowance(msg.sender, address(this)) >= _serviceCost, "Token allowance not set");

        // Transfer payment to the contract.
        require(
            IERC20Token(BusdTokenAddress).transferFrom(msg.sender, address(this), _serviceCost), "Payment failed");

        // Emit an event to log the service request.
        emit PaymentMade(msg.sender, block.timestamp);
    }

    // Function to withdraw funds from the contract (only the owner can do this).
    function withdrawFunds() public payable onlyOwner {
        uint256 contractBalance = IERC20Token(BusdTokenAddress).balanceOf(address(this));
        require(contractBalance > 0, "No funds to withdraw");
        require(
            IERC20Token(BusdTokenAddress).transfer(owner, contractBalance), "Withdrawal failed");
    }

    // Function to check the BUSD balance in the contract.
    function getContractBalance() internal view onlyOwner returns (uint256) {
        return IERC20Token(BusdTokenAddress).balanceOf(address(this));
    }
}
0

1 Answer 1

1

This is because Solidity 0.8.20 introduced the PUSH0(0x5f) opcode, which is not currently supported by BSC. You can use 0.8.18 or 0.8.19.

pragma solidity ^0.8.18;

Not the answer you're looking for? Browse other questions tagged or ask your own question.