Ethereum : Raw Transaction Creation and Signing
Ethereum is often described as “the world computer.”
You are executing transactions and changing the state of the Ethereum blockchain when you communicate with it.
Have you ever wondered what happens when you perform an Ethereum transaction?Let’s look at an example transaction and see if we can grasp it.
prerequisites
Using the ethereumjs-tx library, we’ll create a raw transaction and sign it.
Let’s look at each field in the raw transaction object to see how they’re set.
nonce : Each Ethereum account has a field called nonce to keep track of the total number of transactions that account has executed.
gasPrice : Price per unit of gas you are willing to pay for this transaction.
gasLimit: Maximum gas you are willing to pay for this transaction.
to: The address to which you are directing this function call.
value: Total Ether you want to send.
data : The message field.
Full code
output
Your geth/parity node broadcasts the signed transaction to its peers, who then broadcast to their peers, and so on.Your local node also outputs the transaction id until the transaction is broadcast to the network, which you can use to monitor the status of your transaction.The hash of the signed transaction object is used as the transaction id.
transactionId = sha3(serializedTx)