January 21, 2026

Capitalizations Index – B ∞/21M

Create the basic Smart Contract – Tran X. Dong – Medium

Create the basic Smart Contract – Tran X. Dong – Medium

Ethereum Developer: Learn Solidity from scratch

First off, what is a Smart Contract? It’s just a piece of code that lives permanently on the blockchain. You create a Smart Contract by sending a transaction with the contract code compiled to bytecode to reduce its size. Contracts can’t be deleted but can be blocked to avoid people from executing functions on it.

The good thing about Smart Contracts is that the initial code can’t be changed. For instance, you can’t upload a Smart Contract “Example.sol” version 1 and override it with “Example.sol” version 2. The version 1 will stay there since the blockchain is immutable. Immutable means that it’s unchanging over time or unable to be changed.

What’s the purpose of a Smart Contract? It allows you to create code that acts like a real-world contract where the conditions can’t be changed. Everybody using that contract is accepting the terms and can trust it because nobody can modify the code after deploying it. It’s like signing a contract for a job and storing it in a super-secret vault that nobody can access.

Meaning that you don’t have to trust third-party companies to do what they say. You just take a look at the code and you’re guaranteed that it will do exactly what it is promising.

They are especially good when it comes to financial application since they can handle and store ether money.

Let’s start right away with how to create a Smart Contract with this language.

During all the tutorials in this book I’ll be using atom.io since it’s my favorite code editor but you can use whatever you feel like using. Sublime text and visual studio code are also very good choices.

A Smart Contract always starts with the version of Solidity that we are using. So open a text editor such as atom, create a new empty document and write the version of Solidity that will be used for this contract at the beginning of the file like this:

pragma solidity 0.4.20;

In this case I’m using the version 0.4.20 but feel free to use the latest version available. You can find the current version in the official docs: Solidity.readthedocs.io. Note that all the lines must end with a semicolon ; to be valid in Solidity.

You can also specify the latest version with the caret symbol ^ to tell the compiler that you want to use the most recent version of Solidity or the one indicated. For instance:

pragma solidity ^0.4.20;

If there’s a version 0.4.21 or bigger, the compiler will use that version instead of 0.4.20. It also depends on the compiler you’re using. Most of them allow you to change the version used at any moment.

However I don’t recommend this because you never know what version is being used when compiling the contracts and newer versions may be incompatible with the code of the contract. It’s not unusual to deprecate keywords making your contract invalid for that newer version.

For that reason, remember to not use the caret symbol when specifying the version of Solidity.

Then, you start your contract by defining the name of it with the keyword contract:

pragma solidity 0.4.20;

contract Example

You can use any name. Remember to capitalize the first letter to indicate that it is a contract. Just like classes in java.

Now you can start writing the contract logic. But before doing that, save the file with the termination .sol for instance Example.sol. This is the official Solidity file termination. Remember to name the file based on the contract name inside. For instance if you’re creating a contract called Robot it will be confusing to name the file Car.sol. Be smart and keep things simple by using the same name in the file.

At this point you know how to create the basic structure of a Smart Contract. Next, you’ll see the types of variables that you can use in a contract to store information on the blockchain.

Published at Wed, 20 Feb 2019 10:09:07 +0000

Previous Article

Cryptos ‘Not a Substitute’ for the Yellow Metal, Says World Gold Council

Next Article

45 Days Left for SEC to Decide on CBOE-VanEck Bitcoin ETF

You might be interested in …