Function Visibility Specifier
public
: 외부에서 함수에 직접 접근할 수 있다. ABI의 일부가 되며, 내부적으로든 외부적으로든 호출할 수 있다.
internal
: 상태 변수는 기본적으로 internal
한정자를 갖는다. 이 함수는 현재 컨트랙트 및 그것을 상속한 컨트랙트에서만 사용할 수 있음을 의미한다. 외부에서는 이러한 함수들에 접근할 수 없으므로 컨트랙트 ABI에 속하지 않는다.
private
: 이 함수를 선언한 컨트랙트에서만 사용할 수 있다. 파생 컨트랙트에서도 사용할 수 없으며 컨트랙트 ABI에 속하지 않는다.
external
: 외부에서 직접적으로 접근할 수 있지만, 내부에서는 접근할 수 없다. 이러한 함수는 컨트랙트 ABI로 사용된다.
Function State Mutability
constant
: 이 함수는 블록체인의 상태를 수정할 수 없다. 상태 변수를 읽고 호출자에게 반환하는 일은 할 수 있지만, 변수를 수정하거나 이벤트를 호출하거나 다른 컨트랙트를 생성하거나 상태를 변경하는 다른 함수를 호출하는 일을 하지 못한다. constant
함수는 현재 상태 변수를 읽고 반환할 수 있는 함수라고 생각하면 된다.
view
: view
함수는 constant
함수의 별칭이다.
pure
: pure
함수는 함수의 능력에 제약이 더 많다. pure
함수는 읽고 쓰지 못한다. 즉, 상태 변수에 접근할 수 없다. 어떤 함수가 현재 상태와 거래 변수에 접근할 수 없게 하려면 pure
함수로 선언하면 된다.
payable
: 함수에 payable
키워드가 붙으면 호출자로부터 이더를 받을 수 있다. 송금자가 이더를 제공하지 않으면 호출이 실패한다. 함수가 payable로 표시되면 이더만 받을 수 있다.