Exception Handling

The exception handling mechanism in solidity is defined for handling cases when the error is made on the user’s end like invalid inputs, or even validate a condition.

  1. revert: Used when we want to revert the state of smart contract back to how it was, in case exception conditions arise.
  2. required: It enforces a condition satisfying mechanism to ensure a certain condition is met before a piece of code is executed. (Input validation mechanism)
  3. assert: unlike revert and required, assert is used to pre-enforce conditions. Suitable for conditions that should NEVER Occur.

Unlock the Power of Solidity: Exploring the Essential Keywords for Smart Contract Development

Solidity is a smart contract programming language built solely to develop smart contracts that can be deployed on blockchains. C++ and JavaScript inspired it, an Object Oriented and High-Level language (HLL), that helps developers define the behaviour and rules for a Decentralized Application (Dapp). Smart contract facilitates autonomous, secure, and efficient transaction execution on the blockchain without needing any intermediary (self-executable) and solidity provides the base framework for achieving the same.

It is essential to understand the common keywords used in solidity to solidify your core understanding of the language so in this article, we’ll pin down some prominent keywords that help us develop these smart contracts by embracing the true power of solidity language.

Table of Content

  • Contract
  • Constructor
  • Data Types
  • Delete
  • Enum
  • Function
  • Interface
  • Import
  • Struct
  • Visiblity Specifiers
  • Exception Handling
  • Pragma Directive
  • License Defintion
  • Modifier
  • Data Location
  • Global Variables
  • Fallback Function
  • SelfDestruct
  • ‘assembly’ and ‘inline assembly’

Similar Reads

Contract

The keyword ‘contract’ as indicated by its name is used to define a smart contract....

Constructor

Constructor keyword is used to create a constructor which is a special type of function that will be executed as soon as the smart contract is Deployed to the chain, and is used to set the initial state variables in the contract and do some initilial startup work....

Data Types

address: Stores ethereum address, either a contract address or account’s address.bool: Stores a true or false binary value.int or unit: int is a positive or negative value, uint (unsigned integer) is a positive whole number storage type.bytes: Represnts a dynamic array used for storing arbitrary binary data.string: It is a data type defined for storing the long sequence of alphanumeric and special characters. Mainly used for storing UTF-8 encoded characters – text data....

Delete

The ‘delete’ keyword is used along with the state variables or structs for resetting their values. It helps in managing the contract state and resources by clearing the data structures values, resetting states etc....

Enum

The keyword ‘enum’ is used to declare an enumeration type consisting of only some of the selected pre-defined values that are called ‘enumerators’....

Function

A function is a set of code statements that are executed when a function is called from the inside (from another function) or outside of the smart contract....

Interface

The ‘interface’ keyword is used to declare an interface in solidity for providing a declaring for functions that will be implemented by smart contracts....

Inheritance – ‘is’ keyword

In the context of Solidity, Inheritance refers to the property of once smart contract to acquire properties of another smart contract. The ‘is’ keyword is used for two purposes:...

Import

Import statements are nothing but extracting and accessing a piece of code that exists somewhere outside the current file. In solitidy, we can import from two places:...

Struct

‘struct’ keyword is used to declare a structure that consists of various different data types. It is used to declare a new ‘type’ in itself like a custom data type....

Visiblity Specifiers

Visibility specifiers are analogous to the access specifiers or modifiers in object oriented languages, they define the visibility and accessibility of the function or variables....

Exception Handling

The exception handling mechanism in solidity is defined for handling cases when the error is made on the user’s end like invalid inputs, or even validate a condition....

Pragma Directive

Solidity and Blockchain is an ever evolving space, that’s why many updates and breaking changes are made very often compared to any other technologies that’s why it offers this feature to avoid compatibility issues....

License Defintion

It is used to specify the license version under which the code will be distributed (made available to everyone). Every license has their own set of protocols for right to use, code modification, copy writing guidelines etc. Solidity has some of the popular license under : SPDX (Software Package Data Exchange), Apache License, MIT License, GPL & LGPL etc....

Modifier

In Solidity, modifiers are special type of functions that helps us add some extra functionality to the existing functions. You can define a modifier by using keyword ‘modifier’ followed by its name, and parameters it may take....

Data Location

In solidity, for effective memory management we can decide where to store the variables based on their nature or existence duration....

Global Variables

Some variables are facilitated for accessing the global state of the blockchain :-...

Fallback Function

Fallback function is a special type of function in solidity that is called when either condition is met :-...

SelfDestruct

It helps clearly define the contract’s exact purpose and can be used to introduce a loophole or honeypot in the contract, indicating its vulnerability. Example: After certain amount of ethers are collected, then it will first call a transfer function to transfer all the ether to another address and then self-destruct like it never existed....

‘assembly’ and ‘inline assembly’

Both the keywords are typically used when we’re trying to define assembly level bytecode for the EVM (Ethereum Virtual Machine) directly....