0

I'm a beginner with Web3 programming. Trying to understand how all it all works.

Managed to get some nodejs code working for buying tokens but when trying to create a script that sells tokens I get an error message related to the .buildTransaction method. I don't understand where I can get the buildTransaction method from? I guess it should go into the ABI same as for the swapExactTokensForETHSupportingFeeOnTransferTokens but I have looked everywhere and can't even find an example so it seems like I'm missing something.

Would really appreciate some help on this. Have been sitting 3 hours just trying to understand how I can get the buildTransaction to work.

My code:

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

Error message:

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

3
  • Welcome, what is the library you're using, in which programming language ?
    – Franfran
    Commented Mar 9, 2022 at 12:51
  • Thank you. I am using NodeJS, including all these libraries per below: ` var Tx = require('ethereumjs-tx'); var Web3 = require('web3') var Contract = require('web3-eth-contract'); const ethers = require("ethers"); const web3utils = require("web3-utils"); `
    – Marcus
    Commented Mar 9, 2022 at 16:18
  • Alright, looks like you're using the web3.py syntax. Please refer to the web3.js library instead. This is what you wanna use to send a transaction: web3js.readthedocs.io/en/v1.7.1/… And to add an account to sign the transaction: web3js.readthedocs.io/en/v1.2.11/…
    – Franfran
    Commented Mar 9, 2022 at 18:26

0

Your Answer

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

Browse other questions tagged or ask your own question.