Network
Launch Date
Consensus
Note
Sepolia
Oct 2021
PoW
Like-for-like representation of Ethereum
Görli
Jan 2019
PoA
Proof-of-Authority
Kiln
Mar 2022
PoS
Post-Merge (for ETH2), shadow fork of the mainnet
Kintsugi
Dec 2021
PoS
DEPRECATED, use Kiln; post-Merge (for ETH2)
Ropsten
Nov 2016
PoW
DEPRECATED, use Sepolia; the Merge to happen on Jun 8, 2022
Rinkeby
Apr 2017
PoA
DEPRECATED, use Görli and Görli Faucet
Kovan
Mar 2017
PoA
DEPRECATED, use Sepolia or Görli
List of active and deprecated Ethereum testnets, including Kintsugi.
Features
Optimistic rollup 
ZK-rollup 
Proof
Uses fraud proofs to prove transaction validity. 
Uses validity (zero-knowledge) proofs to prove transaction validity. 
Capital efficiency
Requires waiting through a 1-week delay (dispute period) before withdrawing funds. 
Users can withdraw funds immediately because validity proofs provide incontrovertible evidence of the authenticity of off-chain transactions. 
Data compression
Publishes full transaction data as calldata to Ethereum Mainnet, which increases rollup costs. 
Doesn't need to publish transaction data on Ethereum because ZK-SNARKs and ZK-STARKs already guarantee the accuracy of the rollup state. 
EVM compatibility
Uses a simulation of the Ethereum Virtual Machine (EVM), which allows it to run arbitrary logic and support smart contracts. 
Doesn't widely support EVM computation, although a few EVM-compatible ZK-rollups have appeared. 
Rollup costs
Reduces costs since it publishes minimal data on Ethereum and doesn't have to post proofs for transactions, except in special circumstances. 
Faces higher overhead from costs involved in generating and verifying proofs for every transaction block. ZK proofs require specialized, expensive hardware to create and have high on-chain verification costs. 
Trust assumptions
Doesn't require a trusted setup. 
Requires a trusted setup to work. 
Liveness requirements
Verifiers are needed to keep tabs on the actual rollup state and the one referenced in the state root to detect fraud. 
Users don't need someone to watch the L2 chain to detect fraud. 
Security properties 
Relies on cryptoeconomic incentives to assure users of rollup security. 
Relies on cryptographic guarantees for security. 
Start building
on Alchemy.
Sign up for free
Start building on Optimism.
Sign up for free
Start building on Arbitrum.
Sign up for free
Start building on Ethereum.
Sign up for free
Start building on Polygon.
Sign up for free
Start building on Starknet.
Sign up for free
Start building on Flow.
Sign up for free
kiln faucet
Get free Kiln ETH.
Start building today
Goerli faucet
Get free Goerli ETH.
Start building today
mumbai faucet
Get free Mumbai Matic.
Start building today
rinkeby faucet
Get free Rinkeby
ETH.
Start building today
Start building on Ethereum.
Get started for free
Start building on Ethereum.
Get started for free
Start building on Flow.
Get started for free
Start building on Polygon.
Get started for free
Start building on Starknet.
Get started for free
Start building on Optimism.
Get started for free
Start building on Solana.
Get started for free
Start building on Solana.
Sign up for beta access
Start building on Solana.
Join the waitlist
Arbitrum logo
Start building on Arbitrum.
Get started for free
Learn
Solidity at
Alchemy
University
Get started today
curl 
https://release.solana.com/v1.10.32/solana-install-init-x86_64-pc-windows-msvc.exe 
--output 
C:\solana-install-tmp\solana-install-init.exe 
--create-dirs
Learn Solidity
SOLIDITY FUNCTION OVERVIEW

What are Solidity functions?

Solidity Function Types: View, Pure, Special, Fallback, and Function Visibility
Last Updated:
October 4, 2022
Table of Contents
Table of Contents
Table of Contents

{{learn-solidity}}

There are multiple types of Solidity functions including view functions, pure functions, special functions, and fallback functions. Functions also can be modified with a function visibility attribute of public, external, internal, and private. This article will introduce Solidity function types, syntax, how to read functions and visibility.

What are Solidity functions?

Solidity functions are self-contained modules of code that accomplish a specific task. Like other web3 programming languages, Solidity allows the developer to write modular code by using functions to eliminate the redundancy of rewriting the same piece of code. Instead, devs can call a function in the program when it’s necessary. 

