Created
October 4, 2021 16:05
-
-
Save Chmarusso/5b2012b7dc9afec33ec19d1583046f4a to your computer and use it in GitHub Desktop.
Transfer ERC20 from contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.7; | |
// SPDX-License-Identifier: MIT | |
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | |
contract FeeCollector { | |
address public owner; | |
uint256 public balance; | |
event TransferReceived(address _from, uint _amount); | |
event TransferSent(address _from, address _destAddr, uint _amount); | |
constructor() { | |
owner = msg.sender; | |
} | |
receive() payable external { | |
balance += msg.value; | |
emit TransferReceived(msg.sender, msg.value); | |
} | |
function withdraw(uint amount, address payable destAddr) public { | |
require(msg.sender == owner, "Only owner can withdraw funds"); | |
require(amount <= balance, "Insufficient funds"); | |
destAddr.transfer(amount); | |
balance -= amount; | |
emit TransferSent(msg.sender, destAddr, amount); | |
} | |
function transferERC20(IERC20 token, address to, uint256 amount) public { | |
require(msg.sender == owner, "Only owner can withdraw funds"); | |
uint256 erc20balance = token.balanceOf(address(this)); | |
require(amount <= erc20balance, "balance is low"); | |
token.transfer(to, amount); | |
emit TransferSent(msg.sender, to, amount); | |
} | |
} |
Can you help me with this https://ethereum.stackexchange.com/questions/129590/use-weth-for-nft-marketplace/129594#129594?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the issue? @devatoz