• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Codemotion Magazine

Codemotion Magazine

We code the future. Together

  • Magazine
  • Dev Hub
    • Community Manager
    • CTO
    • DevOps Engineer
    • Backend Developer
    • Frontend Developer
    • Web Developer
    • Mobile Developer
    • Game Developer
    • Machine Learning Developer
    • Blockchain Developer
    • Designer – CXO
    • Big Data Analyst
    • Security Manager
    • Cloud Manager
  • Articles
    • Stories
    • Events
  • Sign In
Home » Dev Hub » Blockchain Developer » Solidity: “Hello World” with the Blockchain language
Blockchain Developer

Solidity: “Hello World” with the Blockchain language

Dive into how Solidity works, how it is translated in the Ethereum Virtual Machine, and which IDE to use to write code.

Last update December 21, 2019 by Giacomo Barbieri

Solidity, "hello world" with the Blockchain language

In a previous article, we introduced the basic concepts of the Ethereum Blockchain, including a quick overview of ERC-20 tokens.

This article dives into Solidity, the programming language used to interact with the Ethereum Blockchain. We will learn how it works, how it is translated in the Ethereum Virtual Machine and then executed, and which IDE should be used to start writing code.

Solidity

The principal and most widely known language used to write smart contracts in Ethereum is Solidity. Designed in 2014, a few months before the official launch of the Ethereum Blockchain, Solidity is now used for the Ethereum public Blockchain, as well as for private Blockchains such as Hyperledger. As discussed in the first article of this series, Solidity is a statically-typed programming language that runs smart contracts on the EVM, Ethereum Virtual Machine.

Solidity is compiled of bytecode that is subsequently executed on the EVM. To date, there are a total of 142 valid opcodes that make up the bytecode necessary to compile any Ethereum smart contract.

Another commonly used language is Vyper, based on Python, but the focus of this series does not include the development of smart contracts with Vyper.

The Ethereum Virtual Machine

On the Ethereum Blockchain, a smart contract is a simple Ethereum address with a special capability – running EVM bytecode when receiving a transaction, which allows the performance of calculations and further transactions.

Transactions can carry a payload of 0 or more bytes of data, used to specify the type of interaction with a contract and any additional information.

The smart contract begins execution on the EVM at the beginning of the bytecode: each opcode is encoded as one byte (except for PUSH opcodes, which have an immediate value). Every opcode is also associated with a specific gas cost. The sum of all the gas costs of a smart contract is the cost of one execution of the smart contract. Since gas cost is critical in ensuring the viability of a smart contract (an expensive-to-run smart contract is often not feasible for actual use), it’s important to bear in mind that a smart contract needs to run with the fewest possible instructions. A full list of gas costs per opcode is available here.

Interaction with a smart contract is possible with a public ABI – a list of supported ways a user can interact with a contract.

To interact with the contract, users submit a transaction carrying any amount of gas (even 0 is acceptable) and a data payload formatted according to the ABI, specifying the type of interaction and any additional parameters.

The logical structure of a smart contract can be divided as described below:

  • Call Data: the data associated with a transaction. This usually contains a 4-byte method identifier followed by serialized arguments;
  • Stack: the EVM maintains a stack of uint256 that is used to hold local variables, function call arguments and return addresses;
  • Memory: an array of uint8 is used to hold processing data while the contract is being executed – this data does not persist across consequent transactions
  • Storage: a persistent associative map, with uint256s as keys and values, that contains all contract fields and mappings.

Choosing the IDE

To write code and test smart contracts, a plethora of IDEs is available, both as online and offline applications. A complete list (as of today) of all the known IDEs used to develop Solidity  is provided below, then we dive into the simplest to use.

Online

  • Remix: Built-in static analysis and test Blockchain VM;
  • Ethereum Studio: Built-in browser Blockchain VM, Metamask integration (one-click deployments to Testnet/Mainnet), transaction logger and live coding;

Offline

  • Atom: editor with Atom Solidity Linter, Etheratom, autocomplete-solidity, and language-solidity packages;
  • VIM Solidity: VIM syntax file for Solidity;
  • Visual Studio Code: Visual Studio Code extension that adds support for Solidity;
  • IntelliJ Solidity Plugin: open-source plug-in for JetBrains IntelliJ Idea IDE (free/commercial) with syntax highlighting, formatting, code completion;
  • YAKINDU Solidity Tools: Eclipse-based IDE, featuring context-sensitive code completion and help, code navigation, syntax coloring, built-in compiler, quick fixes and templates;
  • Eth Fiddle: allows you to write, compile and debug the smart contract. Features sharing and search of code snippets.

