Posts

Solidity - Variable Scope

  Scope of local variables is limited to function in which they are defined but State variables can have three types of scopes. Public  − Public state variables can be accessed internally as well as via messages. For a public state variable, an automatic getter function is generated. Internal  − Internal state variables can be accessed only internally from the current contract or contract deriving from it without using this. Private  − Private state variables can be accessed only internally from the current contract they are defined not in the derived contract from it. pragma solidity ^ 0.5 . 0 ; contract C { uint public data = 30 ; uint internal iData = 10 ; function x () public returns ( uint ) { data = 3 ; // internal access return data ; } } contract Caller { C c = new C (); function f () public view returns ( uint ) { return c . data (); //external access } } contract D is C { function y () publ

Solidity - Variables

 S olidity supports three types of variables. State Variables  − Variables whose values are permanently stored in a contract storage. Local Variables  − Variables whose values are present till function is executing. Global Variables  − Special variables exists in the global namespace used to get information about the blockchain. Solidity is a statically typed language, which means that the state or local variable type needs to be specified during declaration. Each declared variable always have a default value based on its type. There is no concept of "undefined" or "null". State Variable Variables whose values are permanently stored in a contract storage. State Variable Variables whose values are permanently stored in a contract storage. pragma solidity ^ 0.5 . 0 ; contract SolidityTest { uint storedData ; // State variable constructor () public { storedData = 10 ; // Using State variable } } Local Variable Variables whose values a

Solidity - Types

  While writing program in any language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. You may like to store information of various data types like character, wide character, integer, floating point, double floating point, boolean etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Value Types Solidity offers the programmer a rich assortment of built-in as well as user defined data types. Following table lists down seven basic C++ data types − Type Keyword Values Boolean bool true/false Integer int/uint Signed and unsigned integers of varying sizes. Integer int8 to int256 Signed int from 8 bits to 256 bits. int256 is the same as int. Integer uint8 to uint256 Unsigned int from 8 bits to 256 bits. uint256 is the same as uint. Fixed Point Number

Solidity Syntex

A Solidity source files can contain an any number of contract definitions, import directives and pragma directives. Let's start with a simple source file of Solidity. Following is an example of a Solidity file − pragma solidity >= 0.4 . 0 < 0.6 . 0 ; contract SimpleStorage { uint storedData ; function set ( uint x ) public { storedData = x ; } function get () public view returns ( uint ) { return storedData ; } } Pragma The first line is a pragma directive which tells that the source code is written for Solidity version 0.4.0 or anything newer that does not break functionality up to, but not including, version 0.6.0. A pragma directive is always local to a source file and if you import another file, the pragma from that file will not automatically apply to the importing file. So a pragma for a file which will not compile earlier than version 0.4.0 and it will also not work on a compiler starting from version 0.5.0 will be writt

Solidity Overview

 Solidity is a contract-oriented, high-level programming language for implementing smart contracts. It has been designed to target the Ethereum Virtual Machine (EVM). Solidity is an object-oriented programming language for writing smart contracts. It is used for implementing smart contracts on various blockchain platforms, most notably, Ethereum. Solidity is statically typed (A statically-typed language is a language (such as Java, C, or C++) where variable types are known at compile time.), supports inheritance, libraries and complex user-defined types programming language. You can use Solidity to create contracts for uses such as voting, crowdfunding,  and multi-signature wallets. What is Ethereum? Ethereum is a decentralized ie. blockchain platform that runs smart contracts i.e. applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference. In blockchain, decentralization refers to the transfer of control and decision-