3

I am trying to call a function on a contract on the FTM network using web3.py. My code runs, and the final call to sendRawTransaction returns a tx id, but it never makes it to any of the nodes. Can anyone point me in the right direction? Thanks!

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://rpc.ftm.tools/'))
w3.eth.blockNumber # Test, successful

my_addy = w3.toChecksumAddress('0xxxx')

contract_addy = w3.toChecksumAddress('0xxxx')

abi = '''xxx'''

contract = w3.eth.contract(contract_addy, abi=abi)

signed_txn = w3.eth.account.signTransaction({
    'nonce':w3.eth.get_transaction_count(my_addy)+ 3,
    'from':my_addy,
    'to':caddy,
    'gas':98340,
    'gasPrice':Web3.toWei(106.3613, "gwei"),
    'value':Web3.toWei(0, "ether"),
    'data': contract.encodeABI(fn_name="funcation_name", args=[123]),
    'chainId':250,
  },
  'XXprivate_keyXX'
)    

x = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

> x # tx id is being returned, but never makes to a node
HexBytes('0x4xxxxxxx6')
4
  • Why are you using w3.eth.get_transaction_count(my_addy)+ 3 to set the nonce?
    – Ismael
    Sep 14, 2021 at 23:13
  • oops, that's supposed to be +1 -- cut and paste fail when removing private info from gist. (is +1 correct?)
    – dsldsl
    Sep 15, 2021 at 23:32
  • In most cases 'nonce':w3.eth.get_transaction_count(my_addy) should work. If you don't have any pending transaction get_transaction_count returns the next nonce.
    – Ismael
    Sep 16, 2021 at 2:01
  • Were you able to resolve this? I'm having issues with send_raw_transaction function on fantom as well?
    – MSalty
    Nov 4, 2021 at 6:14

1 Answer 1

1

Have you tried using build transaction?

contract = w3.eth.contract(contract_addy, abi=abi)

function_txn = contract.functions.**functionname**(
**kwargs
).buildTransaction({
    'nonce':w3.eth.get_transaction_count(my_addy, 'pending'),
    'from':my_addy,
    'to':caddy,
    'gas':98340,
    'gasPrice':Web3.toWei(106.3613, "gwei"),
    'value':Web3.toWei(0, "ether"),
    'chainId':250
  })    

signed_txn = w3.eth.account.signTransaction(function_txn,'XXprivate_keyXX')
x = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

Your Answer

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

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