0

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

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

1
  • Thank You for your assistance. – Haider Yaqoob Jan 25 '20 at 17:59

Your Answer

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

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