[Ethereum] Difference between transactions and raw transactions in web3.js


Reading the documentation of web3.js I have come across sending transactions and raw transactions.In the documentation it's specified that send raw transaction sends an already signed transaction.

Does this imply that web3.js does not sign transactions when sendTransaction() is called?

Best Answer

All transactions need to be signed. Otherwise they are considered invalid transactions and will not be included in the blockchain.

A raw transaction is a transaction in raw bytes. If one has the raw bytes of a valid transaction, they can use sendRawTransaction. Otherwise, web3.js creates the signed transaction's bytes for you automatically as part of sendTransaction(). web3.js converts the JSON transaction {from:..., to:..., value:...} to the raw bytes and signs it for you automatically.

Raw bytes are required if you are using a platform like infura.io which does not handle private keys but deal only with signed transactions.