0

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 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 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 at 2:01
  • thank you, great tip!
    – dsldsl
    Sep 16 at 7:09

Your Answer

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

Browse other questions tagged or ask your own question.