[SOLVED] Swap Contract - bug

function swap(uint256 amountTK2) public {
uint256 _amountTK1 = (amountTK2 / _valueTK1) * (10 ** 18);
require(owner2[msg.sender], “Not authorized”); //user
require(
_token1.allowance(_owner1, address(this)) >= _amountTK1, // wallet zeex
“Token1 allowance too low”
);
require(
_token2.allowance(msg.sender, address(this)) >= amountTK2, //USDT
“Token2 allowance too low”
);
_safeTransferFrom(_token2, msg.sender, _owner1, amountTK2);
_safeTransferFrom(_token1, _owner1, msg.sender, _amountTK1);
}

function _safeTransferFrom (
    IBEP20 token,
    address sender,
    address recipient,
    uint amount
) private {
    bool sent = token.transferFrom(sender, recipient, amount);
    require(sent, "Token transfer failed");
}

I have implemented a Swap contract and two BEP20 tokens on BSC testnet. But when I test the swap function (connected with the wallet that has the Token2) there is an exception in the metamask. I’m having trouble debugging and understanding what’s going on.

GitHub completo.

Could someone help me? This is a real project, but I’m struggling.

You could try to debug it in remix after you deploy it in remix locally.

My brain was BUG. rsrs
Thank you very much for the comment. I managed to solve it now :slight_smile:

1 Like