For this series, we will use Ethereum Studio. This is the most complete out-of-the-box solution for developing and deploying smart contract on the network.

First steps with Ethereum Studio

Ethereum Studio is available on studio.ethereum.org. Visiting the website will activate a pop-up banner that instructs the user to choose from a set of smart contract templates. For now, we will choose the ‘Hello World’ smart contract template – this will allow us to understand the basics of development without writing specialized code.

An ‘Hello World’ template on Ethereum Studio – studio.ethereum.org,

Before writing any actual code, it’s important to understand all the basic functions of Ethereum Studio.

The window is divided into three panes (from left to right):

  • Explorer: in the first pane, one can view the usual file hierarchy. At the top of the explorer, one can view the blockchain network on which the contract will run (the default is the Browser blockchain – a fake blockchaindesigned for running tests on) and the associated contract address. Note that only one smart contract can be deployed per address.
  • Text: where the code should be written
  • Simulator: a visual simulation of the functions of the smart contract or, in the case of smart contracts running at the core of an app, a rendering of the app (much like Xcode).

In preferences (top-right corner of the window), it’s possible to adjust the gas requirements of the contract, setting personalized amounts for gas limit and gas price (in Gwei).

At the bottom of the window, you’ll find basic information about the account address and the network: the address balance (in ETH), the gas limit, the gas price and the address of the network.

Now we’re finally ready to write some code. In the articles that follow, we will write basic functions and discover how to create smart contracts for different purposes.

Tagged as:Ethereum Blockchain Languages Smart Contracts

Reactive Forms in Angular
Previous Post
System Administrator’s DOs and DON’Ts: interview with Kenneth Hess
Next Post

Primary Sidebar

Whitepaper & Checklist: How to Organise an Online Tech Conference

To help community managers and companies like ours overcome the Covid-19 emergency we have decided to share our experience organizing our first large virtual conference. Learn how to organise your first online event thanks to our success story – and mistakes!

DOWNLOAD

Latest

Decoding Adaptive Vs. Responsive Web Design

Decoding Adaptive Vs. Responsive Web Design

Web Developer

How to Implement Data Version Control and Improve Machine Learning Outcomes

How to Implement Data Version Control and Improve Machine Learning Outcomes

Machine Learning Developer

7 Ways to Use UX Design to Enhance User Data Security

7 Ways to Use UX Design to Enhance User Data Security

Security Manager

What are the Main Areas of Development for Programmers to Land Their Dream Job? Codemotion

What are the Main Areas of Development for Programmers to Land Their Dream Job?

Backend Developer

How to Contribute to an Open-Source Project

How to Contribute to an Open-Source Project

Backend Developer

Related articles

  • Blockchain Developers’ Dream Job: What Are the Main Areas of Development?
  • Exploring Primecoin: An Alternative Cryptocurrency Project
  • How Blockchain Technology Can Ensure Data Security in Space?
  • How to improve your Blockchain developer career
  • Blockchain and cryptocurrencies serving against COVID-19
  • Building the controller of a decentralised application with web3.js
  • Practical business cases of blockchain-based solutions
  • Creating the interface of a smart contract
  • The Convergence of IoT and Blockchain is Transforming Industries
  • The blockchain security risks that you don’t hear about

Subscribe to our platform

Subscribe

Share and learn. Launch and grow your Dev Community. Join thousands of developers like you and code the future. Together.

Footer

  • Learning
  • Magazine
  • Community
  • Events
  • Kids
  • How to use our platform
  • About Codemotion Magazine
  • Contact us
  • Become a contributor
  • How to become a CTO
  • How to run a meetup
  • Tools for virtual conferences

Follow us

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • YouTube
  • RSS

DOWNLOAD APP

© Copyright Codemotion srl Via Marsala, 29/H, 00185 Roma P.IVA 12392791005 | Privacy policy | Terms and conditions

  • Learning
  • Magazine
  • Community
  • Events
  • Kids
  • How to use our platform
  • About Codemotion Magazine
  • Contact us
  • Become a contributor
  • How to become a CTO
  • How to run a meetup
  • Tools for virtual conferences

Follow us

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • YouTube
  • RSS

DOWNLOAD APP

CONFERENCE CHECK-IN