How to Write and Read a Solidity Function

To write a Solidity function, developers need to structure it according to its proper syntax, and making sure to write its basic components to ensure the function can execute correctly. 

Solidity Function Syntax

Use the following syntax to create your Solidity function, as seen in the example below:

  1. Define the function with the function keyword
  2. Create a name for the function, which is unique and does not coincide with any of the reserved keywords
  3. List any parameters containing the name and data type of the parameter or include no extra parameters
  4. Create a statement block surrounded by curly brackets


function function-name(parameter-list) scope returns() {   
		// statements
}

Note: Solidity events are declared like functions. Events and functions are both integral to high-level dApp work.

The image below shows the three main components of a Solidity function:

  1. Function name
  2. Function type
  3. Return types
An example of a function in Solidity.

What are the different types of Solidity functions?

There are various types of Solidity functions we’ll be covering in this section including view functions, pure functions, special functions, and fallback functions.

1. View Functions

In Solidity, view functions are read-only and cannot alter the state variables defined in a smart contract. The syntax for a view function is as follows:



function <function-name>() <access-modifier> view returns() {  
		// function body
}

2. Pure Functions

A pure function declares that no state variable will be changed or read. Typically pure functions serve some common utility or calculation. The syntax for a pure function is as follows:



function <function-name>() <access-modifier> pure returns() {  
		// function body
}

3. Special Functions

Solidity has a couple of special functions that you can use when developing a smart contract. Getter and receive functions are important payable functions for smart contracts in Solidity.

Getter Function

State variables defined as public have a getter function that is automatically created by the compiler. The function has the same name as the variable and has external visibility.

Receive Ether Function

A contract can have at most one receive function. A receive function cannot have arguments, is unable to return, and must have external visibility and payable state mutability.

A receive function is executed on a call to the contract that sends Ether and does not specify any function. This function is declared as follows:



receive() external payable {
		...
}

4. Fallback Function

In Solidity, a fallback function is an external function without a name, arguments, or return values. Fallback functions are executed when a function identifier doesn't match any of the available functions in a smart contract, or if there was no data supplied along with the function call.

What is function overloading?

Function overloading occurs when you have multiple definitions for the same function name within the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.

How does Vyper handle function overloading differently from Solidity?

Unlike Solidity, Vyper, a pythonic language based on Solidity, does not allow for function overloading. Attempting function overloading in Vyper will result in a ‚ÄúDuplicate function or event name‚ÄĚ error.¬†

What does function visibility mean?

Specifying function visibility allows us to control which entities can call functions within the smart contract. There are three types of callers: 

  1. The main contract 
  2. A contract derived (i.e. inheriting) from the main contract 
  3. A third party

Function visibility helps you control which of the above callers can execute the function. There are four types of function visibility: 

  1. Public 
  2. External
  3. Internal
  4. Private

The accessibility of the functions decreases from External to Private: public functions are the most accessible and private functions are the least.

External vs. Public 

External and public are the two function visibilities that can be called from outside of the contract they are defined within. External means that the function can exclusively be called by other contracts or Externally Owned Accounts (EOA). Public means that the function can be called externally or from within the contract itself.

Internal vs. Private

As opposed to external and public, internal and private both disallow external parties from accessing the function. For a private function, only functions within the same contract can call it. For an internal function, functions within the same contract or functions within derived contracts can call it.

Keep Learning About Solidity Functions

This article has introduced you to functions in Solidity. To keep learning, sign up for Alchemy University's Ethereum Developer Bootcamp, to gain access to a free, 7-week asynchronous Solidity crash course taught be the experts at ChainShot. If developers are new to development in general, Alchemy University's 3-week JavaScript crash course is a great prerequisite before starting an Ethereum bootcamp.

ALCHEMY SUPERNODE - ETHEREUM NODE API

Scale to any size, without any errors

Alchemy Supernode finally makes it possible to scale blockchain applications without all the headaches. Plus, our legendary support will guide you every step of the way.

Get started for free
Supernode footer
Learn Solidity
SOLIDITY FUNCTION OVERVIEW

Learn Solidity: What are functions?

Solidity Function Types: View, Pure, Special, Fallback, and Function Visibility
Last Updated:
October 4, 2022
Don't miss an update
Sign up for our newsletter to get alpha, key insights, and killer resources.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Table of Contents

