Difference between sendTransaction and sendRawTransaction in web3.py
Asked Answered
M

1

6

What are the practical differences between these web3.py methods for sending a transaction?

  • w3.eth.sendTransaction({})
  • w3.eth.sendRawTransaction(signed_txn.rawTransaction)
Mojgan answered 22/6, 2018 at 10:19 Comment(0)
F
8

w3.eth.sendTransaction() only supports sending unsigned transactions. In order to use it, your node must be managing your private key. Since the node must manage your key, you must not use it with a hosted node.

w3.eth.sendRawTransaction() requires that the transaction be already signed and serialized. So it requires extra serialization steps to use, but enables you to broadcast transactions on hosted nodes. There are other reasons that you might want to use a local key, of course. All of them would require using sendRawTransaction().

Fail answered 22/6, 2018 at 16:47 Comment(2)
Do I need to have my account unlocked in order to use sendRawTransaction()? Im currently trying to transact with a smart contract and am signing transaction and then sending raw transaction separately..Resuscitate
@walksignison No, unlocking an account is something you do with a hosted key, and sendRawTransaction() is used with a local key. If you can't find the question already on stackoverflow, it may be on ethereum.stackexchange.comFail

© 2022 - 2024 — McMap. All rights reserved.