# Functions

## **Function Structure**

![Example](https://1628544884-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTgomzlmn9NrxUY0OQ3cD%2Fuploads%2FLYnBKgAz0CS9tNNKvFiC%2Fimage.png?alt=media\&token=b263a26b-8787-4e4d-94c8-b57d602da604)

* `public` -> visibility declaration&#x20;
* `view` -> Indicates function behavior
* `returns` -> Data type that the function returns (optional)

```solidity
function functionName(parameter1, parameter2) {public|private|internal|external} 
[pure|view|payable] [(modifiers)] [returns (<return types>)]
```

## Function Visibility

#### A function declarations only impose scope and do nothing for security

![](https://1628544884-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTgomzlmn9NrxUY0OQ3cD%2Fuploads%2FopxHCmJSOgXNk10BlsSi%2Fimage.png?alt=media\&token=3431c32e-7647-410b-aacd-876a87ffb117)

### Simply put:

**public ->** functions can be called both internally and externally&#x20;

**external ->** only external calls; cannot be accessed internally

**internal ->** only this contract and contracts deriving from it can access

**private ->** functions can only be called from within the contract

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