There are multiple types of Solidity functions including view functions, pure functions, special functions, and fallback functions. Functions also can be modified with a function visibility attribute of public, external, internal, and private. This article will introduce Solidity function types, syntax, how to read functions and visibility.

What are Solidity functions?

Solidity functions are self-contained modules of code that accomplish a specific task. Like other web3 programming languages, Solidity allows the developer to write modular code by using functions to eliminate the redundancy of rewriting the same piece of code. Instead, devs can call a function in the program when it’s necessary. 

How to Write and Read a Solidity Function

To write a Solidity function, developers need to structure it according to its proper syntax, and making sure to write its basic components to ensure the function can execute correctly. 

Solidity Function Syntax

Use the following syntax to create your Solidity function, as seen in the example below:

  1. Define the function with the function keyword
  2. Create a name for the function, which is unique and does not coincide with any of the reserved keywords
  3. List any parameters containing the name and data type of the parameter or include no extra parameters
  4. Create a statement block surrounded by curly brackets


function function-name(parameter-list) scope returns() {   
		// statements
}

Note: Solidity events are declared like functions. Events and functions are both integral to high-level dApp work.

The image below shows the three main components of a Solidity function:

  1. Function name
  2. Function type
  3. Return types
An example of a function in Solidity.

What are the different types of Solidity functions?

There are various types of Solidity functions we’ll be covering in this section including view functions, pure functions, special functions, and fallback functions.

1. View Functions

In Solidity, view functions are read-only and cannot alter the state variables defined in a smart contract. The syntax for a view function is as follows:



function <function-name>() <access-modifier> view returns() {  
		// function body
}

2. Pure Functions

A pure function declares that no state variable will be changed or read. Typically pure functions serve some common utility or calculation. The syntax for a pure function is as follows:



function <function-name>() <access-modifier> pure returns() {  
		// function body
}

3. Special Functions

Solidity has a couple of special functions that you can use when developing a smart contract. Getter and receive functions are important payable functions for smart contracts in Solidity.

Getter Function

State variables defined as public have a getter function that is automatically created by the compiler. The function has the same name as the variable and has external visibility.

Receive Ether Function

A contract can have at most one receive function. A receive function cannot have arguments, is unable to return, and must have external visibility and payable state mutability.

A receive function is executed on a call to the contract that sends Ether and does not specify any function. This function is declared as follows:



receive() external payable {
		...
}

4. Fallback Function

In Solidity, a fallback function is an external function without a name, arguments, or return values. Fallback functions are executed when a function identifier doesn't match any of the available functions in a smart contract, or if there was no data supplied along with the function call.

What is function overloading?

Function overloading occurs when you have multiple definitions for the same function name within the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.

How does Vyper handle function overloading differently from Solidity?

Unlike Solidity, Vyper, a pythonic language based on Solidity, does not allow for function overloading. Attempting function overloading in Vyper will result in a ‚ÄúDuplicate function or event name‚ÄĚ error.¬†

What does function visibility mean?

Specifying function visibility allows us to control which entities can call functions within the smart contract. There are three types of callers: 

  1. The main contract 
  2. A contract derived (i.e. inheriting) from the main contract 
  3. A third party

Function visibility helps you control which of the above callers can execute the function. There are four types of function visibility: 

  1. Public 
  2. External
  3. Internal
  4. Private

The accessibility of the functions decreases from External to Private: public functions are the most accessible and private functions are the least.

External vs. Public 

External and public are the two function visibilities that can be called from outside of the contract they are defined within. External means that the function can exclusively be called by other contracts or Externally Owned Accounts (EOA). Public means that the function can be called externally or from within the contract itself.

Internal vs. Private

As opposed to external and public, internal and private both disallow external parties from accessing the function. For a private function, only functions within the same contract can call it. For an internal function, functions within the same contract or functions within derived contracts can call it.

Keep Learning About Solidity Functions

This article has introduced you to functions in Solidity. To keep learning, sign up for Alchemy University's Ethereum Developer Bootcamp, to gain access to a free, 7-week asynchronous Solidity crash course taught be the experts at ChainShot. If developers are new to development in general, Alchemy University's 3-week JavaScript crash course is a great prerequisite before starting an Ethereum bootcamp.

