I just want to know the purpose/functionality of serialize function which we use before broadcasting a transaction:

const serializedTransaction = tx.serialize()
const raw = '0x' + serializedTransaction.toString('hex')

This is the piece of code where I'm using serialize function.

1 Answer 1


The serialize function is used to convert the javascript transaction object into an RLP encoding of the transaction. The RLP encoding processes use a standard method to encodes structures/objects into bytes in a way that they can be sent and understood from one application/library to another - independent of the language they are using.

In this case - the transaction is created using ethereumjs-tx, likely passed to web3 or ethers, and then passed to a blockchain node. All three steps need to work with and understand the transaction, so having it in a format each library / application it is passing through can work with is important.

RLP Encoding

ethereum-js-tx serialization


Your Answer

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

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