ETHEREUM SMART CONTRACTS DEVELOPMENT

Functions: Part Two

Hello folks! This part will be the final part of Solidity Fundamentals. We will continue to work on functions and examine the following subjects;

  • receive Ether Function
  • fallback Function
  • Function Overloading
  • Events

receive Ether Function

receive function declared using receive() external payable { … } without function keyword that can’t…


ETHEREUM SMART CONTRACTS DEVELOPMENT

Functions: Part One

In this part we will be focusing on the following topics related Functions;

  • Visibility and Getters
  • Function Modifiers
  • Constant and Immutable State Variables
  • Function Parameters and Return Variables
  • Pure, View Functions

Visibility and Getters

There are four types of visibility for Solidity functions and state variables (see: Data Location and…


ETHEREUM SMART CONTRACTS DEVELOPMENT

Assert, Require, Revert, and Exceptions

Reverting state changes to prevent possible issues is one necessity when writing Solidity. In this part we will be working on how to handle errors using revert, require, assert and try/catch to undoes all changes made to the state in the current call.

Currently, Solidity supports two error signatures: Error(string)


ETHEREUM SMART CONTRACTS DEVELOPMENT

Control Structures

Most of control structures that we are familiar from Javascript, C or Python are also exist in Solidity. There is if, else, while, do, for, break, continue, return with the common semantics from above mentioned languages. Let’s look at an example, and investigate each one of them:

While writing…


ETHEREUM SMART CONTRACT DEVELOPMENT

Data Location and Assignment Behaviors

All reference type has an additional annotation, the data location, about where it is stored. There are three possible options: memory , storage,and calldata.

storage: The location type where the state variables are stored on blockchain which means types that has storage location are persistent.

memory: Variables are in memory


ETHEREUM SMART CONTRACTS DEVELOPMENT

Reference Types

In this part, we will examine reference typesarrays, struct and mapping which store the location of the data, a reference, and don’t share the data directly. …


ETHEREUM SMART CONTRACTS DEVELOPMENT

Value Types: Part Two

In this part, we will be looking at the value types below;

  • Fixed-sized byte arrays
  • Dynamically-sized value types (bytes, string)
  • Enums

Fixed-sized byte arrays — bytes1 (byte), bytes2 … bytes32

The value types bytes1, bytes2, …, bytes32 includes a sequence of bytes from 1 to 32. The keyword byte is…


ETHEREUM SMART CONTRACTS DEVELOPMENT

Operators: Arithmetic, Logical, Comparison, Assignment, Bitwise, Conditional

In this section, we will learn operators which are play vital role in any programming language. At the same time, operators that are used in Solidity are very similar to Javascript. We can group them in 6 prominent categories;

  1. Arithmetic Operators
  2. Logical Operators
  3. Comparison Operators
  4. Assignment Operators
  5. Bitwise Operators
  6. Conditional…


Ethereum Smart Contracts Development

Value Types: Part One

Let’s briefly look at what this section will include. We will be examining value types that are passed by value, further, if value store its own data not a pointer to a specific memory location it’s called value types — also known as primitive data types. …


ETHEREUM SMART CONTRACTS DEVELOPMENT

Layout of a Contract

Let’s briefly talk about what this series is about. Here are some topics that we will discuss, I hope you will enjoy it.

  • Solidity Fundamentals
  • Infrastructure (Metamask, Infura, DappNode)
  • Testing Ethereum Smart Contracts (Waffle, Truffle Suite, Dapp Tools)
  • Smart Contracts Security Best Practices

Ferdi Kurt

Smart Contract Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store