Digital currency – What is digital currency?

Digital currency –
What is digital currency?

By Jake Frankenfield Reviewed by Somer Anderson Updated Mar 23, 2021
Digital money is a form of money that is only available in digital or electronic format and not in physical form. It is also called digital money, electronic money, electronic money or cyber cash.

Main conclusions

• Digital currencies are currencies that are only accessible with computers or mobile phones, as they exist only in electronic form.
• Since digital currencies do not require intermediaries, they are often the cheapest method of trading currencies.
• All cryptocurrencies are digital currencies, but not all digital currencies are crypto.
• Digital currencies are stable and are trading with markets, while cryptocurrencies are trading through consumer sentiment and psychological triggers in price movement.
Understanding digital currency
Digital currencies are intangible and can only be owned and transferred using computers or electronic wallets connected to the Internet or designated networks. Conversely, physical currencies, such as minted banknotes and coins, are tangible and transactions are only possible by their holders who have their physical ownership.
Like any standard fiat currency, digital currencies can be used to purchase goods and pay for services, although they may also find limited use among some online communities, such as gaming sites, gaming portals, or social networks.
Digital currencies have all the inherent properties like physical currency, and allow for instant transactions that can be seamlessly executed to make payments across borders when connected to supported devices.
Difference between digital, virtual and crypto currencies
Since they exist in many variations, digital currencies can be considered a superset of virtual currencies and cryptocurrencies.
If issued by a central bank of a country in a regulated form, it is called the “Central Bank’s Digital Currency (CBDC).” While the CBDC exists only in conceptual form, England, Sweden and Uruguay are some of the nations that have considered plans to launch a digital version of their native fiat currencies.
NEW ECOLOGICAL DIGITAL COIN ACCORDING TO CBDC STANDARD
Along with the regulated CBDC, a digital currency can also exist in an unregulated form. In the latter case, it qualifies to be called a virtual currency and can be under the control of the currency developer (s), the founding organization, or the defined network protocol, instead of being controlled by a centralized regulator.
Since cryptocurrencies are not regulated, they are also considered virtual currencies.
A cryptocurrency is another form of digital currency that uses cryptography to protect and verify transactions and to manage and control the creation of new monetary units.
Bitcoin and Ethereum are the most popular cryptocurrencies.
Essentially, both virtual currencies and cryptocurrencies are considered forms of digital currencies.
Digital currencies
Regulated or unregulated currency available only in digital or electronic format
Virtual currencies
An unregulated digital currency controlled by its developer (s), by the founding organization or by the defined network protocol.
Cryptocurrencies
A virtual currency that uses cryptography to secure and verify transactions, as well as to manage and control the creation of new monetary units.
What is the convertible virtual currency?
Convertible virtual currency is an unregulated digital currency that can be used as a substitute for real and legally recognized currency, even if it does not have legal tender status.
Convertible digital currencies are easily interchangeable with fiat currencies, such as dollars, via cryptocurrency exchanges.
This can be countered with non-convertible virtual currencies that are not used in external trade or directly exchangeable with other currencies, such as virtual currency contained within a video game environment.

• Convertible virtual currency is a cryptocurrency that can be exchanged for fiat currencies on foreign exchange, or which are used directly for legitimate forms of trading and payments.
• These currencies are mainly different from state-guaranteed currencies such as the dollar or the euro in that they have no physical presence and are not issued by a government. Rather they run on decentralized blockchain networks.
• Bitcoin, Ether and Ripple are examples of convertible virtual currencies.

How the convertible virtual currency works
Convertible virtual currency is an example of how technological advances are driving shocking changes in the traditional way of doing things around the world. This is particularly true of the way in which goods and services are paid for and purchased.
Definitions of convertible virtual currency
Virtual currency is defined by the Financial Crimes Enforcement Network (an office of the U.S. Treasury) as “a medium of exchange that functions like a currency in some circles, but does not have all the attributes of real currency.” 1 Convertible virtual currency usually has measurable value in real money, but what makes it convertible is its ability to be exchangeable. Not all virtual currencies can be exchanged for legal tender; therefore, not all virtual currencies are convertible.

