> For the complete documentation index, see [llms.txt](https://solstep.gitbook.io/solidity-steps/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://solstep.gitbook.io/solidity-steps/step-4/31-abstract-contract.md).

# 31: Abstract Contract

An abstract contract is a special contract type in Solidity that provides a base contract from which other contracts can be derived. The purpose of an abstract contract is to provide various common and reusable pieces of code that can be used to create new contracts. This makes it easier for developers to create contracts that are more efficient and secure.

* **Example 1**: A Simple Abstract Contract Below is an example of a simple abstract contract that contains a `greet()` function. This function can be used as a base for other contracts to build upon.

```solidity
contract Abstract {  
  function greet() public virtual {    // Do something here  }
}
```

* **Example 2**: An Abstract Contract with a State Variable Below is an example of an abstract contract with a state variable. The balance state variable can be used as a base in other contracts.

```solidity
contract Abstract {  
  uint256 public balance;  
  function greet() public virtual {    // Do something here  }
}
```

* **Example 3**: An Abstract Contract with a Getter Function Below is an example of an abstract contract with a getter function. The getBalance() function can be used as a base in other contracts.

```solidity
contract Abstract { // abstract can be like an interface
  uint256 public balance;  
  function greet() public virtual;
  function getBalance() public view returns (uint256);
}

contract A is Abstract {  
  uint256 public balance;  
  function greet() public virtual {    // Do something here  } 
  function getBalance() public view returns (uint256) {    
    return balance;  
  }
}
```

*That's it for the lesson 31! In the next lesson, Payable*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://solstep.gitbook.io/solidity-steps/step-4/31-abstract-contract.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
