Web3 Transactions — a Web2 developer Reveal
Hello, welcome to episode 3 of my web2 to web3 transition series. This episode is about Transactions.
While writing this episode, I struggled on how best to explain what Transaction is from both a developer’s perspective and a non-developer’s perspective. Here’s the scenario I came up with.
Let me paint a scenario;
I have an app that I downloaded, and then I need to create my profile within that app. I expect that on click of the create button in the app, my profile will be saved in a database, true? It is also true that the profile was only saved in the database because I clicked the create button, which directly means an action was triggered by that create button that I clicked. This action that was triggered on the click of the create button is a transaction to the database. The location where my profile is saved is the database.
Using the scenario above, in web3 terms, the database is the Blockchain. The action to create a profile is called a Transaction. This “action” is what this article is about.
A transaction in web 2 will be successful or will revert. This concept is known as Atomicity. In the profile scenario above, if you click the create button and something goes wrong maybe a network issue after you clicked the button, that transaction will revert — meaning that your profile will not be created in the database, but if there was no problem, then that transaction will be successful — meaning that your profile has been created in the database.
This is exactly how it is in web3. The state of the blockchain will only be updated if a transaction is successful or will be reverted if not successful. It either holds true or false — a binary state, or if you prefer, a boolean state.
From the profile scenario above, the state change of the database is triggered by four operations: CRUD operation (Create, Read, Update, Delete) as we like to refer to them in the web2 ecosystem. Let’s see how this applies to the blockchain in web3.
CRUD Transactions
CRUD means Create, Read, Update and Delete. These four operations determine the state of any action on any system, from low-level to high-level systems. From reading to a memory slot in low-level systems to deleting items from slots in memory. CRUD operations happen in every level of computing, and transactions are also guided by these four unavoidable operations.
Let’s talk about how these operations apply to web3.
- Create
Create transactions as the name implies are transactions that trigger a new value to be added to a system, whether in web2, web3, embedded systems, high-level computing, whatever. Any transaction that “creates” or add a new entity is a Create Transaction.
2. Read
Read transactions are simply operations that Read from a system, whatever kind of system it may be. This is simply when you read a value from the computer memory in whatever form you read the value. In web3, this is when you read a value from the blockchain directly or from the local memory of every contract deployed to the blockchain. Yes, each contract has it’s own memory. Read operation is simply reading from memory.
3. Update
Update transactions are the trickiest of the four types. Update transactions can sometimes perform the work of create-transactions. This is common in high-level systems, which tend to perform a create operation during an update transaction. Yes, this happens all the time. An example of this is when you update your profile by adding your phone number, and your country is automatically generated and created for you from the phone number. Update transactions can also perform the work of delete transactions by updating a slot in memory to a null value an example is when a value pointer is updated, causing it to lose access to it’s pointer counterpart. From this knowledge of the dynamics of update transactions, the main work of update transactions is still to update a value in memory by assigning an updated value to that value’s slot in memory. In low-level languages, the new value to be used to update must be of the same data type as the value you want to update. In high-level languages, the conversion to the same data type is done for you before the update happens, and sometimes, a create operation is instead performed — that is, a new memory slot is assigned to the new value — which is a Create Operation. Basically, update operations change a current value to a new value that is assigned to that value’s memory slot. Read it again. It will make sense.
4. Delete
Delete is as the name implies. It removes a value from memory, not delete it. In most cases, data is never deleted from memory. They are updated. It is just an abstraction of what happens at low-level memory. Delete operations involves:
i. removing a value from memory,
ii. updating that memory slot with a null pointer or null value,
iii. or making that value inaccessible by deleting it’s key or pointer to that value’s memory slot.
I wrote about many low-level memory concepts in this section. But I had to because these are knowledge I had gained from web2, which have helped me understand important web3 concepts so far. I’m sure it will come in handy as you progress in web3 as well.
Now that I have explained transactions both from a web2 perspective and a systems low-level perspective. Let’s talk about what makes up a web3 transaction.
Web3 Transactions
Transactions in web3, according to the Ethereum book, are signed messages that originate from an Externally Owned Account (EOA), transmitted by the blockchain network, and recorded on the blockchain. There are many concepts in this above definition that are new to this series. I’ll be explaining them as we progress in this series.
Components of a Web3 Transaction
A transaction ( — a serialised binary message) sent to a blockchain contains the following:
- From / Sender Address: This is the address initiating the transaction. This is a unique identifier for the person initiating the transaction. An address on the blockchain is a unique identifier for each participant on the blockchain.
- To / Recipient Address: This is the address of the recipient of the transaction. This is the destination address where the transaction’s value or data will be sent.
- Value: The amount sent in a transaction, denominated in the token (or currency) of the blockchain.
- Nonce: An incremental unique number specific to each transaction, and is sent from the sender’s address. Nonce is similar to how an auto-increment field or a uuid for each record in a relational database is. Nonce ensures that every transaction is processed in the correct order and prevents replay attacks.
- Gas Price: The amount of gas used in a transaction.
- Gas Limit: The maximum amount of gas that can be used in a transaction.
- Data / Payload: Contains additional information for the transaction. It is mostly used with smart contract transactions.
I am working on another article that talks about these components in detail.
Types of Transaction
There are various types of transactions that can be performed on the blockchain.
- Regular Transaction: Transaction from one account to another. These are also referred to as Value Transfer Transactions.
- Contract Deployment Transaction: This is a contract deployment transaction. These transactions deploy smart contracts to the blockchain. This transaction is a Create Transaction, it creates an address on the blockchain which becomes the address of the created or deployed contract. The bytecode of the smart contract deployed is then sent to the newly created contract address.
- Execution of a Contract: These transactions interact with a deployed contract on the blockchain. This is a Read and Update transaction.
- Token Creation Transaction: This is a Create Transaction. These transactions create other contracts. Contracts that create other contracts are referred to as factory contracts.
- Token Swap Transactions: Transactions involving the swap of tokens directly on the blockchain without a centralized intermediary. This is either a create or update transaction.
- Data Transactions: Transactions that store information on the blockchain. These information are text, images, audio, pdfs, other media files, etc.
Transactions in web3 can not be covered in this episode alone. There are still many aspects of transactions that I’m yet to talk about. The concepts of Nonce, Gas, Transaction receipt, and more.
Transactions affect the blockchain, and that means everything that revolves around the blockchain is also affected. So, expect to see more about transactions in later episodes of this web3 series.
Thanks for reading this article.
Bye for now. 🙂