The US government’s Internal Revenue Service defines a convertible virtual currency as a virtual currency that has real currency value. This means that for the IRS, “Bitcoin, Ether, Roblox, and V-bucks are some examples of a convertible virtual currency. Virtual currencies can be digitally exchanged between users and can be purchased or exchanged for US dollars, euros and other real or virtual currencies. ”
Another feature of convertible virtual currencies that make them similar to state-guaranteed currencies is their tax liability, at least in the United States: “The sale or other exchange of virtual currencies, or the use of virtual currencies to pay for goods or services, or holding virtual currencies as an investment, generally has tax consequences. ”
Popular convertible virtual currencies
The most popular form of virtual currency remains Bitcoin. Bitcoin operates on a decentralized peer-to-peer network that uses blockchain technology to prevent fraud and control the supply of money. Conversely, central banks and state treasuries (such as the United States) control the money supply by printing money and taking it out of circulation, raising and lowering interest rates on loans and prosecuting counterfeiters.
Bitcoin is a convertible virtual currency because it can be exchanged for real money based on its determinable value in the market. The value of a Bitcoin in dollars has been trading from $ 13 sometime in 2012 to more than $ 40,000 in December 2020.3 Other popular virtual currencies are Ether, Zcash, Monero, Dash, Ripple, and Litecoin.
What is Blockchain?
Blockchain sounds complicated, and it sure can be, but its basic concept is really quite simple. A blockchain is a type of database. To be able to understand blockchain, it helps to understand in the first place what a database really is.
A database is a collection of information stored electronically on a computer system. The information, or data, in databases is generally structured in a table format to allow easier searching and filtering of specific information. What’s the difference between someone using a spreadsheet to store information rather than a database?
Spreadsheets are designed for one person, or a small group of people, to store and access limited amounts of information. In contrast, a database is designed to house significantly larger amounts of information that can be accessed, filtered and manipulated quickly and easily by any number of users at the same time.
Large databases accomplish this by housing data on servers which are made of powerful computers. These servers can sometimes be built using hundreds or thousands of computers to have the computational power and storage capacity needed for many users to access the database at the same time. While a spreadsheet or database may be accessible to any number of people, it is often owned by a company and managed by a designated individual who has complete control over how it works and the data within it.
How does a blockchain differ from a database?
Storage facility
A key difference between a typical database and a blockchain is the way the data is structured. A blockchain gathers information together in groups, also known as blocks, which contain sets of information. The blocks have certain storage capacities and, once filled, are chained to the previously filled block, forming a chain of data known as the “blockchain.” All new information that follows that the newly added block is compiled into a new block which will then be added to the chain once filled.
A database structures its data into tables, while a blockchain, as the name suggests, structures its data into blocks (blocks) that are chained together. This makes it so that all blockchains are databases, but not all databases are blockchains. This system also inherently renders an irreversible timeline of data when implemented in a decentralized nature. When a block is filled it is set in stone and becomes part of this timeline. Each block in the chain is given an exact date when it is added to the chain.
The legal status of convertible virtual currencies
The nature of convertible virtual currencies makes them susceptible to being used as vehicles for money laundering, tax evasion and terrorist financing. This has led some countries to propose regulatory measures on how currencies will be observed and used for tax purposes.
In the United States, Fincen guidelines state that virtual currency that can be exchanged for legally recognized money is property, not money, and will be treated as such. The tax principles that apply to real estate transactions therefore apply to these types of currencies. A taxpayer who receives Bitcoin or Linden dollars in exchange for goods and services must register the fair value of the virtual currency in dollars as of the date of receipt. This value is included in the calculation of the taxpayer’s gross annual income.
In addition, a virtual currency used for the investment is considered a capital asset and is therefore subject to tax on its capital gains or losses.
The blockchain is an undeniably ingenious invention – the brainchild of a person or group of people known under the pseudonym of Satoshi Nakamoto. But since then, it has evolved into something bigger, and the main question that every single person asks is: What is the Blockchain?
Is Blockchain Technology the New Internet?
By allowing digital information to be distributed but not copied, blockchain technology created the backbone of a new type of internet. Originally devised for digital currency, the Bitcoin blockchain, (Buy Bitcoin) the tech community has now found other potential uses for the technology.
In this guide, we will explain what blockchain technology is and what are its properties that make it so unique. So, we hope you like this, What Is a Blockchain Guide. And if you already know what blockchain is and want to become a blockchain developer please check out our blockchain tutorial in depth and create your first blockchain.

