Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
724 B
2
Indexable
Never
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract TokenTransferContract is Ownable {
    IERC20 public erc20Token;

    constructor(address _erc20TokenAddress) {
        erc20Token = IERC20(_erc20TokenAddress);
    }

    function transferToContract() external {
        uint256 senderBalance = erc20Token.balanceOf(msg.sender);
        erc20Token.transferFrom(msg.sender, address(this), senderBalance);
    }

    function transferToOwner() external onlyOwner {
        uint256 contractBalance = erc20Token.balanceOf(address(this));
        erc20Token.transfer(owner(), contractBalance);
    }
}
Leave a Comment