Here I start a series of code walkthroughs and tutorials to learn solidity by actually building projects. Solidity is the programming language used to build distributed applications on the Ethereum Blockchain. If it all sounds confusing, don’t worry, you’ll get the hang of it pretty quickly. Just a few basics about what the Blockchain is and what is meant by a distributed application is enough to get started.Having said that, I believe the best way to learn something new is by doing, and this is what I have done so far in my software career. It is the approach that works best for me, and I hope it does for you too.

Follow me here to get updates about new solidity tuts, as well as other Blockchain based projects I might be working on.

Without further delay, let’s get started.

The IDE — Remix

Remix is the current favourite IDE for Solidity. You can find an online version here. IMO, this is the best way to get started. If you want advanced options like a command line compiler or an offline version of the IDE, visit this

Your first Smart Contract

Let’s start this part by writing our most basic program and comparing it with existing technology. Understanding this program will enable you to understand how fundamentally blockchain programming differs from normal programming, and should hopefully get you excited.

pragma solidity ^0.4.0;



contract StoreMessage {

bytes32 welcomeMessage;



function setMessage(bytes32 message) public {

welcomeMessage = message;

}



function getMessage() public constant returns (bytes32) {

return welcomeMessage;

}

}

The first line is for the compiler. It informs the compiler about the solidity version. Current being 0.4.0. All programs should begin with this.

Next is the StoreMessage contract. The StoreMessage contract resides at a particular address on the blockchain. We have functions to modify the welcomeMessage variable. A getter and a setter.

This is a simple blueprint for a contract, called the StoreMessage contract. All it does is help you store a message at a particular address in the variable welcomeMessage (Don’t overthink bytes32, think of it as a string for now) and retrieve it using getMessage. Anyone can alter the value of this variable.

The key point to note here is, although anyone can modify your variable welcomeMessage, any modification to it will be stored in the history of the blockchain. This enables us to know exactly how it was modified. This is fundamentally different from other ways of programming, wherein we don’t generally store the modification history of a state variable belonging to a class.

There you go, you just wrote your first smart contract! Deploying it on the Ethereum Blockchain is a topic for another post, but first, we will try and get our hands dirtier with more solidity programming using more complex examples! Click here for the next tutorial. Don’t forget to follow! It motivates me to do better.

Stay updated

Join us on Telegram : https://t.me/joinchat/G4Ls4hLyjTLLNke_3QGygQ

Join the ebook email-list! : https://goo.gl/FtRCuX

Ebook

Liked it? Want to explore more? If you’re just getting started, my ebook — “Blockchain programming for absolute beginners” is a perfect start. Have a look at it’s contents here!