A blockchain is, in the simplest terms, a timed series of immutable records of data that is managed by a group of computers not owned by a single entity. Each of these data blocks (eg block) is protected and linked to each other using cryptographic principles (eg chain).
So, what’s so special and why are we saying it has the ability to disrupt the industry?
The blockchain network has no central authority – it is the very definition of a democratized system. Because it is a shared and immutable ledger, the information it contains is open to anyone and everyone. Therefore, everything built on the blockchain is by its very nature transparent and all stakeholders are accountable for their actions.
What exactly is Blockchain?
A blockchain does not involve any transaction costs.
(An infrastructure cost yes, but no transaction cost.) The blockchain is a simple yet ingenious way of passing information from A to B in a fully automated and safe manner. One party to a transaction initiates the process by creating a block. This block is verified by thousands, perhaps millions of computers distributed around the net. The verified block is added to a chain, which is stored across the net, creating not just a unique record, but a unique record with a unique history. Falsifying a single record would mean falsifying the entire chain in millions of instances. That is virtually impossible. Bitcoin uses this model for monetary transactions, but it can be deployed in many other ways.
Think of a railway company. We buy tickets on an app or on the web. The credit card company accepts a cut for processing the transaction. Blockchain, not only can the railway operator save on credit card processing costs, it can move the entire ticketing process to the blockchain. The two parties to the transaction are the railway company and the passenger. The ticket is a block, which will be added to a ticket blockchain. Just as a monetary transaction on the blockchain is a unique, independently verifiable and unfalsifiable record (like Bitcoin), so can the ticket be. Among other things, the final blockchain is also a record of all transactions, for example, for a certain railway route, or even the entire railway network, which includes every ticket ever sold, every trip ever taken.
In the financial world the applications are more evident and the revolutionary changes more imminent. Blockchains will change the way stock exchanges work, loans are bundled, and insurance is taken out. They will eliminate bank accounts and virtually all services offered by banks. Almost all financial institutions will fail or be forced to change fundamentally once the benefits of secure accounting technology with no transaction fees are widely understood and implemented. After all, the financial system is built on taking a small cut of your money for the privilege of facilitating a transaction. Instead of paying high transaction fees to banks and taking several days for payments to settle and clear, they can only trade with each other on exchange-based blockchains with ease and in no time. Bankers will become mere advisors, not custodians of money. Brokers will no longer be able to earn commissions and the buy / sell spread will disappear.
How does a blockchain work?
• The reason blockchain has gained so much admiration is that:

• • It is not owned by a single entity, so it is decentralized
• The data is stored cryptographically inside
• The blockchain is immutable, so no one can tamper with the data found within the blockchain
• The blockchain is transparent so you can track data if you want
The three pillars of Blockchain technology
The three main properties of Blockchain Technology that have helped it to obtain a broad consensus are the following:
• Decentralization
• Transparency
• Immutability

Pillar 1: Decentralization
Before Bitcoin and Bittorrent arrived, we were more used to centralized services. The idea is very simple. You have a centralized entity that stores all the data and you should interact exclusively with this entity to obtain all the necessary information.
Another example of a centralized system is banks. They store all your money and the only way you can pay someone is by going through the bank.
The traditional client-server model is a perfect example:
When you search for something on Google, it sends a query to the server which then comes back to you with relevant information. It is a simple client-server.

Now, centralized systems have treated us well for many years, however, they have several vulnerabilities.
• First, because they are centralized, all data is stored in one place. This makes them easy targets for potential hackers.
• If the centralized system were to go through a software update, the entire system would stop
• What if the centralized entity somehow shuts down for any reason? This way no one will be able to access the information they have
• In the worst case, what happens if this entity gets damaged and malicious? If this happens then all the data located within the blockchain will be compromised.
So what happens if we take this centralized entity away?
In a decentralized system, information is not stored by a single entity. In fact, all information is owned by the network.
In a decentralized network, if you want to interact with your friend then you can do it directly without going through a third party. This was the main ideology behind Bitcoin. You and you alone are responsible for your money. You can send your money to anyone you want without having to go through a bank.
Pillar 2: Transparency
One of the most interesting and misunderstood concepts in the blockchain is “transparency.” Some people say blockchain gives you privacy, while some say it is transparent. Why do you think this happens?
Well … a person’s identity is hidden through complex cryptography and represented only by his public address. So, if you were to search a person’s transaction history, you won’t see “Bob sent 1 BTC” instead you will see “1MF1bhsFLkBzzz9vpFYEmvwT2TbyCt7NZJ sent 1 BTC”.

