(web3 in python)

I would like to "swap" BNB for pegged ETH on the binance smart chain using pancakeswap.

However, I have difficulties understanding what to put for the "path" variable.

The documentation says about the path variable:

An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.

I understood (from uniswap analogue) that the first address must be WETH (BNB on BSC), but that is a token and I am trying to swap native BNB.

Also, the factory contract has a function "getPair" to obtain a pool between the tokens that you would like to swap. But what "token" address to put for native BNB (which is not a "token", is it?)?

How to create (and understand) this path variable in this case?

1 Answer 1


I know it's been a long time, but I'll answer it to help others who will see this question.

Path is the array of contract addresses involved in the exchange. This can usually be [addressWETH,addressToken], where these two indicate the token contract exchange pool. The address array can have more addresses, depending on the existence of other pools.

It is not possible to switch directly to native BNB. Conversion to native BNB is done using the withdrawal call in the WBNB contract.

In the current design pattern of Uniswap and Pancake routers there is no possibility of direct exchange to BNB or native ETH. WBNB Call Contract: https://bscscan.com/address/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c#writeContract

If this answer helped you, please choose it as the best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.