I'm trying to create a market contract using the token I created as the currency. The market works by placing asks and bids and then using transferFrom
function to hold onto the tokens. However the function fails even though I have approved the contract address.
Here is my "Ask" method.
function addAsk (uint _amount, uint _price) public {
string memory _timestamp = uint2str(block.timestamp);
Ask storage ask = asks[msg.sender];
ask.asker = msg.sender;
ask.amount = _amount;
ask.price = _price;
ask.timestamp = _timestamp;
ask_ids.push(msg.sender);
//Works until here
credits.transferFrom(msg.sender, address(this), _amount);
emit AskPlaced(msg.sender, _amount, _price, _timestamp, tick);
}
Here is how I implemented my ERC20 token in the contract:
IERC20 public credits;
constructor() {
credits = new EnergyCredits();
}
I am getting this error every single time.
I have pinpointed the problem to the following location:
It seems the transferFrom function is having trouble when doing math operations to the "balances" mapping. What could be the reason for this?