Thus, while the person’s real identity is secure, you will still see all the transactions that have been made from their public address. This level of transparency has never existed before within a financial system. He adds that the extra, and much needed, level of responsibility is required by some of these larger institutions.
Speaking purely from a cryptocurrency perspective, if you know the public address of one of these large companies, you can simply pop in an explorer and look at all the transactions they have involved. This forces them to be honest, something they have never dealt with before.
However, this is not the best use case. We’re pretty sure that most of these companies won’t transact using cryptocurrency, and even if they do, they won’t do all of their transactions.
Pillar 3: Immutability
Immutability, in the context of the blockchain, means that once something has entered the blockchain, it cannot be tampered with.
Can you imagine how valuable it will be to financial institutions?
Imagine how many cases of embezzlement can be nipped in the bud if people know they can’t “work the books” and fiddle with the company’s accounts.
The reason the blockchain gets this property is because of the cryptographic hash function.
In simple terms, hashing means to take an input string of any length and give an output of a fixed length. In the context of cryptocurrencies such as bitcoin, transactions are taken as inputs and executed through a hashing algorithm (Bitcoin uses SHA-256) that provides a fixed-length output. Let’s see how the hashing process works. We will insert some inputs. For this exercise, we will use the SHA-256 algorithm (Secure Hashing Algorithm 2 256).
As you can see, in the case of SHA-256, no matter how big or small your input is, the output will always have a fixed length of 256 bits. This becomes critical when dealing with a huge amount of data and transactions. So in practice, instead of remembering the input data which could be huge, you can just remember the hash and keep track.
A cryptographic hash function is a special class of hash functions that has various properties that make it ideal for cryptography. There are some properties that a cryptographic hash function must have in order to be considered safe. You can read them in detail in our hashing guide.
There is only one property we want you to focus on today. It’s called the “Avalanche Effect.”
What does it mean?
Even if you make a small change in your input, the changes that will be reflected in the hash will be huge. Let’s try it out using SHA-256:

