Learn Solidity 01: Writing your first Smart Contract
By: Adesiji Blessing
Tags: Blockchain Technology, Solidity, Smart Contracts, Ethereum, Blockchain

Photo by Zoltan Tasi on Unsplash

I have been fascinated by blockchain technology for so many reasons, which I will not discuss in this article. However, it’s not a new topic that cryptocurrency is the future of money, and NFTs are doing incredibly impressive for digital artists.

So what is my aim with this article? I got interested in the blockchain space, and after doing a lot of research, I couldn’t find enough learning guides like you would, for, say, Data Science which is pretty standard. It would help if you understood that the reason for this is that there is a shortage of Solidity programmers(about 200,000* developers in the world) compared to other popular programming languages. Therefore, there aren’t enough tutorials out there. Hence, I will be writing a series of articles on learning the language, and you can learn from this to become a blockchain developer.

This is the first article of the series, and it will be on writing your first smart contract with Solidity. There are many concepts that you might not be familiar with yet, and that’s perfectly okay. I will do my best to break down each concept into bits as we move along the series, and you can do more research from there.

To get started, here are a few questions that you should be asking; What is a Smart Contract? What is Solidity? How does the blockchain work?

Follow along as I provide answers to these questions below.

What is a Smart Contract?

A “Smart Contract” is simply a program that runs on the Ethereum blockchain. It is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Think of a smart contract as an account on the Ethereum network, which can not be controlled by the user and runs as a program. However, a user can interact with a smart contract by submitting transactions that execute a function defined on the smart contract.

The way smart contracts ensure that transactions occur in real life is much more complex, but here is a simple explanation to understand how things work.

Photo by Cedrik Wesche on Unsplash

Imagine that this article is for sale, and I am the seller, you the reader is the buyer, and you are buying this article by using an affiliate link you saw on the internet. We can deploy a smart contract for this transaction, and here’s how the exchange might occur.

You, the reader, creates a transaction that sends the price of this article to the seller in exchange for a copy of this article. Like you would usually in a normal bank transaction, you will provide my address as an input to the smart contract’s address. The smart contract will then carry out this transaction by verifying that you have enough money in your wallet and that I also have a copy of this article ready for sale. Then, it deducts the money from your wallet, sends it to my wallet, tells me to send you a copy of the article, and finally sends the affiliate commission to the owner of the affiliate link after deducting that from my wallet.

The above is how smart contracts can facilitate transactions between users who do not trust each other, and it is used in the real world to carry out much more complex transactions.

This leads us to the following question: What is Solidity?

What is Solidity?

We already established the fact that Smart Contracts are software programs. For Ethereum, you can write smart contracts using a statically-typed language called Solidity, which is the most widely used smart contract programming language at the moment. Solidity is a full-featured language for writing general-purpose smart contracts, and it looks like JavaScript.

How does the blockchain work?

To answer the last question, I think it’s an important concept to know. I will share a good video by Anders Brownworth, it explains the concept: How does the blockchain work?

Watch here; an elementary visual introduction to the concepts behind how the blockchain works.

Now that you have a good understanding of the concepts above let’s see how you can write your first smart contract.