Hi, I am having issue swapping back DAI tokens to ETH with uniswap interface, I am getting this error "Dai/insufficient-allowance"
on the transaction especially this part require(allowance[src][msg.sender] >= wad, "Dai/insufficient-allowance");
my wallet and contract both hold DAI tokens 200 and 50 respectively and trying to swap 10 DAI. I don’t understand why I get insufficient balance error. How do I resolve this issue?
Here is the snippet of the part where I get the error
function Sell(uint tokenAmount) public payable {
uint deadline = block.timestamp + 15;
require(token.transferFrom(msg.sender, address(this), tokenAmount), 'transferFrom failed.');
require(token.approve(address(uniswapRouter), tokenAmount), 'approve failed.');
// Swap DAI for ETH
uniswapRouter.swapExactTokensForETH(tokenAmount, msg.value, getPathForTokentoETH(), address(this), deadline);
}