Ethereum Transactions
Hello friends, Hope you are doing good and having fun. I am here with another article on the blockchain. Previously, we have discussed the blockchain, some of its concepts, and its characteristics, and today I will talk about transactions. We would also explore the concept of gas in this tutorial. So let’s start by defining a transaction.
What is Ethereum Transaction?
- A transaction is a message signed by an account owner that is added to a block and recorded in the blockchain.
- A transaction is initiated by an externally owned account and then it gets transmitted to the Ethereum network.
- It can be originated only by an externally owned account (an account owned by a human) and not by a contract account.
- Through transactions, one can interact with the Ethereum world. As a result, they change and update the state of Ethereum.
- The transaction can be any action such as transferring ether or calling functions of a smart contract. Consequently, the state of the Ethereum virtual machine (EVM) is changed. For example, when account x transfers some ether to account y, a transaction is initiated and after that, the balances of both accounts are updated. The new balances are then stored in the Ethereum network.
- Any account or node has the right to initiate a transaction. But it must be verified through mining.
- Every transaction has a gas limit and a gas fee. This fee is given to miners as a reward for verifying (or mining) that transaction. I will cover the concept of mining in my next tutorials.
These points highlight the importance of a transaction. You can see that a transaction is the only thing that can change the state of the Ethereum virtual machine. By transaction, you can execute a smart contract or deploy a new smart contract to Ethereum and there is no other way to do that. Contracts cannot deploy themselves, contracts cannot call other contracts unless a transaction is initiated by an externally owned account. So, the Ethereum network state depends on the transactions.
Now, this was the definition and importance of a transaction in the blockchain. In the next part, I am going to explain the structure of a transaction.
Structure of Ethereum Transaction
Any transaction in the Ethereum network has some specific components when it is transmitted to the network. Every node receives the transaction and stores it in its memory. The data of a transaction or the components are listed below:
1. Recipient:
- The address of the account that will receive the transaction is called the recipient. The recipient can be an externally owned account or a contract account. Each transaction is directed towards a recipient.
2. Nonce:
- A nonce is a number showing the sequence of a transaction, Nonce is assigned by the account initiating the transaction.
3. Gas Price:
- Any transaction requires some fee that is paid by the creator of the transaction. The fee is calculated per gas unit. The unit is Wei a smaller unit of ether.
4. Gas Limit:
- The creator of the transaction gives the number of gas units that can be used for the transaction. This is the maximum limit of gas that would be consumed.
5. Value:
- The value specifies the amount of Wei or Ether that the sender account wants to send to the recipient.
6. Data:
- If a transaction recipient is a smart contract then the data contains information for executing functions of the contract. This includes data of variable length.
7. Signature:
- A Signature is the identification of the sender. The signature is generated when an externally owned account confirms and signs the transaction via its private key.
These are the components included in a transaction. In the next section, I will discuss the types of transactions in the Ethereum blockchain.
Types of Ethereum Transaction
The transactions can be classified into three general types that are listed below and defined further.
- Funds Transfer
- Contract Deployment
- Function Execution
Funds Transfer
This type of transaction takes place whenever an account sends some funds (in form of ether) to another account. This transaction has a value associated with it but does not have any data. For example, when account A sends some money to account B for buying something. The gas price is set by the sender.
Contract Deployment
Whenever a contract is deployed on the Ethereum network, this transaction takes place. It has data that is the bytecode of the smart contract. There is no recipient for this kind of transaction. The gas limit must be enough for deploying a contract.
Function Execution
After a contract is deployed on Ethereum, its functions can be called. When a function is called by an account, then this type of transaction occurs. The transaction is directed towards a contract account, therefore the recipient is a contract address. The data contains the function name and its arguments.
So, friends, this was a general classification of transactions. Up till now, you must have got an idea of a transaction and its components. The steps of a transaction generation till its confirmation can be listed as below:
- A transaction is initiated by the sender. The sender’s account provides important information such as recipient address, data, value, and gas limit. After generation, a hash is created that is called a transaction hash.
- The transaction has is a unique identifier for a transaction. An example of this hash is given below:
0x2446f1fd773fbb9f080f674b60c6a033c7ed7427b8b9413cf28a2a4a6da9b56c
- The transaction generated is transmitted to the network and added to the transactions pool waiting to be confirmed.
- A miner picks transactions for the pool to add to the block. This verifies the transactions. When there are a lot of transactions, the waiting time is more. Therefore, a transaction with a higher gas price would be picked first by a miner. In this way, the miner will get more money.
- A number called block confirmation number is given to a verified and added transaction. This shows the number of blocks created after the block in which the transaction was added. As the chain length of the blockchain increases, the transaction becomes more and more trusted and immutable.
This is the process through which a transaction passes. I hope you have an idea of it's working. Next time I will be here with another topic. Till then, take care!
What is Solidity Programming
Hello friends, hope you are doing fine and doing great. In the previous tutorial for introducing Smart Contracts, I told you about Solidity. Solidity is a high-level programming language for writing smart contracts. It is the most popular programming language for Ethereum. So, in this article, I will explain the basic components of solidity. Let’s get started by revising the key points of solidity.
Solidity Programming
- Solidity programming language is made for writing code for the Ethereum platform. These codes (smart contracts) help in executing different functions in Ethereum virtual machine (EVM).
- It is easy to learn the language. If you are familiar with C and JavaScript, you can easily learn solidity.
- The code written in solidity is converted into bytecode by solidity compiler. The compiler of solidity language is solc.
- The extension of a solidity file is .solc.
- It is a case-sensitive language.
- Solidity is a statically typed language.
- The process of writing and compilation is shown in the figure below.
The layout of a Solidity File
In this section, I am going to discuss the general layout of a solidity file. It contains different components. The layout of a solidity file is explained below. It has:
- Pragma
- Comments
- Import
- Contract / Library
Pragma in Solidity Programming
- Before writing the solidity program, you want to mention the version of solidity compiler. So that anyone using the file can choose the correct version for compilation.
- For this purpose, pragma directive is used. It specifies the compiler version of the file.
- Solidity is still growing and a lot of improvements have been made since its development. Therefore, the version keeps on improving.
- The current solidity version is 0.7.4.
- The version is mentioned by using the following syntax.
pragma Solidity ^0.7.0;
I should mention here that semi-colon is the statement terminator in solidity.
- It is declared as the first statement of the program.
- The version number comprises a major build number and a minor build number. When you use ^ character with version number, it means the latest version of the major build number.
- For example, as I declared the version 0.7.0 with ^ character. Here major build number is 7. So solidity compiler of version 7 will compile it.
Comments in Solidity Programming
- Guys, if you are familiar with programming, you must know that programming languages support the option of commenting. Solidity also provides this facility.
- There are two types of comment in solidity:
- Single-Line Comments: single-line comment means a comment comprising of one line only.
- Multi-Line Comments: multiline comments consist of more than one line.
- Forward slashes are used for denoting comments. Single line comment is denoted by double forward slash //. While multiline comment starts with /* and ends with */.
- It is a good practice to add comments to your program. This improves readability.
Import in Solidity Programming
- The import keyword helps in importing other solidity files. These files can then be used in code.
- The functions of the imported file can then be used in a solidity file.
- This functionality helps us in writing code in the form of modules. In this way, lengthy code can be converted into smaller readable ones.
- The syntax for using the import keyword is given below:
import filename;
- The address of the file is mentioned within the import statement.
Contract / Library in Solidity Programming
- The contracts are defined in the solidity file.
- You can define more than one contract or library in one file.
- Contracts, libraries and interfaces can be defined one after the other in a file.
So, this was the general layout of a solidity file. Now, I will move to the next section in which we are going to discuss the structure of a contract.
Structure of a Contract
Contracts are somehow similar to classes in OOP (Object Oriented Programming) Languages. The contracts are written for ethereum virtual machine. Just like other languages, contract code contains functions and variables. The contracts can also inherit from other solidity contracts. There are two special types of contracts in solidity called library and interface. In this section, I have discussed different constructs in a contract. The contract consists of the following:
- State Variables
- Structures
- Modifier Functions
- Event Declarations
- Enumerations
- Functions
Now let’s define these for further understanding.
State Variables
- Variables store values in storage locations. The value saved in a variable can be change or update while programming execution.
- Once a variable is declared, you can use it anywhere in your program, at multiple locations.
- State variables are stored in Ethereum blockchain permanently. The changes in their value and their current value is secured.
- The data type of state variable is declared while writing the program.
- Other qualifiers, used while declaration, are listed below:
- Internal
- Private
- Public
- Constant
- The following data types can be used in solidity:
- Bool for boolean
- Uint / int for unsigned / signed integer
- Bytes for 8 bit signed integer
- Address for addresses of accounts
- Mapping for mappings
- Enum for enumerations
- Struct for structures
- String for character strings
Structure
- With the help of structure, you can define a data type of your own.
- A structure is a composite data type and that means it can contain different variables having different or same data types.
- A group of variables is defined in a structure. Each one is given a name and a data type.
- A structure is declared by using the struct keyword.
Modifier
- A modifier is a function that can change the behavior of the code.
- In solidity, modifiers are used with functions, so they can change the actions of a function.
- If you are calling a solidity function that has a modifier associated with it, then the modifier function will execute first. After its execution, the called function would be executed.
- You will define modifier function only once in the program but you can use it anywhere with multiple functions.
Events
- If you are familiar with programming, you know that different programming languages support events.
- Solidity also supports events. Events tell about the change in the state of a contract.
- With the help of logs, the caller can view the state of the contract after execution.
- Events are declared outside functions, at the global level. Then these events can be called in any function.
- The keyword for event declaration is an event. After that, the identifier is declared followed by a parameter list. The parameter list contains the data type of the variables.
Enumeration
- Enumeration provides us with an interesting facility. With the help of it, you can define a data type of your own choice.
- It contains a list of constants, from which the variable can take values.
- Each value is given an integer starting from 0 for solidity.
- The enumeration is declared by the enum keyword. After the keyword, the identifier is defined followed by the list of constant values in brackets.
- There is no semi-colon at the end of the enum declaration statement.
Function
- Just like any other programming language, a function is a key component of solidity.
- Whenever a transaction is initiated, a function of a smart contract is called.
- Functions can read and write state variables. When a function is executed and a transaction is processed, the state variable may change its state.
- A function can take input parameters, perform operations on them and can return values. The return values can be more than one.
- A function has a name that is its identifier. This identifier can be used anywhere in the program for the execution of functions.
- You can use various qualifiers with a function declaration that decides the visibility of a function. These qualifiers are listed below:
- Public
- Private
- Internal
- External
- Other than visibility qualifiers, some other qualifiers are also used with functions. These show the ability of the underlying function in terms of changing values of state variables. The qualifiers are given below:
- Constant
- View
- Pure
- Payable
So, friends, I have tried to give you a basic idea of the structure of a solidity program. It is not compulsory for a program to have all of the above-listed features. I hope you have learned and got a good understanding of the basics of this language. That was all from my side. Please let me know if you have any questions. I would love to answer them. I am signing off for today, Take care!
Structure of a Block in Blockchain
Hello guys, hope you are doing good and enjoying your lives. Today, I am going to introduce you to the blocks of a blockchain. I gave you an understanding of blockchain, its characteristics, and some idea about accounts and wallets in my previous tutorials, and today my article is about the structure of a block in the blockchain.
I will first define the block before going into the details about its structure. So let’s start without any further delay.
Block in Blockchain
- A block is actually the building block or the key element of a blockchain.
- The definition of a blockchain is based on its blocks. As I defined in my previous posts, a blockchain is a chain of multiple blocks.
- Blocks contain transactions. Each block contains a different number of transactions.
- These transactions are contained in blocks so that they would be added to the distributed ledger.
- The number of transactions is limited by the block size and gas limit. Generally, the block contains more than 500 transactions.
- Other than transactions, a block also consists of some metadata. This metadata is stored in the header of the blockchain.
- The size of a block header is 80 bytes, the detail of which is given in the upcoming sections of this article.
- Let’s first define a parent block in the next part.
Parent Block in Blockchain
As the blocks are linked together one after the other, they have a parent-child relationship. Each block is the parent of the upcoming block. Each child block contains the hash of the previous block i.e., its parent block. The first block of the blockchain is called Genesis Block and it has no parent.
The block contains different fields which can be roughly categorized as listed below:
- The block size: The size of this field is 4 bytes and it contains the size of the block.
- The block header: The size of a block header is 80 bytes. It further contains different fields.
- The transaction counter: This field contains the number of transactions and the size of it is between 1-9 bytes.
- The transactions: This field contains transactions of the block and its size is variable.
This was some information regarding the fields of an Ethereum block. Now, we will move towards the next part in which I am going to give you an idea about the block header and its fields.
Block Header in Blockchain
The header of an Ethereum block contains different fields of metadata which are listed below.
- Hash of the previous block: Every block header gives information about the previous or parent block. This field contains the hash value of the previous block and this reference connects all the blocks. The size of this field is 32 bytes.
- Version: This field stores the version number to show software upgrades. The size of the version field is 4 bytes.
- Difficulty: The mining difficulty at the time of the block creation is stored in this field. The concept of mining would be explained in the upcoming articles. Its size is 4 bytes.
- Timestamp: This field contains the time at which the block was created. The size of this field is 4 bytes.
- Nonce: A nonce is a value used during the mining of the block. This field’s size is also 4 bytes.
- Merkle tree root: A Merkle tree is a structure obtained from hashing the transactional data of a block. The root of this tree is stored in the block header under this field. 32 bytes is the size of the Merkle tree root field.
This was all about the header of a block. In the next part, I am going to give you an idea about the properties of a block.
Properties of a Block:
There are a lot of properties of a block that give us important information about it. I am listing down the properties here.
Difficulty Property:
- As I mentioned earlier, this property gives the difficulty level of solving the puzzle to mine the block.
totalDifficulty Property:
- This property of the block tells us the total difficulty of the blockchain.
gasLimit Property:
- This property tells us the maximum gas allowed by the block which in turn tells us about the number of transactions that the block can accommodate.
gasUsed Property:
- The gasUsed property gives the amount of gas used by the block for executing all of its transactions.
Number Property:
The number shows the block number in the list of blocks.
Transactions Property:
- This means all of the transactions contained in the block.
Hash Property:
- This property shows the hash of the block.
parentHash Property:
- This property saves the hash of the previous block.
Nonce Property:
- Nonce property shows the nonce value that I defined earlier. It is a variable used in mining the block.
Miner Property:
- The miner property gives information about the miner of the block. This gives the account of the block miner.
So guys these were the properties of a block. I will move towards the next part i.e., the identification of a block.
Block Identification:
The blocks of a blockchain need an identification to refer them or distinguish them from other blocks. Two parameters are used for this purpose which are given below:
1. Block Hash
Block hash is the main identification parameter of a block. This value is obtained by cryptographic hashing of the header of the block. The hashing operation is performed twice. The header of the block contains metadata of the block and when this data is hashed the result is the block hash, whose size is 32 bytes.
The hash of the block is not stored in the block’s data whether the block is being transmitted to the other nodes or it is stored as part of the blockchain on some node. When a node receives a block from the network, it computes its hash itself.
2. Block Height
The second parameter used for identifying a block is its height. As we already know that the blocks are linked together in a list type structure starting from the genesis block. The genesis block is given a height 0 zero. The second block in the blockchain or the first block after the genesis block is at height 1 and so on.
In this article, I have explained the structure of an Ethereum block. The article explained the header and some properties of the blocks. I hope you have learned something new from it. Take care!
Smart Contracts: Definition, Working, Writing & Deploying
Hello friends, Hope you are doing fine and having a good time in your life. The topic that I am going to discuss today is a very interesting and important one in the context of blockchain. I will discuss smart contracts in this article and I am sure you will learn the concept by the end of this tutorial. I have mentioned smart contracts in my previous articles and defined them before.
Before discussing smart contracts, let’s first revise what a contract is, and then we will talk about smart contracts.
Contract
- When two persons or two parties want to carry out a deal or a transaction such as buying property, they need some proof for future reference.
- So, a contract between two or more individuals is a legal document that serves as proof for the transaction.
- All conditions of the transaction are mentioned in the contract and must be fulfilled by the involved parties.
This was the basic idea and revision of the concept of a contract. Now, I will introduce a smart contract in the next section.
Smart Contract
When reading about blockchain and decentralized applications, you must have encountered the term “Smart Contract”. The name may indicate to you that it could be a contract that executes smartly or that has smart conditions. Well, in actuality, it is a contract whose conditions fulfill when it executes. If the conditions of such a contract are not met, then the execution fails.
- In the Ethereum blockchain, a smart contract is actually a program that is deployed on Ethereum.
- The smart contract contains logic and it is written in some high-level language.
- An example of a high-level language is solidity that we will discuss in the upcoming tutorials.
- A smart contract is a set of rules that are coded in the form of a program. These rules govern the transactions between the Ethereum accounts. The transaction could be a transfer of assets, transfer of money, or a change of Ethereum state.
- In Ethereum, the type of account having a smart contract is called “Contract Account”.
- Smart contracts can have balance and can also store data. They contain several functions that can be called by other accounts.
I have told you earlier that only an externally owned account can initiate a transaction on Ethereum and call a smart contract. Once initiated, the smart contract can call other smart contracts deployed on Ethereum or it can deploy a new contract.
Writing Smart Contracts
In this part of the tutorial, we are going to discuss writing smart contracts for Ethereum. Various tools are available for writing smart contracts. First, let’s talk about Remix.
Remix
- The remix is an Integrated Development Environment for writing smart contracts.
- It is a browser-based IDE and helps in developing contracts easily.
- The language used is Solidity.
- It helps in the following functions:
- Writing and developing smart contracts
- Deploying contracts on Ethereum networks
- Troubleshooting contracts
- A remix is an open-source tool available freely for everyone. So, if you are not comfortable using the online version, you can simply download it and use its functionality.
- The downloaded version can be used offline on a local computer system.
- The general steps for writing a smart contract using the online tool are given below:
- Open your browser and type https://remix.ethereum.org/ in the address bar.
- The site will show some default contracts. You can use that, study that or you can simply delete that if not needed.
- On the left bar, there would be an option to create a new file. Use that to create your smart contract.
- Write the code for your smart contract in the newly made file.
- The next steps are to compile the contract using a solidity compiler and deploying it on the network.
- After deployment, the functions written in the contract code can be executed.
This was a brief introduction to remix. Let’s talk about Solidity now.
Solidity
- Solidity is a high-level programming language used for writing smart contracts.
- This language has similarities with C and JavaScript languages.
- Solidity is case-sensitive.
- The extension of a solidity file is .solc and this file contains code.
- You can write and read such a file in any text editor.
- The solidity compiler is used for the compilation of code and named “solc”. The compiler generates the bytecode of the smart contract.
- This bytecode is generated for the Ethereum virtual machine as it cannot understand code in the high-level language.
- You can install solc using npm by typing the following command in the command prompt.
npm install –g solc
Remix and Solidity are the two essential tools for writing smart contracts. In the next part, we will discuss the deployment of contracts.
Deploying Smart Contracts
The contracts are deployed after compilation. The solidity compiler performs this task and generates two main outputs that are listed below:
- ABI
- Bytecode
Now let’s explore these two concepts.
ABI
- ABI stands for Application Binary Interface.
- ABI of a smart contract contains a declaration of all public and external functions. It also contains their parameters and returns types.
- ABI is the definition of a contract. Any account that wants to execute a contract function uses its ABI.
- After deployment, the contract instance is created using its application binary interface.
Bytecode
- The bytecode is understandable by Ethereum and helps in deploying the contract on the Ethereum virtual machine.
- Ethereum virtual machine cannot understand solidity so bytecode is a must.
ABI definition and bytecode both are necessary for deployment. The transaction for deploying a contract on EVM takes place and an address is generated for the smart contract. This address is the identifier of the contract. Any function of the contract can be called and executed using the contract address.
So, guys, this was all about smart contracts. We discussed the main idea and some steps to create a smart contract. The two main tools for creating a contract are also discussed in this tutorial. I hope you have learned these concepts and enjoyed reading them. That’s all for today. Take care and have fun.
dApps: Definition, Features, Comparison & Developing Tools
Hello friends, hope you are doing fine and enjoying your life. In today’s article, I am going to discuss decentralized applications that are abbreviated as dApps. With the invention of blockchain technology and afterward Ethereum, the idea of decentralized applications has gained a lot of attention. So let’s get into the details and learn what a dApp is.
Decentralized Applications (dApps)
- An application built on a decentralized platform such as Ethereum is called a Decentralized Application(dApp).
- A dApp generally consists of a backend and a frontend.
- The backend of a dApp is a smart contract mostly written in solidity language.
- The front end of a decentralized application is the user interface. The user can interact with the application using the frontend.
- Smart contracts available on Ethereum are open for anyone. So, a dApp can use the smart contracts present on Ethereum other than its own backend.
- Now l am going to give you the similarity and differences between a centralized application and a decentralized application in the next section.
Centralized vs Decentralized Application
In the traditional internet system, there is a central server and various computer systems connected with it. The backend program of centralized applications runs on that central server. While in decentralized applications, the backend program runs on a decentralized network. I have discussed the decentralization concept in my previous articles.
The front end of a centralized application can be written in various languages such as HTML. The front end of the application connects the user with the functionality of the backend. Similarly, in decentralized applications, the front end can be written in any programming language and that will help the user in interacting with the backend.
In the upcoming section, I am going to discuss smart contracts. We have already discussed them before. So we will try to make a connection of a dapp with smart contracts.
Smart Contracts
- A smart contract is simply a program that is controlled by its logic.
- The logic given in the code controls the execution of the smart contract.
- It is deployed on the Ethereum network by an account.
- The backend of a dApp is written in the form of smart contracts. Thus, smart contracts control the execution of a dApp.
Features of a dApp
In this part of the tutorial, I will talk about the characteristics of a DApp that make it so useful. These are listed below:
Decentralization
- As a dApp runs on a decentralized platform, it is independent.
- No central authority controls it. A dApp is controlled by the backend logic.
Deterministic
- The output of the dApp is known. It will always produce the same result with the same conditions.
Open Source
- The dApps are open source and available for anyone. The dApp’s operation is autonomous.
Transparency
- Dapps provide transparency, trust and audibility. The data is secure and accessible to anyone.
Turing Compatibility
- As Ethereum is Turing complete, a dApp on Ethereum is Turing compatible.
Isolation
- All dApps on Ethereum virtual machines are executed independently in a virtual environment.
- Any errors in one code do not break the functions of the rest of the network.
Privacy
- While using or deploying a dApp, the user does not have to provide his real identity and that helps in privacy.
Data Integrity
- Data is secure and immutable in dApps. No hacker or malicious entity can change the data.
No Downtime
- When a decentralized application is deployed on the peer-to-peer network, it is available for everyone.
- Not like traditional systems, where a failure in the central server makes the app unavailable.
These are some features of a decentralized application. Along with these features, some other points make Ethereum dApps different and usable. I am listing some of those exciting features below:
- A dApp is uncensored as no party has control over it.
- A dApp is able to create digital assets.
- A dApp can create a new currency.
- A dApp allows you to use the functionality of decentralized systems in any application.
- Any node can use a dApp and connect to the Ethereum network.
Tools for Developing dApps
A variety of tools are available for developing dapps. Some of them are listed below:
- Programming Language
- Web3 Library
- Development Frameworks
- Integrated Development Environment
- Blockchain
- Ethereum Network
- Wallet
Programming Language:
- A programming language for writing smart contracts is needed while developing a dApp.
- The most common one is solidity.
- Vyper and LLL are two other options for writing contracts.
Web3 Libraries:
- Web3 library provides an interface for interaction with Ethereum nodes. They are available in different language options. Such as web3.js and ethers.js for javascript and web3.py for python.
Development Framework:
- The development framework helps you in performing operations such as compilation, ABI generation and testing etc.
- The most common development framework is Truffle. It is node-based and the most used one.
IDE:
- IDE or Integrated Development Environment also helps in dApp development.
- The Remix is an online IDE that you can use from your web browser. It is the most convenient option.
- You can also use the Visual Studio extension for solidity.
Blockchain:
- While testing your dApp, you need some development blockchain where you can quickly deploy your contracts and test them.
- Ganache is the tool for that facility. It creates a local blockchain on your system.
Ethereum Network:
- While working on the dApps, you have the option to deploy it on the network of your choice.
- For example, while testing you can use the test network.
- There is no value of ether on the test network, so you can easily test your dApp.
- Ether has value on the main Ethereum network, named Mainnet.
Wallet:
- A wallet is a software application that is used for keeping track of the balance and managing keys.
- Various wallets are available with different functions and security levels. The common one is Metamask, a web-based wallet.
These are some of the tools that you need for developing a dApp. With that, I am concluding this article. I am hoping you have got some good information from this tutorial. Let me know if you have any queries. Take care, bye!
Ethereum Wallet: Definition, Working and Types
Hello friends, hope you are doing good and enjoying your life. Today, I am going to introduce you to the Ethereum wallets. I have given you an introduction to blockchain, its characteristics, and an introduction to accounts in my previous tutorials, so let’s get started with today’s tutorial on Ethereum wallets.
What is Ethereum Wallet???
In this section, I will introduce you to the Ethereum wallet and then we will move into its further details.
- A blockchain wallet is just like a real-life wallet but in software form. It is the digital form of a wallet.
- A wallet is application software that acts as a user interface to the Ethereum network.
- The wallet is a system to manage and store the keys.
- This digital wallet allows transferring cryptocurrencies from one account to another.
- The functions that can be performed by using a wallet are:
-
- Access to your money
- Access to accounts
- Management of keys
- Management of addresses
- Management of cryptocurrencies such as bitcoin or ether
- Tracking and viewing the user’s balance in different accounts
- Initiating transactions
- Signing transactions
- Interacting with contract accounts
This was some basic idea of wallet technology. Let’s move towards an important feature of wallets i.e., key management in the next section.
Key Management in Ethereum Wallet
- The actual function of a wallet is managing keys.
- If you think that your wallet will contain money then it is not true. You can view your balance via your wallet but this balance is actually residing on the Ethereum blockchain.
- Your wallet contains keys (both private and public) and by using these keys, you can sign transactions on Ethereum.
- To transfer ether or any cryptocurrency to other accounts, you need keys stored in your wallet.
- In centralized systems such as banks, your money is saved under your account. You can check the account balance and perform transactions with the involvement of banks. While in the blockchain you can control your money with your wallet yourself.
Ethereum Wallet Design
- While designing or choosing a wallet, two factors are considered that are convenience and privacy.
- There is always a trade-off between the two.
- With more convenience comes privacy issues and with strict privacy, convenience is compromised.
Types of Wallet
The wallets are classified into two main types depending upon the relationship between the keys they hold. These types are given below:
- Deterministic Wallet
- Non-deterministic Wallet
Now, I will explain these types a little bit. The first one is the deterministic wallet.
1. Deterministic Wallet
- In this kind of wallet, all wallet keys are generated from a single key.
- This single key is called the master key and it is derived from a seed.
- All of the keys are related to each other. Here, the original seed value is very important.
- These keys can be generated again with the use of seed value.
- Commonly, these keys are linked in the form of a tree structure where the root is the seed value.
2. Non-deterministic Wallet
- The second type of wallet is a non-deterministic wallet. In this kind, the keys are not related to each other.
- Each key of such a wallet is generated independently from different seed values.
- This wallet is also termed a random wallet and it is better than a deterministic wallet in terms of security.
Mnemonic Words
- There is a concern about security in deterministic wallets as all keys are related.
- If anyone gets a hold of the seed value, he can generate the master key and then all other keys of the wallet. It will give access to the balance.
For unfortunate data loss accidents, when a person loses his seed, the seed value is converted to mnemonic codewords. The mnemonic code words are a bunch of English words that the wallet holder has to keep safe. This word list can be saved in the form of a hard copy by writing that on a piece of paper and then storing it in a secure place.
This concludes the section here. I will now discuss different wallet applications available for you in the next part.
Different Forms of Wallet
There are different kinds of wallet applications for you to select from. The interesting thing about wallets is that you can switch from one type of application to the other. If you do not like the wallet that you are using, you can change your wallet easily and there is no loss in doing so. All the funds in your current wallet would be transferred to the new wallet. Your keys would be moved from the old wallet to the new one.
The wallet applications are classified into three types that are listed below.
- Mobile Wallet
- Desktop Wallet
- Online Wallet
- Hardware Wallet
- Paper Wallet
Mobile Wallet
- A mobile wallet is simple a phone application.
- You install the wallet application on your mobile phone and then access your account.
- These wallets can be used anywhere and are safer than online wallets.
- The only problem arises when there is a phone breakdown when you can lose your money.
Desktop Wallet
- A desktop wallet is also a safer option than online wallets.
- You can download a desktop wallet on your personal computer and access it anytime from the same device.
- The issue with this type of wallet arises when your desktop gets out of order, gets hacked, or is infected by a virus.
Online Wallet
- An online wallet is a convenient option to use.
- It can be opened anywhere from any device having an internet connection.
- These wallets reside on the cloud. Online wallets have higher security issues and can be used wisely.
Hardware Wallet
- In this kind of wallet, the keys are stored on some hardware device such as a flash drive.
- The hardware wallet remains offline mostly which provides security features.
- This wallet is a convenient and safe option although expensive among others.
Paper Wallet
- The last type of wallet is a paper wallet. This is the safest option among all options.
- The public and private keys are written or printed on a sheet of paper to make a physical copy and that copy is called a paper wallet.
- The transactions are done by entering private keys or you can also scan the QR code of your paper wallet.
These were the types of wallet applications and you can choose any of them depending on the features you prefer the most. So, guys, this was all about wallets. I hope you have learned something new from this article. That was all for today, Take care!
Ethereum Accounts: Definition, Types and Fields
Hello friends, hope you are doing good and enjoying your life. Today, I am going to introduce you to Ethereum accounts. I have given you an introduction to blockchain in my previous tutorials, so let’s get started on the essentials of this technology. I am going to start with accounts.
Ethereum Accounts
- An account is an important component of the Ethereum system.
- It is the main building block and has a balance in ether (ETH) (Ethereum currency).
- An account is capable of sending transactions on the Ethereum network.
- The interactions between different accounts create transactions that are stored in the distributed database.
- Each transaction involves the sender account, receiver account and contract account.
- An account can be controlled by a user or it can be a program deployed on the Ethereum blockchain.
Types of Ethereum Accounts
In this section, I am going to describe the two types of accounts in Ethereum, namely externally owned and contract.
- Each account has a balance property that shows how much balance the account currently holds.
- Therefore, accounts are classified into two main types:
-
- Externally Owned Accounts
- Contract Accounts
Externally Owned Accounts
- Externally Owned Account is abbreviated as EOA. This is the type of account that is owned by people on the Ethereum network.
- An individual makes an account on Ethereum and a public-private key pair is generated for the account. The account is not identified by the person’s name or any personal information.
- The private key of EOA gives control and access to one’s assets and contracts. The private key is kept secured by the user.
- While, as the name suggests, the public key of the account is open. This key acts as the identity of the account.
- The public key is generated from the private key via a one-way cryptographic function.
- As an example, if you create an account on Ethereum, you will keep the private key to yourself while the public key would be shared. Transactions between accounts are carried out through public keys.
- The address of an Ethereum account is generated through its public key.
- This type of account interacts with other externally owned accounts and contract accounts. It carries out transactions with the former one and interacts with the latter one by calling and executing its functions.
- This type of account has no code. It has balance in ether.
- Now, let’s talk about the second type of Ethereum accounts.
Contract Accounts
- In this section, I am going to tell you about the second type that is contract accounts.
- In some ways, contract accounts are similar to externally owned accounts but there are some differences between them too that I will mention later.
- First, let’s define a contract account. A contract account has a code for a smart contract.
- The contract account is identified by its public address.
- This account does not own a private key.
- These accounts also have balance property and they can hold ether too but these accounts have smart contract code. This code contains functions to execute and state variables.
- The logic of the smart contract controls this account. The smart contract that is deployed on the Ethereum blockchain is the owner of the contract’s account.
- When an externally owned account initiates a transaction with a contract account, the code of that contract runs in Ethereum virtual machine. The transaction contains data other than ether that tells information about what functions to run and what parameters should be given to the functions for execution.
This was some introduction to both accounts. Now, I am going to highlight some key differences and similarities between these two types.
Difference in Externally Owned Account and Contract Account
- An externally owned account (EOA) does not have a code while a contract account has a code.
- Externally owned accounts have a private key associated with them that contract accounts do not have.
- An externally owned account can initiate a transaction with another externally owned account or a contract account. But a contract account cannot initiate transactions.
- A contract account responds to transactions and in doing so it can call further contracts and their functions.
- Transaction between two EOAs is only of one kind that is the transfer of ether while transactions with a contract account can be of any kind, for example, calling other contract’s functions, deploying another contract, etc.
- An externally owned account is free to create while creating a contract account has a cost.
Similarities in Externally Owned Account and Contract Account
- Contract and externally owned accounts both are identified by their public addresses.
- Both types of accounts can have a balance and are capable of sending and receiving ether.
- Both of these accounts can interact with smart contracts deployed on Ethereum.
This was a comparison between externally owned and contract account. In the upcoming section, I am going to tell you about the components of an account.
Fields of an Ethereum Account
Any Ethereum account, whether an EOA or a contract account contains four fields which are given below:
- Nonce
- Balance
- CodeHash
- StorageRoot
I am going to give you an introduction to each of them. The first one on the list is Nonce.
Nonce:
- The nonce of an account is actually a counter that tells us about the number of transactions sent from that account for an externally owned account.
- While, for a contract account, this counter indicates the number of contracts created by that account.
Balance:
- This property shows the balance of the account as the name suggests.
- The balance is actually in Wei, a unit of ether (ETH) where 1 eth = 1x10e18 Wei.
CodeHash:
- This field gives the hash value of the contract code of the account.
- In the case of contract accounts, the smart contract code is hashed and the resulting value is stored in this field.
- While for externally owned accounts, this field contains the hash value of an empty string.
StorageRoot:
- The data of an account is stored in the world state trie.
- Each leaf of this trie represents one account.
- The storageRoot contains the hash value of the root of the storage trie.
- This field of account is empty by default.
These are the four fields of an Ethereum account. I hope this article has given you an understanding of Ethereum accounts. I will bring another interesting topic next time for you. Till then, take care!
Blockchain Mining: Definition, Process, Pooling & Miners
Hello Friends, Hope you are doing fine and having fun in your lives. In my previous tutorials on blockchain and Ethereum, I have talked about mining a few times. So, in today’s article, I am going to discuss the concept of mining with you. This is an important part of learning the working of blockchain to see how the decentralization of blockchain happens. Let’s start today’s article by defining mining.
Blockchain Mining
- As blockchain is a peer-to-peer network. Mining is also a peer-to-peer process.
- Blockchain (or Ethereum) mining is used to verify transactions on the network.
- In this process, miners (the person or node who performs mining) add transaction records to the decentralized distributed ledger of the blockchain.
- The transactions are added to the blocks, and the blocks are secured and linked after mining in the form of a chain.
- Mining requires computational power and effort from miners. And basically, it is the process of adding blocks.
- In this way, the transactions get confirmed and money and assets move from one account to another.
This was the idea of mining. In the next part, I am going to define the miner and discuss its role in the Ethereum blockchain network.
Blockchain Miner
- As defined earlier, a miner is a person or computer that performs the mining process.
- Miners provide their time, efforts, and computer resources for mining and serve the blockchain system.
- As a reward for their contribution, miners get transaction fees. The sender (or initiator) of the transaction pays this fee to the miner.
- A miner adds a number of transactions in the new block and collects the transaction fee for each of them.
- Any person can become a blockchain miner. A blockchain mining software needs to be installed and executed by the miner. This allows them to communicate with the blockchain network.
- A computer performing this process then becomes a node. The nodes interact with each other to collaborate for verifying transactions.
This was all about the miners and their importance. Now, I will explain the idea of decentralization in the context of mining in the upcoming section.
Mining and Decentralization
I have discussed the concept of decentralization in previous articles. Decentralization means no central server or no central authority to manage and control the data. An example of centralization is our traditional banking system. And an example of decentralization is blockchain.
Decentralization is related to the mining process. Miners contribute to the blockchain system by providing their computing powers in verifying the blocks of transactions. This verification process is mining and it eliminates the need for a central entity.
The agreement of everyone on the state of the Ethereum network is essential for this system. Miners make this possible by solving the blocks and this increases the trust and security in this system. The decentralized process and consensus happen from these four processes.
- Each transaction is verified by every node independently. The verification is done based on complete criteria.
- The addition of these verified transactions into new blocks by miner nodes independently. The addition is done with a computation via a proof of work algorithm.
- The new blocks are then verified by all nodes independently. The next step is assembling these blocks into the chain.
- The selection of the chain having computation via proof of work, by every node independently.
In the next part, I will discuss the step by step process of mining via nodes.
Mining Process
For explaining the procedure of mining in steps, let’s start with the transaction generation.
- The first step is the initiation of a transaction by an account.
- A person (an externally owned account) starts a transaction by providing all the necessary data and then signing it via his private key.
- The transaction is transmitted to the Ethereum network via some node requesting to be confirmed by miners.
- When nodes of the network get a request from a transaction, they add that unconfirmed transaction to the pool of other such transactions.
- All unconfirmed and unadded transactions will wait in that pool.
- Any miner starts the process of mining by adding hundreds of different transactions in its block. More number of transactions means a more rewarding fee for the miner.
- The miner verifies each transaction in its block and executes any code with it.
- The miner would change the state of the Ethereum virtual machine and produce the proof of work certificate for its block.
- The miner also produces a checksum of the new Ethereum virtual machine (EVM) state.
- When the computation is complete and a certificate has been produced for the block, it would be transmitted to the network.
- When other nodes receive the new block, they check the authenticity of the block certificate.
- Then execute all transactions included in the new block and check the state of the Ethereum virtual machine.
- They produce a checksum of their EVM state and match it with the checksum of the EVM state provided by the miner.
- If the checksum matches, the new block is added to the blockchain. The resulting EVM state is accepted as the new state.
- The transaction confirmed via a new block is then removed from the pool of unconfirmed transactions.
- Every new node that joins the blockchain network downloads the complete blockchain starting from the genesis block.
- Each transaction of every block is executed again until the final state of EVM is obtained. This state matches with the EVM of all other nodes.
- In this way, transactions get verified again and again increasing trust and security features.
So, guys, this was the process of mining. I tried to make this easy to understand for beginners. Before concluding this article, I want to introduce you to another concept related to mining and that is “Mining Pools”.
Mining Pool
- With time, the mining competition has been increased.
- Mining a block requires a lot of electricity and hardware resources and the likelihood of successful mining is very low.
- Therefore, miners now group and work together in mining pools where they share their resources and also the reward.
- In this way, everyone gets something out of their input.
In conclusion, I hope you have got an idea of how mining works from this article. Next time, I will present another new concept to you. Till then, take care!
Ethereum Blockchain: Definition, Currency, Working & Components
Hello friends, Hope you are doing good. In my last tutorial, I gave you an introduction to blockchain technology and this article is the second one of this series. Today I am going to talk about Ethereum. In simple words, Ethereum is an open-source platform of blockchain technology. But unlike the bitcoin blockchain, it offers more functionality. The blockchain in bitcoin tracks bitcoins only. It tracks the ownership and transfer of bitcoins. While Ethereum is not only a payment network for cryptocurrency but also termed as the world computer due to its wide functionality. First, let’s go through the key introductory points of Ethereum, and then we will dive into the details:
What is Ethereum Blockchain?
- Ethereum blockchain is an open-source global platform that supports decentralized applications.
- It offers a programmability feature, coding is done in smart contracts.
- It runs its own currency named Ether and is abbreviated as ETH.
Now let’s take a look at its invention history, and then I will talk about its features in the next sections.
History of Ethereum
In this section, I will give you an idea that how Ethereum was invented and why there was a need of developing such a platform. When bitcoin was invented and people realized the power of blockchain, developers tried to design new applications other than cryptocurrency. The limited functionality of the existing blockchain made it difficult to build different types of projects and hence, arose the need for a new blockchain.
In 2013, Vitalik Buterin presented a white paper giving the idea of the Ethereum blockchain. Afterward, Vitalik and Gavin Woods worked together and built upon that idea. And guys, finally in 2015, the first block of the Ethereum blockchain was mined. So, this was a little history and now before getting you bored, I will move towards the next section explaining the programmability of Ethereum.
Ethereum Programmability
- The main function of Ethereum is that it is programmable, which means applications can be built on it.
- It is a general-purpose blockchain capable of executing code.
- The language offered by bitcoin was very limited with limited data types and size, but this is not the case with Ethereum.
- Ethereum is also called Turing complete and I will explain the concept of Turing completeness in the upcoming sections.
Working of Ethereum Blockchain
I am going to tell you about the working of Ethereum Blockchain in this section.
- The memory in Ethereum stores data and code.
- The Ethereum blockchain tracks the changes in data and thus it tracks the changes in its memory.
- Ethereum first loads the program, executes it and finally stores the results in its blockchain.
This procedure is the same as in the computers that we use in our daily life. The difference is that the data in our computer is stored locally while in Ethereum blockchain, the changes in state are distributed and each node has data stored in it. Also, the changes in data are according to the consensus rules. The process can be summarized as:
- Accepting transactions from different nodes or accounts.
- Updating the state for accepted transactions.
- Storing and maintaining the state in its memory.
- The states are maintained until another accepted transaction happens.
- This process is repeated for each change.
Now let’s list down some main components of ethereum technology. I am going to give you a simple definition of each one for a basic understanding.
Components of Ethereum Blockchain
The components of Ethereum are given below:
Peer to peer network:
- Ethereum blockchain is a peer to peer network, all computers or nodes are connected with each other.
Nodes:
- Any device whether a computer or a mobile, connected to the blockchain containing the data are called nodes. All nodes are connected to each other.
Transactions:
- The messages exchanged on the network are called transactions. A transaction involves a value, a recipient, a sender, and a data payload.
Consensus Rules:
- The set of rules that is followed for considering the validity of a transaction and a block in Ethereum I called consensus rules. These rules are enforced by all nodes.
Consensus Algorithm:
- The consensus algorithm is the procedure to obtain agreement on the longest chain in the distributed Ethereum network. The most commonly used consensus algorithms for Ethereum are proof of work and proof of stake.
State Machine:
- Ethereum transactions and state changes are processed by the state machine called Ethereum Virtual Machine abbreviated as EVM.
- Ethereum virtual machine executes the program in machine language.
- These programs are written in a high level language such as Solidity and then a compile converts the program into bytecode.
- The program written in a high level language is called a smart contract.
So, these were some components and terminologies associated with Ethereum Blockchain. Next, I am going to introduce the cryptocurrency that Ethereum uses.
Ethereum Currency: Ether
The cryptocurrency used on the Ethereum blockchain is ether (ETH). This cryptocurrency acts as fuel for the execution of smart contracts. This currency is integral and users pay it for using the Ethereum network. The purpose of this currency is:
- Storing value.
- Allowing users to perform transactions by exchanging payments.
- Allowing payments for computational costs of code execution means each transaction executes by paying a small transaction fee.
- Running applications (Decentralized Applications).
At the time of writing this article, the currency is worth 2355.44 USD. That was some basic idea of the ether, now let’s move towards smart contracts.
Smart Contract
- A program that executes on Ethereum is called a smart contract.
- It is a set of rules or codes that control the transfer of value according to programmed conditions.
- One feature of a smart contract is immutability. Immutability means that the code of a smart contract cannot be changed after its deployment.
- Smart contracts are deterministic. The outcome of the smart contract execution is the same for anyone running it.
Before concluding this article on Ethereum introduction, I will give you an idea of Turing completeness as I mentioned earlier.
Turing Completeness
- Ethereum is a Turing complete system.
- Ethereum can read and write data to memory and execute programs in the Ethereum virtual machine.
- It can compute any program that a Turing complete machine can.
- The main difference provided by Ethereum is that it combines computing power with blockchain.
- All of the characteristic features of blockchain are combined with the programmability feature and that makes Ethereum a useful invention.
That was all for today. I hope you have got an idea about Ethereum. Next time we will move towards the interesting features of this technology and also we would talk about dApps in upcoming articles. Till then, take care!
Characteristics of Blockchain Technology
Hi friends, hope you are doing well. I have given you an introduction to
Blockchain Technology and ethereum in my previous tutorials. In today’s article, I am going to talk about the characteristics of blockchain. There are several key characteristics of blockchain technology that make it different and usable from other technologies.
The architecture of blockchain is so unique that it inherently provides a lot of features to this technology. These features have benefits for several areas and sectors so let’s discuss these characteristic features.
Characteristics of Blockchain
We have already discussed the components of Blockchain in our previous tutorial Introduction to BlockChain Technology. Now, let's understand the characteristics of Blockchain one by one:
1. Decentralization
- The most important one on the list is decentralization so I am going to explain it first.
- Blockchain is entirely different from traditional internet architecture where each computer or system is connected to a central server. The central server is responsible for managing data.
- In the blockchain, each system has access to the whole data with no central server controlling the operations. No organization is in charge of the data.
- The consensus mechanism in the blockchain is responsible for controlling the network.
- Each node has an updated copy of data and execution power instead of only one server having data and execution control.
- The benefits of decentralization are listed below:
Less Failure
- One benefit of decentralization is that the network and data are available always even if some server or node is not accessible.
User Control
- Users have full control of their assets and transactions.
No Intermediary
- There is no need for a central authority for verifying transactions.
Less possibility of hacking
- Attacking the system requires a lot of computing power.
Distributed Ledger
- The next feature is distributed ledger and to understand this, I will define ledger first. A ledger is a file for recording the transactions.
- An example is the ledgers in banks. All transactions of an account are listed in the ledger in an order. Each new transaction is added to it while retaining the previous record.
- Similarly, every approved transaction is added to the blockchain ledger while maintaining the previous history.
- The blockchain ledger is open to everyone as any node can view the transactions.
- Also, every node on the network is connected to other nodes of the network in many to many connections which makes it a distributed network.
- The network is maintained by all of the nodes. Each node provides computational power to this system.
- Some of the benefits of a distributed ledger are as follow:
- Fast Response: As the network is distributed with no central power, the transactions take less time.
- Participation: Every node participates in maintaining the record and database. Each node takes part in the validation process.
- No Tempering in Data: Each node has a copy of data, a single node cannot temper the past data. Any malicious activity is noticed easily.
- Equal Privileges: All nodes in the distributed network go through the same process of transaction verification.
- This was some idea of a distributed ledger in the blockchain. Next, I will talk about the Immutability feature.
Immutability
- Immutability is a core characteristic of blockchain. Immutable refers to something that cannot be changed with time.
- The data stored in the blockchain cannot be corrupted and this is a very useful and interesting feature.
- In the blockchain, immutability means that any records or transactions stored in it can never be changed or removed. Let’s explain how immutability works here.
- The data in the blockchain is added in the form of blocks. These blocks are verified by nodes and every entity of the network accepts them.
- Every node has a copy of data and changing a single copy residing on a single node cannot alter the data on the entire network.
- The data in each block is cryptographically secure and hashed. Each block is identified by its hash value and each block has the hash value of the previous block too.
- Changing the data of a block changes its hash value too and as each block contains information of the previous block the hash no longer matches with the next block of the chain.
- So, the distributed nature and cryptography make the data immutable in the blockchain.
- Once a transaction is recorded in a block, verified by nodes, and added to the blockchain, no one is able to modify or remove that from the database.
Security
- The next feature that I am going to discuss is security. The architecture of blockchain provides data security.
- Due to cryptography, all information is secure in the database and that makes it different from the existing internet structure.
- The account information is also secure and the identity of each node is hidden. Each account has a private and public key. The private key is secured and cannot be generated via public key.
- The network is controlled by a set of rules instead of any authority. So, no one is able to change the rules for themselves. The system enforces security and integrity itself.
- Now let’s talk about another important feature i.e., traceability.
Traceability
- Blockchain provides the traceability feature.
- Traceability means being able to trace and track the origin of something. Traceability allows verifying the source or origin, history, and all data of a product.
- As blockchain is an immutable database, any asset or transactional data can be traced back.
- The origin of any transaction can be traced back to the distributed ledger.
- This characteristic is very useful in a lot of applications such as in a supply chain network.
Cryptographic Hashing
- I have already given you an idea of what cryptographic hashing is in this article. The blockchain transactions are all cryptographically secured.
- The transactions in a block are hashed and thus converted to a fixed-length value. This value is stored in the block.
- Data can be converted to a hash value but a hash value cannot be converted back to input data which implies that cryptographic hashing is a one-way function.
- The pair of a public and a private key for each account also has cryptography associated with it. The public key is generated from the private key. The private key is secured and not shared on the network while the public key is open on the network. The public key can be generated via private key using cryptographic functions but the private key cannot be generated using public key due to the one-way nature of cryptographic functions.
Anonymity
- Having discussed the important features of blockchain technology, let’s not leave out another significant property that is anonymity.
- On a blockchain network, the true identity of a participant is hidden.
- Each participant of the distributed network has an address associated with it. This address is the identity of that entity instead of a true identity.
- The addresses keep the user anonymous on the network.
So, I have explained the basic characteristics of blockchain that make it unique from the traditional systems. I am hoping that you will get an idea of the benefits of blockchain after reading this article. I will come with another useful article next time. Till then, take care!