Functions

Function Structure

  • public -> visibility declaration

  • view -> Indicates function behavior

  • returns -> Data type that the function returns (optional)

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

Simply put:

public -> functions can be called both internally and externally

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

Cannot create a function with the same name as a storage variable. Will conflict with getter function.

Last updated