# Solidity File Structure

## Structure of a Solidity file

### SPDX License Identifier

All solidity contracts should have License declaration in the first line.

```solidity
// SPDX-License-Identifier: MIT
```

List of licenses from SPDX repository: <https://spdx.org/licenses/>

### Pragmas

`pragma` is the keyword used to declare the compiler version of Solidity. `pragma` only applies to the current local file so you must add `pragma` to all files in the project directory.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
```

You can use the `^` sign or the comparison operators `<`, `<=`, `>`, `>=` in conjunction with the compiler declaration.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20; // use compiler version 0.8.20 and above
```

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0; // use compiler version bigger or equal to 0.4.22 and less than 0.9.0
```

### Import file from other sources

#### Import the whole file

```solidity
import "FileName"
```

#### Import all and assign alias

```solidity
import * as symbolName from "FileName";
```

#### Name import

`Name import` means you will specify the name of the import object from another file. The reason you should use this option is that it makes your code clearer.

```solidity
import {ContractOne as alias, ContractTwo} from "FileName";
```

### Comment

To comment, you can use `//` and `/* */`

```solidity
// comment for 1 line.

/*
Comment for
multiple lines
*/
```

There is also [NatSpec](https://docs.soliditylang.org/en/v0.8.24/natspec-format.html#natspec) comment with `///` or `/** **/`

```solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;

/// @author The Project Team
/// @title A simple storage example
contract SimpleStorage {
    uint storedData;

    /// Store `x`.
    /// @param x the new value to store
    /// @dev stores the number in the state variable `storedData`
    function set(uint x) public {
        storedData = x;
    }

    /// Return the stored value.
    /// @dev retrieves the value of the state variable `storedData`
    /// @return the stored value
    function get() public view returns (uint) {
        return storedData;
    }
}
```


---

# Agent Instructions: 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:

```
GET https://bootcamp.openguild.wtf/smart-contract-development/introduction/solidity-file-structure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
