Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Solidity Introduction
  • Solidity - Environment Setup
  • Solidity - Basic Syntax
  • Solidity - Types
  • Solidity - Operators
  • Solidity - Mappings
  • Solidity - Functions
  • Solidity - Fallback Function
  • Mathematical Functions
  • Solidity - Inheritance
  • Solidity - Constructors
  • Solidity - Interfaces
  • Solidity - Events
  • Solidity - Error Handling
Open In App
Next Article:
Solidity - Basics of Interface
Next article icon

Solidity - Abstract Contract

Last Updated : 30 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Abstract contracts are contracts that have at least one function without its implementation or in the case when you don't provide arguments for all of the base contract constructors. Also in the case when we don't intend to create a contract directly we can consider the contract to be abstract. An instance of an abstract cannot be created. Abstract contracts are used as base contracts so that the child contract can inherit and utilize its functions. The abstract contract defines the structure of the contract and any derived contract inherited from it should provide an implementation for the incomplete functions, and if the derived contract is also not implementing the incomplete functions then that derived contract will also be marked as abstract. An abstract contract is declared using the abstract keyword. 

Example: In the below example, an abstract contract is created which is inherited by another contract that has implemented all the functions of the abstract contract. Abstract contract instance is created in the calling contract and an object of the child contract is created. Using the object of the child contract all the abstract functions that are implemented in the child contract are invoked.

Solidity
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; /// @title A contract for describes the properties of Abstract Contract /// @author Jitendra Kumar /// @notice For now, this contract just show the functionalities of Abstract Contract abstract contract AbstractContract {     // Declaring functions     function getStr(       string memory _strIn) public view virtual returns(       string memory);     function setValue(uint _in1, uint _in2) public virtual;     function add() public virtual returns(uint); }  // child contract 'DerivedContract' inheriting an abstract parent contract 'AbstractContract' contract DerivedContract is AbstractContract{      // Declaring private variables     uint private num1;     uint private num2;      // Defining functions inherited from abstract parent contract     function getStr(       string memory _strIn) public pure override returns(       string memory){         return _strIn;     }          function setValue(       uint _in1, uint _in2) public override{         num1 = _in1;         num2 = _in2;     }     function add() public view override returns(uint){         return (num2 + num1);     } }  // Caller contract contract Call{      // Creating an instance of an abstract contract     AbstractContract abs;          // Creating an object of child contract     constructor(){         abs = new DerivedContract();     }      // Calling functions inherited from abstract contract     function getValues(     ) public returns (string memory,uint){         abs.setValue(10, 16);         return (abs.getStr("GeeksForGeeks"),abs.add());      } } 

 

Remix IDE

 

Deploy the Smart Contract: After successful compilation of the smart contract select the Call  contract before deploying it.

Select the Call Smart Contract

Output: To get the output of the smart contract click the getValues button and see the output in console log.

decoded output     {                  "0": "string: GeeksForGeeks",                  "1": "uint256: 26"                  }
Output

Here, AbstractContract contract is an abstract contract that has some functions without their implementation, and DerivedContract is its child contract. The getStr() and setValues() functions takes string and values, while the add() function adds the values of setValues() function. abs is an object of AbstractContract which creates an instance of DerivedContract in call contract that uses the variables of the contract and calls the functions.


Next Article
Solidity - Basics of Interface

J

jeeteshgavande30
Improve
Article Tags :
  • Programming Language
  • Solidity
  • Blockchain

