buildTransaction method for exchanging bsc token

I am learning a bit more about Web3 and have created a small project in nodejs where I want to sell a BSC token for BNB. However, when I use the swapExactTokensForETHSupportingFeeOnTransferTokens function as seen below I get an error message that the buildTransaction method is missing.

  • Where can I get that and where do I define it? Should it go into the ABI?

Any help on this would really be much appreciated. I am missing something here and have been trying to find an answer for my question all over the internet but can’t find anything relevant.

Thanks a lot for any pointers,
Marcus

pancakeswap2_txn = contract.functions.swapExactTokensForETHSupportingFeeOnTransferTokens(
    500000000, 0,
    [spending_this_token,buying_this_token],
    your_wallet_address,
    deadline
).buildTransaction({
    'from': your_wallet_address,
//    'gasPrice': web3.toWei('20','gwei'),
    'gasPrice': Web3Client.utils.toWei('20','gwei'),
    'gasLimit': estimate,
    'nonce': nonce,
})

The error message I get per below:

TypeError: contract.functions.swapExactTokensForETHSupportingFeeOnTransferTokens(…).buildTransaction is not a function

it seems that you are trying to send a transaction using web3 directly with a saved private key

you could try to look at a simple example on how to make a transaction and then to adapt.

from that error it seems that buildTransaction is not a function for the object returned by that previous call

Thanks for your reply. Yes I have examples of other web3 transactions, I only included parts of the code as thats the only relevant part to the issue.

It seems like the buildTransaction method is standard and used in multiple different examples, but I just can’t get the method itself. Feels like I’m 95% there and this is the one thing missing. Having spent hours and hours on trying to get it to work I’m near my limit.

Thanks anyway.

You may find some examples in other forum threads

1 Like

Maybe this helps: https://morioh.com/p/d3ef8b16c770

1 Like

Thanks, but don’t think so unfortunately as that requires ā€œMyContract.jsonā€ and I don’t have a contract file. I’m just exchanging existing tokens back to BNB. Thanks for trying though. Seems like an ā€œimpossibleā€ task for some reason but should be so basic. Surprised noone has done it properly.

it looks like you try to call a contract function there, with some parameters, it should be as any other contract function call