> For the complete documentation index, see [llms.txt](https://learn.fi-code.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.fi-code.com/overview/contract-structure.md).

# Contract Definitions

The basic structure of a smart contract written is fi is fairly simple, and takes a similar approach to other object-oriented languages. The core definitions include Constants, Storage Variables, Structs and Contract Entry Points.

Furthermore, we are also working on additional definitions for internal functions and response functions (for contract to contract communication via a promise-like system).

## Constants

Constants can be defined and reused throughout your code like any other global constant. Constants can only be defined as [basic types.](/overview/types.md)

**const \<type\*>  \<constant name> \<literal value>;**

```
const int ONEHOUR 3600;
```

## Storage Variables

Storage variables are permanently stored within the block chain and represent the state of the contract. Storage variables can be of any type (basic and complex, as well as custom types defined as structs).

These variables must be defined, and can be accessed via the storage object:

**storage \<type|struct> \<variable name>;**

Which can then be accessed via the storage object:

**storage.\<variable name>**

```javascript
storage int counter; 
#Storage variable named counter, accessed via storage.counter

entry increaseCounter(){
    storage.counter.add(int 1);
}
```

## Structs

Structs allow you to define more complex custom types to be used within fi. Once a struct has been declared, it can be used as a variable type.

**struct \<struct name>(\<typed variables>)**

Where typed variables is a list of arguments defining the type and name of each variable:

**\<type|struct> \<variable name>, ...**

You can declare a new instance of type object using the new keyword, followed by the object name.

```
struct Person(
    string name,
    int age,
    string favouriteFood
);

storage Person me;

entry add(string name, int age, string food){
    storage.me = new Person(input.name, input.age, input.food);
}
```

Struct variables can be accessed using a fullstop/dot - this can traverse recursively:

```
entry changeName(string name){
    storage.me.name = input.name;
}
```

## Entry Points

Entry Points define the public calls that can be made to a smart contract written in fi. A smart contract can contain multiple entry points, each of which needs to be declared using the entry keyword followed by a name and optional input variables within a set of parenthesis. \
\
**Input variables**\
Input variables are a list of typed variables, similar to declaring a struct. This declaration can be blank, i.e. () .

**\<type|struct> \<variable name>, ...**

Input variables can then be accessed via the input variable:

**input.\<variable name>**

**\*Note: At least one entry point must be defined for a contract to compile correctly.**

```
entry add(string name, int age, string food){
    storage.me = new Person(input.name, input.age, input.food);
}
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learn.fi-code.com/overview/contract-structure.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
