Ethereum Transactions – Should the RLP Encoded or Hashed Raw Transaction be Signed?

transactions

I'm trying to understand how to create Ethereum transaction from scratch but I'm not sure what am I supposed to sign.

Should I sign the hashed rlp encoded transaction or just the rlp encoded raw transaction?

  1. Rlp encoded tx: f83a1854a817c80821458a83730393937393730433531383132646333413031304337643031623530653064313764633739433885174876e8080
  2. Rlp encoded hashed tx: Hash(f83a1854a817c80821458a83730393937393730433531383132646333413031304337643031623530653064313764633739433885174876e8080)

Thanks!

Best Answer

you are supposed to sign the transaction hash. the hash is 32 bytes.

the hash is returned by Hash() function of Ethereum API and it is a complex function which will depend on block number. the block number will tell what kind of fork is Ethereum currently on (London,Berlin, EIP155, etc). Depending on Ethereum fork, the process of generating these 32 bytes (the hash) you need to sign will be different, and of course it will be rlp-encoded internally (the order/amount of fields varies depending on the fork).

the signature must be produced by ECDSA algorithm and comply with its format (as the standard specifies). these are the R/S/V fields which are set by the API after your transaction is signed (by common libraries we all use)

all of this stuff is already done by the libraries so you just have to call the appropriate functions to avoid reinventing the wheel

Related Topic