Do you see it? Even if you just changed the case of the first input alphabet, look at how much it affected the output hash. Now, let’s go back to the previous point when we were looking at the blockchain architecture. What we said was:
The blockchain is a linked list that contains data and a hash pointer that points to the previous block, thus creating the chain. What is a hash pointer? A hash pointer is similar to a pointer, but instead of containing only the address of the previous block it also contains the hash of the data within the previous block.
This little tweak is what makes blockchains so incredibly reliable and pioneering.
Imagine this for a second, a hacker attacks block 3 and tries to change the data. Due to the properties of the hash functions, a slight change in the data will drastically change the hash. This means that any slight changes made in block 3 will change the hash which is stored in block 2, now that in turn will change the data and hash of block 2 which will result in changes in block 1 and so on and so forth. Street. This will completely change the chain, which is impossible. This is exactly how blockchains achieve immutability.
Maintain the Blockchain – Network and Nodes
The blockchain is managed by a peer-to-peer network. The network is a set of interconnected nodes. Nodes are single computers that take input and perform a function on them and give an output. The blockchain uses a special type of network called a “peer-to-peer network” which divides the entire workload among the participants, who are all equally privileged, called “peers”. There is no longer a central server, now there are several distributed and decentralized peers.
Why do people use peer-to-peer networking?
One of the primary uses of peer-to-peer networking is file sharing, also called torrenting. If you are using a client-server model for downloading, it is usually extremely slow and depends entirely on the health of the server. Also, as we said, it is prone to censorship.
However, in a peer-to-peer system, there is no central authority, and so if one of the peers in the network also goes out of the way, you have even more peers to download. Furthermore, it is not subject to the idealistic standards of a central system, so it is not prone to censorship.
If we were to compare the two:
Image courtesy: Quora
The decentralized nature of a peer-to-peer system becomes critical as we move on to the next section. How critical? Well, the simple (at least on paper) idea of combining this peer-to-peer network with a payment system has completely revolutionized the financial sector by giving birth to cryptocurrency.
The use of networks and nodes in cryptocurrencies ..
The cryptocurrency peer-to-peer network structure is structured according to the consensus mechanism they are using. For cryptocurrency like Bitcoin and Ethereum that use a normal proof-of-work consensus mechanism (Ethereum will eventually switch to Proof of Stake), all nodes have the same privilege. The idea is to create an egalitarian network. Nodes do not have special privileges, however their functions and degree of participation may differ. There is no centralized server / entity, no hierarchy. It is a flat topology.
These decentralized cryptocurrencies are structured this way due to one simple reason, to stay true to their philosophy. The idea is to have a monetary system, in which everyone is treated equally and there is no governing body.
So, what is a node in the context of Ethereum? A node is simply a computer that participates in the Ethereum network. This participation can take place in three ways:
• Maintaining a shallow copy of the blockchain as a Light Client
• Maintaining a complete copy of the blockchain as a full node
• Verifying transactions as Mining
However, the problem with this design is that it’s not really that scalable. That’s why many next-generation cryptocurrencies adopt a leader-based consensus mechanism. In EOS, Cardano, Neo, etc. the nodes elect the leader nodes or “supernodes” that are responsible for the consensus and overall health of the network. These cryptographics are much faster but they are not the most decentralized systems.
So, in a sense, cryptocurrencies have to make the trade-off between speed and decentralization.
Online transactions are closely related to identity verification processes. It is easy to imagine that wallet applications will transform over the next few years to include other types of identity management.
Blockchain and Mainstream Adoption
The impact of blockchain technology is truly far-reaching and has many more use cases than being a facilitator for transactions. Several sectors have discovered the benefits of blockchain integration. While Bitcoin and Ethereum are examples of public blockchains, most of these industries require specific functionality from their distributed ledger architecture. That’s why they use a special kind of blockchain called “authorized blockchain.”
What is an Authorized Blockchain?
So what’s the difference between a public and a licensed blockchain? Public blockchains are open protocols. Anyone can join the network and participate in the protocol and take care of the general consensus of the network. Furthermore, the data stored in the blockchain is practically open for everyone to see since everything is public.
While transparency is a very desirable feature, the fact remains that businesses don’t want to use a network where any average Joe can peek into their daily dealings and be a part of some confidential information.
As such, businesses prefer to use a unique form of blockchain called “permissioned” chains, limiting the number of nodes that enter the network. Authorized chains can also be differentiated into public and private blockchains.
Authorized public blockchain
In an authorized public system, anyone can enter the network, but only a few can take care of the general consent and networks. Let’s take a real example to understand how this system works. Anyone can log into a public ATM and use it. You don’t need to have special privileges to use it (save for an ATM card). But, not everyone can open the car and add new features and cash. Only the bank that owns the machine has the right to do so.
Blockchains like stellar, ripple, EOS, Sovrin, etc. are examples of public and authorized blockchains. In EOS, anyone can join the network. However, to participate in the consensus, it will be necessary to be elected as one of the 21 block producers and block some participation in the ecosystem.
Private authorized blockchain
A private blockchain is a blockchain where members must obtain permission to enter the system and only a select few nodes are allowed to make administrative decisions. Think of a university. Not everyone can enter this university. Applicants must first pass an entrance exam. Furthermore, if it is an extremely prestigious university, they will need to have enough money to pay the admission fees. However, the administrative decisions of the university are made by the student council, that is, the students elected / selected to take care of these roles. Not all students can handle the administrative side.
Many companies have created consortia using protocols such as Hyperledger Fabric, which are licensed private blockchains.
# 1 Smart contracts
Distributed ledger technology allows for the coding of simple contracts that will execute when specified conditions are met. Ethereum is an open-source blockchain project that was built specifically to realize this possibility. Still, in its early stages, Ethereum has the potential to harness the usefulness of blockchains on a truly evolving scale.
At the current level of technology development, smart contracts can be programmed to perform simple functions. For example, a derivative could be paid when a financial instrument meets a certain benchmark, with the use of blockchain and Bitcoin technology allowing the payment to be automated. With Etherum being the largest smart contract network, some top cryptocurrency exchanges like Okex are also deploying their decentralized smart contract networks like Okex Chain, where users can launch their decentralized applications, create token trading pairs and trade freely. without time and a limited place.
# 11 Identity management
There is a definite need for better identity management on the web. The ability to verify one’s identity is the cornerstone of financial transactions that take place online. However, the remedies for the security risks that come with web business are imperfect at best. Distributed ledgers offer advanced methods of proving who you are, along with the ability to digitize personal documents. Having a secure identity will also be important for online interactions – for example, in the sharing economy. A good reputation, after all, is the most important condition for conducting online transactions.
The development of digital identity standards is proving to be a very complex process. Technical challenges aside, a universal online identity solution requires cooperation between private entities and the government. Added to this is the need to orient the legal systems in the various countries and the problem becomes exponentially difficult. An Internet e-commerce currently relies on the SSL certificate (the little green block) for secure web transactions. Netki is a startup that aspires to create an SSL standard for the blockchain. Having recently announced a $ 3.5 million seed round, Netki expects a product launch in early 2017.
# 12 AML and KYC
Anti-money laundering (AML) and knowing the customer (KYC) practices have strong potential to be adapted to the blockchain. Currently, financial institutions have to go through a labor-intensive multi-step process for each new client. The costs of KYC could be reduced through verification between client institutions and at the same time increase the effectiveness of monitoring and analysis.
Startup Polycoin has an AML / KYC solution that involves transaction analysis. Transactions identified as suspicious are reported to control officers. Another startup, Tradle is developing an application called Trust in Motion (Tim). Featuring an “Instagram for KYC”, Tim allows customers to take an instant photo of key documents (passport, utility bill, etc). Once verified by the bank, this data is stored cryptographically on the blockchain.
What is a blockchain and how does it work exactly … in terms of code?