There are multiple types of Solidity functions including view functions, pure functions, special functions, and fallback functions. Functions also can be modified with a function visibility attribute of public, external, internal, and private. This article will introduce Solidity function types, syntax, how to read functions and visibility.

What are Solidity functions?

Solidity functions are self-contained modules of code that accomplish a specific task. Like other web3 programming languages, Solidity allows the developer to write modular code by using functions to eliminate the redundancy of rewriting the same piece of code. Instead, devs can call a function in the program when it’s necessary. 

How to Write and Read a Solidity Function

To write a Solidity function, developers need to structure it according to its proper syntax, and making sure to write its basic components to ensure the function can execute correctly. 

Solidity Function Syntax

Use the following syntax to create your Solidity function, as seen in the example below:

  1. Define the function with the function keyword
  2. Create a name for the function, which is unique and does not coincide with any of the reserved keywords
  3. List any parameters containing the name and data type of the parameter or include no extra parameters
  4. Create a statement block surrounded by curly brackets


function function-name(parameter-list) scope returns() {   
		// statements
}

Note: Solidity events are declared like functions. Events and functions are both integral to high-level dApp work.

The image below shows the three main components of a Solidity function:

  1. Function name
  2. Function type
  3. Return types
An example of a function in Solidity.

What are the different types of Solidity functions?

There are various types of Solidity functions we’ll be covering in this section including view functions, pure functions, special functions, and fallback functions.

1. View Functions

In Solidity, view functions are read-only and cannot alter the state variables defined in a smart contract. The syntax for a view function is as follows:



function <function-name>() <access-modifier> view returns() {  
		// function body
}

2. Pure Functions

A pure function declares that no state variable will be changed or read. Typically pure functions serve some common utility or calculation. The syntax for a pure function is as follows:



function <function-name>() <access-modifier> pure returns() {  
		// function body
}

3. Special Functions

Solidity has a couple of special functions that you can use when developing a smart contract. Getter and receive functions are important payable functions for smart contracts in Solidity.

Getter Function

State variables defined as public have a getter function that is automatically created by the compiler. The function has the same name as the variable and has external visibility.

Receive Ether Function

A contract can have at most one receive function. A receive function cannot have arguments, is unable to return, and must have external visibility and payable state mutability.

A receive function is executed on a call to the contract that sends Ether and does not specify any function. This function is declared as follows:



receive() external payable {
		...
}

4. Fallback Function

In Solidity, a fallback function is an external function without a name, arguments, or return values. Fallback functions are executed when a function identifier doesn't match any of the available functions in a smart contract, or if there was no data supplied along with the function call.

What is function overloading?

Function overloading occurs when you have multiple definitions for the same function name within the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.

How does Vyper handle function overloading differently from Solidity?

Unlike Solidity, Vyper, a pythonic language based on Solidity, does not allow for function overloading. Attempting function overloading in Vyper will result in a ‚ÄúDuplicate function or event name‚ÄĚ error.¬†

What does function visibility mean?

Specifying function visibility allows us to control which entities can call functions within the smart contract. There are three types of callers: 

  1. The main contract 
  2. A contract derived (i.e. inheriting) from the main contract 
  3. A third party

Function visibility helps you control which of the above callers can execute the function. There are four types of function visibility: 

  1. Public 
  2. External
  3. Internal
  4. Private

The accessibility of the functions decreases from External to Private: public functions are the most accessible and private functions are the least.

External vs. Public 

External and public are the two function visibilities that can be called from outside of the contract they are defined within. External means that the function can exclusively be called by other contracts or Externally Owned Accounts (EOA). Public means that the function can be called externally or from within the contract itself.

Internal vs. Private

As opposed to external and public, internal and private both disallow external parties from accessing the function. For a private function, only functions within the same contract can call it. For an internal function, functions within the same contract or functions within derived contracts can call it.

Keep Learning About Solidity Functions

This article has introduced you to functions in Solidity. To keep learning, sign up for Alchemy University's Ethereum Developer Bootcamp, to gain access to a free, 7-week asynchronous Solidity crash course taught be the experts at ChainShot. If developers are new to development in general, Alchemy University's 3-week JavaScript crash course is a great prerequisite before starting an Ethereum bootcamp.

Build web3 with Alchemy

Alchemy combines the most powerful web3 developer products and tools with resources, community and legendary support.

Get started for free