I want to receive an erc20 token as value for a function.
Basically, the function caller defines an amount which will then be transferred from their balance to the smart contract. Which transfer pattern should I use for this?
As an example, Why will this function not accept my ERC20 token input?
contract Transform {
InputToken inputToken;
OutputToken outputToken;
event Transformed(address from, uint256 input, uint256 output);
constructor(address _inputToken, address _outputToken) public {
inputToken = InputToken(_inputToken);
outputToken = OutputToken(_outputToken);
}
function transformTokens(uint256 _amount) external payable {
require(_amount > 0);
uint256 input = _amount; //It's reverting here?? I don't see the issue
uint256 rate = 1000;
uint256 output = input.div(rate);
uint256 excess;
inputToken.transferFrom(msg.sender, address(this), input);
outputToken.mint(msg.sender, output);
Transformed(msg.sender, input, output);
}
}