Created a DEX (token swap) but unsure how to swap native tokens

Hi All,

I have created a token swap contract which takes in a token and swaps this for another (just like PancakeSwap and the others) But I'm stuck on how to do this with native tokens, I can swap other tokens to tokens, and everything works fine but not BNB to tokens?

What am I missing?

My function i use is below.

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;


You can always wrap the native token in an ERC-20/BEB-20 contract. So for example, deposit native ETH into wETH and then swap the wETH as a regular ERC-20 token.