Similar Reads

    Solidity Tutorial
    Solidity tutorial is designed for those who want to learn Solidity programming language and for experienced Solidity developers looking to gain a deeper understanding of the language. The following Solidity tutorial explains the basic and advanced concepts of Solidity programming language and provid
    6 min read

    Solidity Basics

    Introduction to Solidity
    Solidity is a brand-new programming language created by Ethereum which is the second-largest market of cryptocurrency by capitalization, released in the year 2015 and led by Christian Reitwiessner. Some key features of solidity are listed below: Solidity is a high-level programming language designed
    5 min read
    Setting Up Smart Contract Development Environment
    A development environment is an environment in which all the resources and tools are available which are used to develop a program or software product. Here, an attempt to create a development environment that is a collection of the processes and tools that are used to develop smart contracts.There
    5 min read
    Solidity - Basic Syntax
    Solidity is a programming language specifically designed for developing smart contracts on the Ethereum blockchain. It is a high-level, statically-typed language with syntax and features similar to those of JavaScript, C++, and Python. Solidity is used to write self-executing smart contracts that ca
    5 min read
    "Hello World" Smart Contract in Remix-IDE
    What do you mean by Smart Contract? Smart contracts are self-executing contracts. The term was coined by Nick in 1994. Smart contracts are very different from traditional software programs. They are immutable once deployed on the blockchain. It was because of Ethereum the term smart contract became
    4 min read
    Solidity - Comments
    Comments are an important aspect of programming as they help in providing clarity and understanding to the code. They allow developers to document the code and explain its purpose, making it easier for others to read and maintain the code. Solidity, being a programming language, also supports the us
    4 min read
    Solidity - Types
    Solidity is a statically typed language, which implies that the type of each of the variables should be specified. Data types allow the compiler to check the correct usage of the variables. The declared types have some default values called Zero-State, for example for bool the default value is False
    4 min read

    Variable and Operators

    Solidity - Variables
    A Variable is basically a placeholder for the data which can be manipulated at runtime. Variables allow users to retrieve and change the stored information.  Rules For Naming Variables 1. A variable name should not match with reserved keywords. 2. Variable names must start with a letter or an unders
    4 min read
    Solidity - Variable Scope
    Variable scope is an essential concept in Solidity, the programming language for Ethereum smart contracts. Solidity has various types of variables with different scopes, such as local, state, and global variables. Local Variable Local variables are declared within a function and are only accessible
    3 min read
    Solidity - Operators
    In any programming language, operators play a vital role i.e. they create a foundation for the programming. Similarly, the functionality of Solidity is also incomplete without the use of operators. Operators allow users to perform different operations on operands. Solidity supports the following typ
    7 min read

    Control Flow in Solidity

    Solidity - While, Do-While, and For Loop
    Loops are used when we have to perform an action over and over again. While writing a contract there may be a situation when we have to do some action repeatedly, In this situation, loops are implemented to reduce the number of lines of the statements. Solidity supports following loops too ease down
    3 min read
    Solidity - Decision Making Statements
    Decision making in programming is used when we have to adopt one out of a given set of paths for program flow. For this purpose, conditional statements are used which allows the program to execute the piece of code when the condition fulfills. Solidity uses control statements to control the flow of
    4 min read
    Solidity - Break and Continue Statements
    In any programming language, Control statements are used to change the execution of the program. Solidity allows us to handle loops and switch statements. These statements are usually used when we have to terminate the loop without reaching the bottom or we have to skip some part of the block of cod
    2 min read

    Reference & Mapping Types in Solidity

    Solidity - Strings
    Solidity is syntactically similar to JavaScript, C++, and Python. So it uses similar language structures to those languages. Strings in Solidity is a data type used to represent/store a set of characters.  Examples: "Hii" // Valid string "Hello World" // Valid string "2022" // Valid string In Solidi
    3 min read
    Solidity - Arrays
    Arrays are data structures that store the fixed collection of elements of the same data types in which each and every element has a specific location called index. Instead of creating numerous individual variables of the same type, we just declare one array of the required size and store the element
    6 min read
    Solidity - Enums and Structs
    Enums are the way of creating user-defined data types, it is usually used to provide names for integral constants which makes the contract better for maintenance and reading. Enums restrict the variable with one of a few predefined values, these values of the enumerated list are called enums. Option
    3 min read
    Solidity - Mappings
    Mapping in Solidity acts like a hash table or dictionary in any other language. These are used to store the data in the form of key-value pairs, a key can be any of the built-in data types but reference types are not allowed while the value can be of any type. Mappings are mostly used to associate t
    4 min read
    Solidity - Conversions
    Solidity is a programming language that is used to write smart contracts for the Ethereum blockchain. One important concept in Solidity is conversions, which allow you to change the type of a variable or expression. The article focuses on discussing three types of conversions in Solidity. The follow
    6 min read
    Solidity - Ether Units
    In the world of Ethereum smart contracts, understanding how Ether (ETH) and its subunits work is crucial. Solidity is the programming language used to write these smart contracts, and it interacts directly with Ether, the cryptocurrency of the Ethereum network. This article focuses on discussing Eth
    7 min read
    Solidity - Special Variables
    There exist special variables and functions in solidity which exist in the global namespace and are mainly used to provide information about the blockchain or utility functions. They are of two types: 1) Block and Transaction Properties: Block Transaction Properties block.coinbase (address payable)C
    3 min read
    Solidity - Style Guide
    Solidity is a computer programming language used to create Ethereum smart contracts. These contracts self-execute. The code and the agreements contained therein are enforced by the blockchain network. Solidity is a high-level language, meaning that it is designed to be human-readable and easy to wri
    13 min read

    Solidity Functions

    Solidity - Functions
    A function is basically a group of code that can be reused anywhere in the program, which generally saves the excessive use of memory and decreases the runtime of the program. Creating a function reduces the need of writing the same code over and over again. With the help of functions, a program can
    4 min read
    Solidity - Function Modifiers
    Function behavior can be changed using function modifiers. Function modifier can be used to automatically check the condition prior to executing the function. These can be created for many different use cases. Function modifier can be executed before or after the function executes its code. The modi
    8 min read
    Solidity - View and Pure Functions
    The view functions are read-only function, which ensures that state variables cannot be modified after calling them. If the statements which modify state variables, emitting events, creating other contracts, using selfdestruct method, transferring ethers via calls, Calling a function which is not 'v
    2 min read
    Solidity - Fall Back Function
    The solidity fallback function is executed if none of the other functions match the function identifier or no data was provided with the function call. Only one unnamed function can be assigned to a contract and it is executed whenever the contract receives plain Ether without any data. To receive E
    3 min read
    Solidity Function Overloading
    Function overloading in Solidity lets you specify numerous functions with the same name but varying argument types and numbers.Solidity searches for a function with the same name and parameter types when you call a function with certain parameters. Calls the matching function. Compilation errors occ
    1 min read
    Mathematical Operations in Solidity
    Solidity is a brand-new programming language created by the Ethereum which is the second-largest market of cryptocurrency by capitalization, released in the year 2015 led by Christian Reitwiessner. Ethereum is a decentralized open-source platform based on blockchain domain, used to run smart contrac
    6 min read

    Solidity Advanced

    Solidity - Basics of Contracts
    Solidity Contracts are like a class in any other object-oriented programming language. They firmly contain data as state variables and functions which can modify these variables. When a function is called on a different instance (contract), the EVM function call happens and the context is switched i
    4 min read
    Solidity - Inheritance
    Inheritance is one of the most important features of the object-oriented programming language. It is a way of extending the functionality of a program, used to separate the code, reduces the dependency, and increases the re-usability of the existing code. Solidity supports inheritance between smart
    6 min read
    Solidity - Constructors
    A constructor is a special method in any object-oriented programming language which gets called whenever an object of a class is initialized. It is totally different in case of Solidity, Solidity provides a constructor declaration inside the smart contract and it invokes only once when the contract
    4 min read
    Solidity - Abstract Contract
    Abstract contracts are contracts that have at least one function without its implementation or in the case when you don't provide arguments for all of the base contract constructors. Also in the case when we don't intend to create a contract directly we can consider the contract to be abstract. An i
    3 min read
    Solidity - Basics of Interface
    Interfaces are the same as abstract contracts created by using an interface keyword, also known as a pure abstract contract. Interfaces do not have any definition or any state variables, constructors, or any function with implementation, they only contain function declarations i.e. functions in inte
    2 min read
    Solidity - Libraries
    Libraries in solidity are similar to contracts that contain reusable codes. A library has functions that can be called by other contracts. Deploying a common code by creating a library reduces the gas cost. Functions of the library can be called directly when they do not modify the state variables i
    4 min read
    Solidity - Assembly
    Assembly or Assembler language indicates a low-level programming language that can be converted to machine code by using assembler. Assembly language is tied to either physical or a virtual machine as their implementation is an instruction set, and these instructions tell the CPU to do that fundamen
    4 min read
    What are Events in Solidity?
    Solidity Events are the same as events in any other programming language. An event is an inheritable member of the contract, which stores the arguments passed in the transaction logs when emitted. Generally, events are used to inform the calling application about the current state of the contract, w
    2 min read
    Solidity - Error Handling
    Solidity has many functions for error handling. Errors can occur at compile time or runtime. Solidity is compiled to byte code and there a syntax error check happens at compile-time, while runtime errors are difficult to catch and occurs mainly while executing the contracts. Some of the runtime erro
    6 min read
    Top 50 Solidity Interview Questions and Answers
    Solidity is an object-oriented programming language used to implement smart contracts on blockchain platforms like Ethereum, which generates transaction records in the system. To excel in your journey toward top companies as a Solidity developer, you need to master some important Solidity Interview
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences