Hi All,
I have created a swap contract that can swap tokens for tokens, but im unable to work out how to swap native tokens.
I can swap WBNB, but not BNB to other tokens ?
Not entirely sure what I am missing.
The code takes the contract address for the tokens and then does a "swapExactTokensForTokensSupportingFeeOnTransferTokens" call to swap token-token.
How could i change the below code to accept BNB tokens?
function SwapTokensForTokens(address _tokenIn, uint amountIn, uint256 _amountOutMin) external {
IERC20(_tokenIn).transferFrom(msg.sender, address(this), amountIn);
IERC20(_tokenIn).approve(address(uniswap), amountIn);
address[] memory path;
if (_tokenIn == uniswap.WETH()) {
path = new address[](2);
path[0] = _tokenIn;
path[1] = tokenToSwap;
} else {
path = new address[](3);
path[0] = _tokenIn;
path[1] = uniswap.WETH();
path[2] = tokenToSwap;
}
uniswap.swapExactTokensForTokensSupportingFeeOnTransferTokens(
amountIn,
_amountOutMin,
path,
msg.sender,
block.timestamp
);
}