Hello, I am testing a smart contract that accepts erc20 and erc721 tokens. I am having a problem of sending erc20 to this smart contract. When im calling the function which transfers tokens, the error “execution reverted: Check the token allowance” is displayed. Obviously, this error is due to the fact that the allowance of my erc20 tokens is 0. The function code is attached below. What am I doing wrong with allowance setup?
Environment
I’m using online remix ide for developing my contracts and then they have been deployed it to rinkeby testnet. To interact with contracts, I am using my ether wallet.
Details
Code to reproduce
here is the code of my function:
function put_aktiv(uint256 number_erc20, uint256 number_erc721, uint256 token721_id) public payable {
uint256 token1155_id;
token20.approve(address(this), 100); //approve allowance
uint256 allowance = token20.allowance(msg.sender, address(this));
require(allowance >= 1, "Check the token allowance");
token20.transfer(address(this),1);
token20.transferFrom(msg.sender, address(this), number_erc20);
token721.transferFrom(msg.sender, address(this), token721_id);
token1155_id = create_erc1155_token(number_erc20, token721_id);
token1155.safeTransferFrom(address(this), msg.sender, token1155_id, 1,"");
}