Gentle introduction to Solidity
It is little more than 5-years now, the buzz of Bitcoins, Ethereum, Cryptocurrency have remained at peaks. Be it the rise of such currencies, adoption by countries, or stringent laws enforced by governments. Amidst all this noise the one solid technology that has sustained and growing at equal strides is the decentralized applications or more popularly addressed as DApps.
Developers and enthusiasts who track technology trends regularly who not need much introduction but there is always someone catching up and this dispatch is more for such readers. This serves a quick summary for those trend trackers as well.
Before we dive in, please keep the bias or interest on cryptocurrency and the concept of money away at bay.
Those forms are only offshoot of the concept and are not the concept in entirety.
Concept of decentralized apps pivot on the core concept of decentralized ledgers. Not to be confused with distributed computing, decentralized apps though work and runs on various networked computer the similarity between those terminology ends there. Decentralized apps work with zero-trust environment and needs majority of cohort to agree. This is over and above the features that the app offers. E.g., Decentralized apps can serve content publishers, digital wallets, or for that reason it can be for entertainment game as well.
If you feel we left dangling on the sentence where we say “majority of cohort [needs] to agree”, it was intentional. They need to agree on information that gets recorded in ledger. Ledger is the source of truth for all participating members in the DApp. One of another popular way of introducing Dapp’s are – it is not owned by a single entity (individual or organization or anything else). Thus, while introducing we used the word zero-trust environment. With those ideas straightened let us have a quick summary at what is Dapp before we move further onto the interesting topic – “How does developer sharpen their skills on this topic?”.
DApp is a distributed application operates on nodes with zero-trust between them. These apps use a distributed ledger as a source of truth for the data they operate upon which differs based on the utility or feature the Dapp offers.
During our regular technologists gathering we exchanged our perspectives to arrive at what you have seen as our understanding of Dapp. By no means was that a formal definition. But it served purpose in grasping the concept. However, there was one topic which we all avoided while building this understanding of Dapp. It was of cryptocurrencies. That was the topic which started us to talk about Dapp.
Here is how we build our collective understanding on cryptocurrencies – Rather than trying to look at it from Bitcoin or Dodgecoin or any other such coin in circulation, we attempted to build and understanding on Token or popularly addressed in abbreviated form – NFT (Non-Fungible Token).
The data we talked about in the distributed ledger records the transfer of ownership of token. Thus, we could stitch this easily back to Dapp. The question Ownership of what? leads us to the use that Dapp serves and thus fauna of Dapp as it is present in world today. i.e., the token represents the ownership of something. That something could be picture, file, video, music.
After this point we had a vague idea of what this beast was but we did not yet understand what a developer can contribute.
Behold! The nuance related to the topic of “transfer of ownership” brought us the pivotal role developer plays in this world. The concept of ownership and rules associated with a transfer can differ from object to object and principles on which two parties want to exchange them. Bottomline! There are rules.
These rules are to be practiced and policed i.e., no transfer violates this rule and not parties involved in transfer play foul. The only way this could be accomplished is by automating or coding it. Thus, we have Smart Contracts.
Let us look back and summarize the collective understanding with the recent learnings in perspective –
DApp is a distributed application operates on nodes with zero-trust between them. These apps use a distributed ledger as a source of truth for the tokens they create and exchange governed by a smart contract.
This collective understanding helped us now focus our energies on something interesting that we discovered – Smart contracts. This way of building a collective understanding helps us lower the friction between the understanding we have on a topic as well communicate more effectively amongst team members. We all knew there is lot more involved than what was discussed. But by simplifying this quickly changing and complex topic we could focus on where we developers could contribute more and add details as we go along.
Smart contracts are programmed using a programming language. This is different from conventional programming language but works on very similar principles. The most popular language for writing smart contracts is Solidity. Other than Solidity, languages like Vyper, Ivy, Bitcoin Script are also there.
We have shied away from mentioning Ethereum so far. This is a platform which has not been used so far in describing the concept of Dapp. However, before we dive in programming we need to talk about the platform. Platform like Ethereum and Bitcoin define rules by which the overall swarm of participating nodes operate and work with contract etc. Without mincing the words – Dapp runs on a platform. So let us tweak our collective understanding statement a bit to take the form –
DApp is a distributed application running on a platform comprising of nodes with zero-trust between them. These apps use a distributed ledger as a source of truth for the tokens they create and exchange governed by a smart contract.
Now, we have Solidity and it works on Ethereum and like we said earlier common to many modern programming languages Solidity particularly works in a Ethereum Virtual Machine known as EVM.
The easiest way to get going with Solidity is by installing Truffle Suite. To our surprise following command installs Truffle Suite –
npm install truffle -g
|
This is our familiar npm package manager. Does that mean we write in javascript? The answer is a mix of yes and no.
We will use javascript to test and manage the Dapp but we will use Solidity to define the smart contract that is backbone of such app.
Truffle by nature requires its own focused articles to talk about. But if we stay focused on our cause of exploring our common understanding about Dapp, it serves as compiler of smart contract that could be run in Ethereum Virtual Machine (EVM). But this is not the only app that compiles solidity. solc is another npm package that helps compile solidity but it stops there. Taking that outcome into app is something that Dapp developer will have to do by themselves. Truffle just makes the getting started lot easier.
Let us start off on Solidity with scaffolding of its contract and leave a full-fledged discussion on that for the next dispatch.
pragma solidity >=0.4.23 <0.8.0;
contract HelloWorld {
…
}
|
We will make more meaning of this contract and shape it to a specific requirement in our next dispatch. Until then happy coding!