5 min read
Transactions in Ethereum are cryptographically signed data messages that contain a set of instructions. These instructions can interpret to sending Ether from one Ethereum account to another or interacting with a smart contract deployed on the blockchain. Transactions are a simple but powerful concept that has allowed users worldwide to interact on a decentralized network. This guide will cover the idea of transactions in the context of the Ethereum network.
What we will cover
- Transaction fundamentals
- Transaction architecture
- Viewing transaction data programmatically
What you will need
- Terminal window
A transaction usually consists of the following parameters: [nonce, gasPrice, gasLimit, to, value, data, v, r, s]. However, Ethereum has evolved to allow other transaction standards such as EIP-1559. The EIP-1559 transaction standard came from an improvement proposal to allow more predictable gas fees and a more efficient transaction market. Before going over transactions, let us quickly recap where transactions derive from.
There are two types of accounts, smart contract accounts and externally owned accounts (EOA):
- Externally owned accounts (EOA) refer to accounts that humans manage, such as a personal Metamask or Coinbase wallet. This account is identified by a public key (also known as an account address) and is controlled by a private key. The public key is derived from the private key using a cryptographic algorithm. It's important to note that these accounts cannot store information other than your accounts balance and nonce.
- Smart contract accounts (also known as contract accounts) also contain an address to balance mapping but differ because they can also include EVM code and storage. Contract accounts control themselves by the logic in the EVM code stored within the account.
Ethereum utilizies the elliptic curve digital signature algorithm (ECDSA) to prove authentication (i.e., prove that we have a private key for our public address) and verify that our transaction comes from the account signing the transaction and is not fraudulent.
Types of Transactions
Let us tie the information we just learned about accounts with the different types of transactions:
- Message call transaction: A message call derives from an externally owned account that wants to interact with another EOA or contract account. An example of a message call would be sending Ether from one account to another, or interacting with a smart contract (e.g, swapping tokens on Uniswap).
- Contract creation transaction: A contract creation derives from an EOA to create a smart contract account (generally to store code and storage). An example of this type of transaction would be deploying a storage smart contract to store data.
- Pending: Transactions broadcasted to the network waiting to be mined. If the transaction is taking longer than expected, it's possible that your gas fee is not high enough to meet execution at the current time.
- Queued: A transaction that cannot be mined yet due to another pending transaction in the queue first or an out of sequence nonce.
- Cancelled: Can no longer be mined. Replaced by a transaction with a higher gas fee, same nonce value, and a null value for the data and/or value field.
- Replaced: Can no longer be mined. Used to replace current pending orders for faster execution or modification of values and data. This also consists of using the same nonce as the transaction you want to cancel and a higher gas fee.
- Failed: A transaction that resulted in an error due to a revert error, bad instructions, illogical code, or not enough gas to run the remainder of a function call.
For an in-depth look into pending and queued transactions, visit our QuickNode guide here.
The transaction format for Ethereum was originally one standard but has evolved over time to allow other transaction formats. The set of instructions in a transaction object looks like this:
- from - the sending address.
- to – the receiving address (if EOA, the transaction will transfer value. If a smart contract account, the transaction will use contract code).
- value – the amount of ETH to be sent from the sending address (denominated in Wei)
- data – can contain code or a message to the recipient.
- gasLimit – the maximum amount of gas units that can be used.
- nonce - a number used to track ordering of transactions and prevent replay attacks
- maxPriorityFeePerGas - the maximum amount of gas to be included as a tip to the miner.
- maxFeePerGas - the maximum amount of gas willing to be paid for the transaction (including baseFeePerGas and maxPriorityFeePerGas).
- signature – derived from the sending account's private key and is created when the sender signs the transaction.
As you can tell from the fields above, the term gas gets mentioned several times. It is an important piece of a transaction. Transactions use gas as fuel to execute and be mined onto the blockchain, but more importantly, gas fees help keep the Ethereum network secure. Gas is paid in Ether (the native coin on Ethereum) but denominated in other units such as Wei and Gwei to be more measurable. Wei is used when describing smaller value transactions, and Gwei is commonly used when dealing with gas fees.
The transaction lifecycle can be simplified to:
- An external account creates a transaction object.
- The account sending the transaction verifies it by signing which creates a transaction hash
- The transaction is broadcasted across the network using an Ethereum node
- The transaction execution is idle until the transaction is mined and added to the block or replaced/canceled.
Set Up Your QuickNode Ethereum Endpoint
Now let's take everything that we've learned and see it in action. We'll easily set up an Ethereum endpoint with QuickNode and use it to retrieve a transaction by its hash. If you already have an account, navigate to the Endpoints page and fire up an Ethereum mainnet endpoint. Otherwise, create an account on our signup page.
Viewing Transaction Data Programmatically
Start by opening up your terminal window and run the command curl (check if you have proper dependencies). If you get the response `curl: try 'curl --help' or 'curl --manual' for more information`, great you have the required dependencies and can run the curl code below.
Copy the code below and replace the URL placeholder with your QuickNode endpoint. Paste the modified code into your terminal and hit enter.
The output should contain the same values as below:
To see additional QuickNode RPC endpoints you can call, navigate to our QuickNode Docs.
That's a wrap! In this guide, we explained the core concepts of transactions on Ethereum. Remember that Ethereum follows an Account-Balance model and can utilize different types of transactions for different use cases. We hope you continue to advance your learning and share it with others.
Subscribe to our newsletter for more articles and guides on Ethereum. Feel free to reach out to us via Twitter if you have any feedback. You can always chat with us on our Discord community server, featuring some of the coolest developers you'll ever meet :)