When I called fransferFrom by using erc20 interface (IERC20), an error says "gas required exceeds allowance (10000000) or always failing transaction".
I made allowance for the contract beforehand.
This is the contract that call transferFrom.
pragma solidity ^0.6.7;
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 TokenSale {
address public token_address;
constructor(address _token_address) public {
token_address = _token_address;
}
function sendEtherFromDeposit(address _token_supplyer) public returns(bool success) {
require(IERC20(token_address).allowance(_token_supplyer, address(this)) >= 10000, "insufficient allowance amount");
IERC20(token_address).transferFrom(address(this), msg.sender, 1000);
success = true;
}
}
Are there any problem of my code? Could you give me any advise, please?
approve
beforehand? – goodvibration Sep 2 '20 at 7:05icb_address
. Same goes for_icb_supplyer
. There is also no local variable_token_address
in the constructor. On top of all of that, the opening statement of your question makes no sense descriptive-wise. This question is in poor condition! – goodvibration Sep 2 '20 at 7:07