> For the complete documentation index, see [llms.txt](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/basics/2./undefined/undefined-1.md).

# 함수의 기본 구조

솔리디티에서 함수(function)은 컨트랙트의 동작을 정의하는 핵심 단위이다.

함수를 통해 외부에서 데이터를 읽거나, 내부 상태를 변경하거나, 이더를 송금하는 등의 다양한 작업을 수행한다. 기본 구조는 아래와 같이 구성된다.&#x20;

```solidity
function 매개변수 [접근제어자] [함수제어자] [returns (반환 타입)]{
    // 함수 실행 내용
}
```

* `function`: 함수 정의 키워드
* 매개변수 : `uint`, `address`등 자료형 + 변수명
* 접근제어자 : `public, private, intenal, external`
* 함수제어자 : `view, pure, payable` 등
* `returns` : 리턴값이 있을 경우 반환 타입(자료형) 명시

이제 함수의 기본 구조를 알았으니, 직접 선언해보고 호출해보자.&#x20;

참고 문서 : [솔리디티 공식 문서 - functions](https://docs.soliditylang.org/en/latest/contracts.html#functions)
