Skill 1.2.3

Build, sign and send transactions and interpret receipts

Key Concepts

A transaction contains a to address (absent for contract creation), a value in wei, data, a gas limit, the sender's nonce, the chain ID and fee fields. EIP-1559 transactions (type 2) set maxFeePerGas and maxPriorityFeePerGas; legacy transactions set a single gasPrice. web3.js fills missing fields, such as the nonce and fees, by querying the node.

web3.eth.sendTransaction(tx) asks the node or wallet to sign with an account it manages. For a local key, account.signTransaction(tx) produces a raw signed transaction, and web3.eth.sendSignedTransaction(signed.rawTransaction) submits it with eth_sendRawTransaction. Both return a promise that resolves to the receipt when the transaction is included in a block; the promise also emits events such as transactionHash and confirmation.

The receipt's status is 1n for success and 0n for a reverted transaction, which is still included in a block and still pays for the gas it used. gasUsed × effectiveGasPrice is the fee paid; contractAddress is set for contract creations; logs holds emitted events.