So Basically I m playing around on the BSC Testnet and trying to swap from One Token to Another. I tried to use all the Swap function(swapExactEthforTokens,swapTokensForToken,..supportingFee...) but I always get a failed Transaction or a Pancakeswap:'INVALID_PATH' error. I looked on the other Transaction on the Router and saw that people often used the swapExactEthforTokens function when they swapped from WBNB to a Token: example

My Adress that Im using on Bsc : Adress


pancAbi = {here is the ABI}
pancakeRouterContract = '0xD99D1c33F9fC3444f8101754aBC46c52416550D1'
tokenToBuy = '0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd'       #WBNB
spend = '0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee'         #Binance Usd                               # web3.toChecksumAddress("0xed24fc36d5ee211ea25a80239fb8c4cfd80f12ee")  # wbnb contract

# Setup the Uniswap contract
contract = web3.eth.contract(address=pancakeRouterContract, abi=pancakeRouterAbi)

nonce = web3.eth.get_transaction_count(sender_address)

start = time.time()

pancakeswap2_txn = contract.functions.swapExactTokensForETH(
    (int(time.time()) + 100000)
    'from': sender_address,
    'value': web3.toWei(0.001, 'ether'),  
    'gas': 200000,
    'gasPrice': web3.toWei('50', 'gwei'),
    'nonce': nonce,
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key=privateKey)
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)

1 Answer 1


you need to approve transaction with contract.functions.approve() function before calling contract.functions.swapExactTokensForETH ().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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