I'm trying to execute swap on Pancakeswap with web3.js but I get error

@Fredo can you share the code to buy on pancake without WSS request API only with https://bsc-dataseed.binance.org/

So, how do you specify the value of BNB you want to use?

When swapping from token to bnb, you dont have to specify the value of BNB, you only need to pass the amount of token (you intend to buy) to the SwapExactTokensForETH function.

If you need to know the amount of BNB you'l get from a certain amount of token, then use the GetAmountsOut function. In my experience, its better to use this value for calculating the AmountsOutMin parameter needed for the SwapExactTokensForETH function.