What's the Anatomy of a Blockchain Transaction?
When we talk about ‘transactions’ on a public blockchain network, we’re usually talking about interactions between two addresses: in other words, tokens, be they fungible or non, or other crypto-assets being ‘sent’ from one address to another. There are also “internal transactions”, which are interactions that occur between smart contracts, and for the most part fall outside of the scope of this article.
For clarity’s sake, nothing is actually being sent anywhere. A smart contract-enabled blockchain network like Ethereum has a number of different components, but the ‘backbone’ of the system is a distributed ledger. What’s that? Imagine a spreadsheet that contains, on one side, every single Ethereum wallet address, and each one of those addresses has a column for each type of crypto-asset that it holds.
Let’s use an example for illustration. Say that Guillaume wants to send a transaction to Dolores. Guillaume has 1.36 ETH in his account, and he plans on sending Dolores 0.5 ETH. Sounds like a good day for Dolores.
Guillaume opens up his MetaMask wallet, enters Dolores’ address, configures the gas parameters that he’s comfortable with paying, and hits ‘send’.
At this point, the transaction enters a local temporary holding status, known as the local memory pool, or local mempool. The transaction will then get ‘picked up’ by the closest node in the network. Depending on Guillaume’s gas settings, his transaction will be prioritized (the more Guillaume is willing to pay per unit of gas, the faster his transaction will be processed), and propagated to other nodes in the network. The nodes will do the work of verifying that Guillaume has the ETH to spend, and then will actually perform the ‘transaction’: the ledger will be modified; 0.5 will be debited from Guillaume’s balance, and 0.5 will be credited to Dolores’.
‘The moving hand, having writ, moves on’: ETH didn’t move through a network per se; it wasn’t an email sent from Guillaume’s computer to Dolores’ MetaMask inbox or anything of the sort. Guillaume sent a request, authenticated by his private keys through MetaMask, to the network to debit his account and credit Dolores’, and after the verification process programmed into the network’s protocols, this was done.
That’s all there is to a transaction: a request to the ledger to reallocate something from one address to another.
When things go wrong
Things can go wrong for a number of reasons. Often, they’re ‘software in nature’: MetaMask has a bug, or something was misconfigured regarding the network you’re trying to use; there was a connectivity error.
A common issue is that the user, in an attempt to pay less for their transaction, sets a very low gas limit, and network conditions are so congested that there isn’t space in any blocks for such a “cheap” transaction, sometimes for a very long time: eventually, this transaction will become “stale” and will have to be canceled by the user.
If you’ve sent a transaction and it hasn’t been finalized, its status will be shown as “pending” in MetaMask.
If you sent a transaction, and it failed, the most likely cause is a lack of gas: you “ran out of gas”, in other words, the transaction had a cost in gas that, when multiplied by the gas price, resulted in a total amount of the network’s native currency that was greater than what you had in your wallet.
For more on calculating gas, consult our gas guide here.
This can happen for a number of reasons, but one thing to consider is what the transaction is that you’re trying to carry out. Minting an NFT during peak network traffic times can be very gas-intensive; if you’re trying out a new or experimental transaction, it may be worth trying on a test network before paying real live network fees.
Another common problem is when users go too far in the other direction. In an attempt to save as much money on gas as possible, they configure a custom amount of gas that is so low that the transaction never gets picked up and included in a block. It will stay, pending, for a number of days in this state, until it is considered “stale” and is “reverted”, which means the network considers it never to have happened: the transaction failed.
If you’ve run into one of these issues, take a look at the Knowledge Base version of this article for next steps.
Your mind on your tokens, and your tokens on your mind
If it helps you to use the mental model of a transaction moving a balance from one wallet to another, then by all means, keep at it—on a day-to-day basis, this is what your experience will be like, and as the UX engineers of Web3 keep doing their jobs, it should become more and more seamless. But keep that ledger in the back of your mind for when things get complicated.
And keep an eye on this space—soon we’ll have a piece from another member of the team, breaking down some of the most common crypto scams.