- Toshendra Kumar Sharma
- May 29, 2024
What is Solidity?
Solidity is known as a contract-based, high-level programming language. This platform has similar syntax to the scripting language of JavaScript. Solidity as a programming language is made to enhance the Ethereum Virtual Machine. Solidity is statically typed scripting language which does the process of verifying and enforcing the constraints at compile-time as opposed to run-time.
This typed programming languages will help and do the checking at run-time as opposed to Compile-time. This platform also supports inheritance in object-oriented programming, inheritance enables new objects to take on the properties of existing objects. A class that is used as the basis for inheritance is called a superclass or base class. A class that inherits from a superclass is called a subclass or derived class. As you will see, it is possible to create contracts for voting, crowd funding, blind auctions, multi-signature wallets and more.
Ethereum Language
The source code in Ethereum language is written in Solidity version 0.4.0 which does not break functionality.
The first line of code pragma solidity contract does not suddenly behave differently with a new compiler version. According to the docs, the keyword pragma is called that way because, in general, pragmas are instructions for the compiler about how to treat the source code. Pragma once is a preprocessor directive that tells the compiler to include the source code once in a single compilation.
The line unit stored data declares a state variable called stored data of type unit. The functions set and can be used to modify or retrieve the value of the variable. Believe it or not, this is an Ethereum contract, albeit a rather simple deal. The functions of this contract allow you or anyone to store a single number that is accessible by anyone in the world without a feasible way to prevent you from publishing this figure. Anyone could just call set again with a different value and overwrite your number, but the number will still be stored in the history of the blockchain. The line unit stored data declares a state variable called stored data of type unit.
The example above is the simplest form of an Ethereum contract. Like learning mathematics, this contract is equivalent to adding and subtracting. Obviously, mathematics is more complicated than just adding and subtracting, but at the fundamental level, all of the mathematics can be broken down into addition/subtraction operations. For example, 5×5 is the same as adding 5 five times. A similar thought process can be used in programming to build programs of higher complexity.