Please Help Me.. I would be highly thankful. Here is my sample code.
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(
address recipient,
uint256 amount
) external returns (bool);
function allowance(
address owner,
address spender
) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract BoStaff {
uint256 public low_speed_price = 5 * (10 ** 18);
uint256 public med_speed_price = 10 * (10 ** 18);
uint256 public high_speed_price = 20 * (10 ** 18);
address payable owner;
IERC20 public token;
event WithDraw(address indexed to, uint256 indexed amt);
event Deposit(address indexed from, uint256 indexed amount);
constructor(address tokenAddress) {
token = IERC20(tokenAddress);
owner = payable(msg.sender);
}
function Approvetokens(uint256 _tokenamount) public returns (bool) {
token.approve(address(this), _tokenamount * (10 ** 18));
return true;
}
function GetAllowance(address spender) public view returns (uint256) {
return token.allowance(spender, address(this));
}
function request_low_speed() external {
require(
token.allowance(address(this), msg.sender) >= low_speed_price,
"Insufficient Allowance to spin to wheel"
);
require(
token.balanceOf(msg.sender) >= low_speed_price,
"Insufficient tokens to spin the staff"
);
token.transferFrom(msg.sender, address(this), low_speed_price);
}
function request_med_speed() external {
require(
token.allowance(address(this), msg.sender) >= med_speed_price,
"Insufficient Allowance to spin to wheel"
);
require(
token.balanceOf(msg.sender) >= med_speed_price,
"Insufficient tokens to spin the staff"
);
token.transferFrom(msg.sender, address(this), med_speed_price);
}
function request_high_speed() external {
require(
token.allowance(address(this), msg.sender) >= high_speed_price,
"Insufficient Allowance to spin to wheel"
);
require(
token.balanceOf(msg.sender) >= high_speed_price,
"Insufficient tokens to spin the staff"
);
token.transferFrom(msg.sender, address(this), high_speed_price);
}
function withdraw() external onlyOwner {
emit WithDraw(msg.sender, token.balanceOf(address(this)));
token.transfer(msg.sender, token.balanceOf(address(this)));
}
function getBalance() public view returns (uint256) {
return token.balanceOf(address(this));
}
function getBalanceOfAddress(address user) public view returns (uint256) {
return token.balanceOf(user);
}
receive() external payable {
emit Deposit(msg.sender, msg.value);
}
modifier onlyOwner() {
require(msg.sender == owner, "Access Denied");
_;
}
}