A blockchain is basically a chain of blocks that hold data. It is basically a glorified linked list. However, what makes it so special? A blockchain is immutable. Meaning, once a data enters a block, it can never be changed. How does a blockchain achieve immutability? It is because of a simple but ingenious mechanism called “hashing”. Check the diagram below:
Image Courtesy: Lauri Hartikka medium article
Each block is connected to the previous block via a hash pointer that contains the hash of the previous block. So how does this make the chain immutable?
One of the most fascinating properties of cryptographic hash functions is that if you change the input a bit, it can greatly affect the output hash. Eg. Look here:
By simply changing the first “T” from uppercase to lowercase, the output hash changed dramatically.
So how does this affect the blockchain?
Each block is linked to the previous one via the hash pointer. Thus, if someone were to tamper with the data in a block, it would drastically change the hash and, consequently, would end up affecting the entire chain (as all blocks are connected). This would freeze the chain which is impossible and therefore the blocks would remain unchanged.
So how do we go about making a block? What does a simple block consist of? In our simple cryptocoin we’re about to make (Let’s call it “Blockgeekscoin”), each block will have the following information:
• Index: To know the block number.
• Timestamp: To know the time of creation.
• Data: The data within the block.
• Previous hash: The hash of the previous block.
• Hash: The hash of the current block.
Before continuing. You need to understand some terms that we will use in our program:
• THIS: The keyword “this” is invoked within a function and allows you to access the values within a specific object that calls that particular function.
• CONSTRUCTOR: A constructor is a special function that can help create and initialize an object within a class. Each class is limited to a single constructor. Now that that’s done, let’s start making our block.
Create the block
const SHA256 = require (“crypto-js / sha256 ″);
class Block
{
constructor (index, timestamp, data, previousHash = “)
{
this.index = index;
this.previousHash = previousHash;
this.timestamp = timestamp;
this.data = date;
this.hash = this.calculateHash ();
}
calculateHash ()
{
return SHA256 (this.index + this.previousHash + this.timestamp + JSON.stringify (this.data)). toString ();
}
}
Code analysis
Okay, this one is off the bat. So, in the first line of the code we called the crypto-js library because the sha256 hash function is not available in Javascript.
Next, we invoked a constructor within the class to call for objects that will have certain values. The thing that probably catches the eye is the calculateHash () function. Let’s see what exactly it is doing.
In a block, we take all the contents and hash them to get the hash of that particular block. We are using the JSON.stringify function to transform the block data into a string for hashing.
Ok, so we have the block ready and good to go. Now let’s link the blocks together in a blockchain.
Now that we’ve built the genesis block, let’s build the rest of the chain.
Section 2: Adding Blocks
First, we need to know what the last block in the blockchain currently is. For this we use the getLatestBlock () function.
getLatestBlock ()
{
return this.chain [this.chain.length – 1];
}
Now that we have determined the latest block, let’s see how we are going to add new blocks.
addBlock (newBlock) {
newBlock.previousHash = this.getLatestBlock (). hash;
newBlock.hash = newBlock.calculateHash ();
this.chain.push (newBlock);
}
So what’s going on here? How are we adding the blocks? How are we checking if the given block is valid or not?
Remember the contents of a block?
A block has the hash of the previous block right?
So what we’re going to do here is simple. Compare the previous ash value of the new block with the hash value of the last block.
Image Courtesy: Lauri Hartikka medium article
If these two values match, then this means that the new block is legitimate and is being added to the blockchain.
Section 3: Validation of the Chain
Now, we need to check that no one has interfered with our blockchain and that everything is stable.
We are using the “per” loop to go from block 1 to the last block. The Genesis block is block 0.
for (let i = 1; i