First SMART CONTRACT

·

2 min read

Smart contracts are piece of code stored inside a blockchain.They are helpful in eliminating the dependency on third party interferences. Smart contracts can't be changed once created. If some problem arises in existing smart contract then a totally new one is created accordingly. Smart contract only executes when all the pre-determined conditions are met otherwise it won't execute.

Smart contracts are the fundamental building blocks of Ethereum applications. These programs are written in an advance programming language called Solidity.

It's an object-oriented language that targets the Ethereum virtual machine (EVM). This language is statically-typed and supports complex programming features such as inheritance and user-defined data types.

To write contracts we can install solidity compilers but for small contracts we can use Remix IDE. It is a web browser based IDE that allows us to write, deploy and administer Solidity smart contracts, without the need to install Solidity locally.

This code below is the implementation of smart contract.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.16 <0.9.0;

contract SimpleStorage {

}

The first line should be added to the top of contract files. SPDX license identifiers were introduced in Solidity 0.6.8 so developers can specify the license the contract uses. SPDX License Identifiers can be used to indicate relevant license information at any level, from package to the source code file level. The MIT license gives users express permission to reuse code for any purpose, sometimes even if code is part of proprietary software.

In second line keyword pragma is used, it is a directive that specifies the compiler version to be used for current Solidity file.

Another way to specify solidity version is by :

 pragma solidity ^0.4.4;

If a source file is of this version, it means the file will compile with 0.4.4 and higher versions in the 0.4.x branch, up to version 0.5.0 where 0.5.0 is not included.

In the next line actual code starts. Contract is a key word in solidity, and it tells our compiler that the next section of this code is going to define a contract. Contract is similar to a class in any object oriented programming like Java or JavaScript. Contract keyword is followed by contract name and curly braces within which code's logic is to be written.