# Functions

**Function Structure**

![Example](/files/APKskEcBIZgkljskKIbw)

* `public` -> visibility declaration&#x20;
* `view` -> Indicates function behavior
* `returns` -> type of variable being returned

```solidity
 // updates message variable. cannot return.
    function setMessage(string newMessage) public {
        message = newMessage;
    }
    
 // synthax will clear. looks correct. but wont work.
    function setMessage(string newMessage) public returns (string){
        message = newMessage;
        return message;
    }    
```

{% hint style="danger" %}
You cannot create a function with the same name as a storage variable. Will conflict with getter function.
{% endhint %}

{% hint style="info" %}
**There are 2 types of functions that you can create in Solidity:**

1. Functions that create transaction on block chain
2. Functions that do not create transaction on block chain (view and pure)

*For more details see: Running Functions page*
{% endhint %}


---

# 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://calnix.gitbook.io/eth-dev/compendium/solidity-basics/functions.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.
