btc/usd
0.36%67,175.64
eth/usd
1.16%3,136.12
ltc/usd
0.29%84.355
xmr/usd
0.87%136.005
xrp/usd
0.07%0.52339
Home > Courses > Blockchain Programming > Solidity Programming and Smart Contracts > Creating dApp With Solidity | Blockchain Coding | Intro

Creating dApp With Solidity | Blockchain Coding | Intro

Share:
Creating dApp With Solidity | Blockchain Coding | Intro

Here is a clear line-by-line Solidity coding guide to start creating your own Blockchain solutions, dApps or anything you like at the crypto universe. Let’s clarify all the basics.

We are getting closer to the Internet revolution right now. It’s going to be decentralized again, like in good old times. Peer-to-peer technologies such as Torrent proved their efficiency and real value to everyone. By the way, I’m a big fan of the T.V. show “Silicon Valley”. I love the idea of the company with a strange name, Pied Piper, to decentralize data storage and spread all files between all people using their smartphones. We haven’t already got the prototype of Pied Piper code in the real world (by the way, the Filecoin project is making something similar), but I know what can help to get closer and scale it not only to data storage. It’s the Blockchain technology.


Blockchain for backend development


Backend code is a set of commands for the server, the way it should deal with all the data. It is usually performed with such languages as PHP or Python. The main problem here is that code could be changed and manipulated in a way beneficial for some groups of people. Imagine it can’t. 

Blockchain code could also be used for backend programming. And the fun part here is that no changes could be made. You can only deploy new regulations in the new directory. But the old code lives in its original form. Furthermore, no operations or transactions could be changed. All of them will be stored in the Blockchain ledger forever.


Solidity


One of the most popular Blockchain programming languages right now is called Solidity. Vitalik Buterin, the primary author of Ethereum, has created it. Solidity is used for making smart contracts. Remember, the smart contract is a code that defines the rules for all participant's controls and penalizes them for breach of obligations.

The most practical and widespread usage of Solidity nowadays is the development of dApps (decentralized applications). 

Here is the list of areas for solutions available in the dApp market right now:

- Games

- Exchanges

- Collectibles (something like rare and unique baseball cards but on Blockchain)

- Casinos

- Video streaming

- Trading signals

etc.

I believe the scope of possible applications is way more huge. We need some time to adapt the technology and build excellent products. And we are writing this guide today precisely for this purpose. Every person could benefit from Blockchain technology, especially if they understand the basics. Who knows, maybe YOU are the person who will make a revolution on the Internet.

So, let’s move on to Solidity coding principles.


 Our first smart contract


Let’s make a code in Solidity. Have a look at the finished version: 



pragma solidity ^0.4.17;
contract Whatsup {
    string public message;
    function Whatsup (string firstMessage) public {
        message = firstMessage;
    }
    function setMessage(string newMessage) public {
        message = newMessage;
    }
    function getMessage() public view returns (string) {
        return = message;
    }
}

At first sight, it looks a bit confusing...
And what does this code do?

It allows anyone to write a text message to the Blockchain. Then, anyone can write another letter, and the program will update (replace) the first message with the second message. All these actions will be saved on our Blockchain forever. 


Explanation of the code


No reason to be scared. Like any programming language, Solidity has basic commands and functions. So we need a bit of practice to feel comfortable with it.

Let’s clarify our intelligent contract code line by line: 


pragma solidity ^0.4.17;

We declare the version of Solidity here, which a compiler program will use. The compiler program translates Solidity to something called Bytecode, which is used by the Ethereum network to understand our smart contract. One of the best and most popular compilers is Remix. We will use it later in our guides.
Solidity is updated regularly, and for this reason, the code does not contradict new rules; we have to state the version that we know and that meets our requirements. It doesn’t mean our code could become old-fashioned. It always depends on the tasks we perform. So if the old version meets our needs, we can use it. You can find the manuals for all the arrangements on the Solidity website


contract Whatsup {

We create an intelligent contract named “Whatsup.”


 string public message;

We make a variable and set a name as “message.”
The type of variable is a “string.” It’s just a piece of text. It’s not an integer, comparison, address (Ethereum address is a type at Solidity), array, or bool (“true” or “false”).  

“public” means the variable will be accessible to everyone.


function Whatsup (string firstMessage) public {
 message = firstMessage;
 } 

We add a function (its name will be “Whatsup,” the same name as our Contract name) which will save our “message” after we write it to the box “firstMessage”. 

If the function has the same name as the contract (“Whatsup”), it is called a Constructor Function. The Constructor Function is called automatically after intelligent contract deployment to the Ethereum network.


function setMessage(string newMessage) public {
 message = newMessage;
 }

This function named “setMessage” will let everyone (“public”) change our variable “message”. 

And we can change it to a new variable (with the name “newMessage”) with the “string” type (see an explanation of string type above). It means anyone can write the text line to the Blockchain, which will be saved as our “message”.


 function getMessage() public view returns (string) {
 return = message;
 }

The function we called “getMessage” shows (“return”) everyone (“public view”) our updated “message” variable. “returns” is used to clarify the type of value (“string”) that the function will give.

By the way, every time we make a function, we need to set some function arguments, and they need to be in brackets. Functions call arguments and perform some operations with them. As you see in the function getMessage(), it has no arguments as it doesn’t need them in this case, it just shows our “message”.  

One more thing about the “getMessage” function. We don’t need it at all. The reason is that we get our “message” anyway with the first constructor function, “firstMessage”. So, the function “firstMessage” performs the same action as the “getMessage” function by default.


Conclusion


That’s it. Not so complex, agree? 

Programming is just a game. You have a goal, and you have some weapons. Practice makes perfect; bit by bit, you become a ninja.

We also need to know the following:

- more commands and their usage

- how to deploy the smart contract to the real Blockchain

- how to connect frontend (website or mobile app) to the backend (Solidity)

- real-life cases to apply Blockchain in

Next time, we will make something more exciting and practical. 

Check our list of Blockchain programming courses available online.

Stay tuned! 


Comments

Scroll to top