hello everyone,
I want transfer Chainlink token to other address but I fail my transaction, anyone know how to solve this problem?

https://kovan.etherscan.io/tx/0x005e623b4da95151c1ef68a71e94a5d94adffe0f1e1b17c27f63c7dbc8ed167d

Mar 6, 2022, 2:10 PM
share the code of the contract, the contract is not verified so cant check by myself
Mar 6, 2022, 2:16 PM
pragma solidity >=0.7.0 <0.9.0;


import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol";


contract MoveETH {

address public owner;

event TransferSent(address _form, address _desAddr, uint _amount);

constructor() {
owner = msg.sender;
// address payable addr = payable(address(sendToAddress));
// selfdestruct(addr);
}

function transferECR20(IERC20 token, address to, uint amount) public{
require(msg.sender == owner, "Only can withdraw funds");
uint256 erc20balance = token.balanceOf(address(this)));
require(amount <= erc20balance, "balance is low");
token.transferFrom(msg.sender ,to, amount);
emit TransferSent(msg.sender, to, amount);
}


function getBalanceMe(IERC20 _token) public view returns(uint){
return _token.balanceOf(address(msg.sender));
}


}
Mar 6, 2022, 2:17 PM
the problem is that you're passing and IERC20 token but u need to pass the address of the contract of the ERC20 and then inside the function load the contract into a variable like IERC20 _contract = IERC20(contract_address)
function transferECR20(address token_address, address to, uint amount) public{
require(msg.sender == owner, "Only can withdraw funds");
IERC20 token = IERC20(token)
uint256 erc20balance = token.balanceOf(address(this)));
require(amount <= erc20balance, "balance is low");
token.transferFrom(msg.sender ,to, amount);
emit TransferSent(msg.sender, to, amount);
}
same for the function for the blanace
Mar 6, 2022, 2:20 PM
Can I use it in my project now?
Mar 6, 2022, 2:21 PM
go ahead, it will show a different error if it fails
Mar 6, 2022, 2:22 PM
ok, I test it now
I try your code but the transaction fail again
Mar 6, 2022, 3:55 PM

© 2024 Draquery.com All rights reserved.