I know this question has been asked too frequently. I apologise, but I did not understand much of the answers. I've been trying to create a Staking Contract but this error has stumped me. This is not the stake function code itself, just the transferring part. This is the code:
function stake(uint256 _amount) public {
stakingToken.transferFrom(msg.sender, address(this), _amount);
stakingToken.approve(msg.sender, _amount);
}
This is the error:
The transaction has been reverted to the initial state.
Reason provided by the contract: "ERC20: insufficient allowance".
Debug the transaction to get more information.
I've tried putting the approve function first and the TransferFrom last. Ive tried using the Transfer function but all have came up with the same exact error.
I've also increased my gas limit to 12000000, I've tried to add ether too, but nothing has worked.
I apologise if this question bothers you, I'm just foraging for an informative answer that will solve my issue.
May you reach the stars.