3

While learning how to use the web3.js package I came across two types of transactions:

RawTransactions/ web3.eth.sendawTransaction(...) and

simple Transactions/ web3.eth.sendTransaction(...)

I understand that in order to make a raw transaction you create the transaction object and you set a hex value for every key. What I don't understand is:

1)why do you need to make all the values hex? (ex. the gasLimit, gasPrice, nonce etc)

2)why use a raw transaction instead of the normal one. I undestand that you sign the tx offline and then simply pass the hash but what's the point of doing this? I mean when do you need to make the tx raw?

If you believe there is anything else I need to know study or if you can provide sources that would help, I would really appreciate that.

Cheers!

1

1 Answer 1

1

1)why do you need to make all the values hex?

Because for raw transaction you have to prepare the raw data in the format which is used for signing. This is something which is hidden when using sendTransaction.

You can read about the difference between the two in these two posts:

Difference between transactions and raw transactions in web3.js

What is a "raw transaction" and what is it used for?

2)why use a raw transaction instead of the normal one

If you have an own node locally accessible, you can use sendTransaction, since your accounts are managed within your node. But for the case, that you don't have an own node, you're using 3rd party nodes to rely your transaction to the network. Since you don't want to present your private key to these nodes, you have to prepare and sign the transaction locally (for instance in JavaScript at client-side in your browser) in the raw format and then call sendRawTransaction on the (not necessarily trustworthy) delegating node.

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.