Home Basic Solidity Smart Contract – Newbie Guide

Basic Solidity Smart Contract – Newbie Guide

by cryptocreed

Last Updated on November 11, 2022 by cryptocreed

The issue with figuring out how to code on Ethereum smart contract is to know where to begin from. After simply finding out about blockchains and Ethereum, you attempt to google, in the expectations of started but you are obstructed taking a gander at dozen conceivable alternatives with confusing stuff you don’t get it. You needed to make a Dapp that would inevitably go on a blockchain, but can’t even begin to begin.

All things considered, there is uplifting news. Making a smart contract doesn’t need to be that overwhelming. With only a fundamental comprehension of any protest situated language (C++, C, Java, and so on), the correct apparatuses and setup available to you, you could undoubtedly make easy to complex smart contracts and test them out in practically no time without expecting to get into the agony of knowing how to send the contracts.

Give us a chance to start with the most basic illustration. It is fine on the off chance that you don’t comprehend everything at this moment; we will go into more detail later.

 Also Read: How To Build Ethereum Smart Contract

Also Read: Most Profitable Eth Mining pool


pragma solidity ^0.4.0;

contract SimpleStorage {

    uint storedData;

    function set(uint x) public {

        storedData = x;


    function get() public constant returns (uint) {

        return storedData;



The principal line basically tells that the source code is composed for Solidity variant 0.4.0 or anything more up to date that does not break usefulness. This is to guarantee that the contract does not all of a sudden carry on distinctively with another compiler variant. The catchphrase pragma is called that way because, in general, pragmas are directions for the compiler about how to treat the source code (e.g. pragma once).

A contract in the sense of Solidity is an accumulation of code (its functions) and information (it’s express) that dwells at a particular address on the Ethereum blockchain. The line uint storedData; pronounces a state variable called storedData of sort uint (unsigned whole number of 256 bits). You can consider it a solitary opening in a database that can be questioned and modified by calling elements of the code that deals with the database. On account of Ethereum, this is dependably the owning contract. What’s more, for this situation, the capacities set and get can be utilized to change or retrieve the value of the variable.

To get to a state variable, you do not need the prefix this. as is normal in different languages.

This contract does not do much yet aside from enabling anybody to store a single number that is accessible by anyone in the world without a (feasible) way to keep you from distributing this number. Obviously, anybody could simply call set again with an alternate value and overwrite your number, however, the number will at present be put away ever. Afterward, we will perceive how you can force get to limitations with the goal that no one but you can change the number.

This contract introduces some new concepts; let us go through them one by one.

The line tends to open minter; pronounces a state variable of sort address that is publicly accessible. The address type is a 160-piece value that does not permit any arithmetic operations. It is appropriate for putting away locations of agreements or keypairs having a place with outside people. The catchphrase public automatically generates a function that allows you to access the current value of the state variable. Without this catchphrase, different contracts have no real way to get to the variable. The function will look something like this:

function minter() returns (address) { return minter; }

Obviously, including a function exactly like that won’t work since we would have a function and a state variable with a similar name, however, hopefully, you get the idea – the compiler figures that out for you.