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
SEPOLIA FAUCET
Get free Sepolia 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
Build with Alchemy's
Gas Manager & Bundler APIs
Learn
Solidity at
Alchemy
University
Get started today
Build with Alchemy's
Gas Manager & Bundler APIs
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
ERROR HANDLING OVERVIEW

Solidity Error Handling Overview: What is require?

Explore the Uses and Differences Between Require, Revert, and Assert
Last Updated:
October 4, 2022
Table of Contents
Table of Contents
Table of Contents

{{learn-solidity}}

‚ÄćHow does error handling work in Solidity?¬†

Solidity uses state-reverting exceptions to handle errors, and such an exception will undo all changes made to the state in the current call and simultaneously flag an error to the caller. ‚Äć

Solidity, an object-oriented programming language to implement smart contracts on blockchains such as Ethereum, has numerous functions to address underlying issues that can occur at compile time or runtime. Even though syntax error checks happen at compile time, runtime errors are difficult to catch and mainly happen during the contract execution process. Some runtime error examples include a divide-by-zero type error, array-out-of-index error, and so on. 

In effect, error handling in Solidity ensures atomicity as a property. When a smart contract call terminates with an error, all the state changes (i.e., alterations made to variables, balances, etc.) are reverted, all the way up the chain of contract calls.

It is important to note that developers can directly interact with other contracts by declaring an interface. On the Ethereum blockchain, transactions are atomic, implying that transactions are either fully complete or have no effect on state and are reverted entirely. 

What are the three main Solidity error handling functions?

Error handling in Solidity is managed in principle by three special functions: assert, require, and revert. Until version 0.4.10, a single throw statement was available in Solidity.

Solidity has been designed to target the Ethereum Virtual Machine (EVM) and is influenced by C++, Javascript, and Python. Using Solidity, developers can create contracts for uses such as voting, crowdfunding, multi-signature wallets, and even blind auctions.

In practice, this means that a developer had to write several test functions in order to check underlying values and throw errors, which is not optimized for gas. In the release of Solidity version 0.4.10, new error handling constructs, asset, require, and revert, were introduced and the throw was made obsolete.

What is the require function?

The require function is used to verify inputs and conditions before execution. For instance, if the condition is false, then the require function immediately stops execution. In other words, require acts as a gate check modifier, preventing logic from accessing further execution of function and thereby producing an error. Require is ideal for logic flow gating and validating user inputs on functions.  

Require statements declare prerequisites for running the function, which should be satisfied prior to code execution. The require function accepts a single argument and after evaluation, require returns a boolean value of true or false. In the event that the execution is terminated due to a false condition, the unused gas is returned to the caller and the state is reversed to the original state. Customer string messages can also be added.

Here is an example of a require statement in Solidity:

The basic example demonstrates how to use the require statement. 

Require Statement Use Cases

For pragmatic reasons, developers could use require for the following scenarios:

  1. Validating responses from an external contract 
  2. Verify state conditions before final execution
  3. Authenticate user inputs 

What is the revert statement? 

‚ÄćRevert does not evaluate any condition and does not depend on any state or statement. The revert statement is similar to the require statement in that the revert function can handle the same error types as the require function, but it is more appropriate for complex logic gates.

If a revert statement is called, the unused gas is returned and the state reverts to its original state. The ability to add a custom message is the same as the require function. 

Here is an example of a revert statement in Solidity:

This basic example demonstrates a revert statement's custom message. 

What is the assert function? 

Assert is a function that is used to check for code that should never be false, and plays an important role in preventing impossible scenarios. If the assert function returns a boolean value of true, then a terminal bug will be displayed and the programs will not execute.

In contrast to the require and revert functions, assert does not return any unused gas and instead, the assert function will consume the gas supply before proceeding to reverse the program to its original state. Interestingly, prior to the Byzantium fork, both the require and assert functions behaved in an identical manner, however, compiled to distinct opcodes.

Assert Type Exceptions

  1. A value is modulo or divided by zero
  2. A zero-initialized variable of a function is called 
  3. A negative or large value is converted to an enum 
  4. Accessing an array within an index that is negative or larger than expected 
Assert statement example.

Assert Statement Use Cases

In theory, assert should be used less frequently compared to the require function. Developers should consider using the assert function for the following use cases: 

  • Validating the contract state after making changes¬†
  • Avoiding conditions which should never be possible¬†
  • Checking for overflow and underflow parameters¬†
  • Examining invariants

Require vs. Revert vs. Assert

Here is a summary that provides a succinct description of all all three Solidity error handling functions: require, revert, and assert.

Require

  • Used at the beginning of a function¬†
  • Validates against illegal input¬†
  • Verifies state conditions prior to execution
  • Refunds leftover gas¬†

Revert

  • Identical to require¬†
  • Useful for more complex logic flow gates (i.e., complicated if-then blocks)¬†
  • Refunds leftover gas

Assert

  • Used at the end of a function
  • Validates something that is impossible¬†
  • Critical for static code analysis tools¬†
  • Does not refund leftover gas

How to Learn More About Require and Solidity Error Handling

Developers interested in learning more about Solidity error handling should sign up for Alchemy University's free Solidity developer crash course. This FREE, 7-week bootcamp helps web2 developers and brand new coders learn how to write Solidity smart contracts. 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
ERROR HANDLING OVERVIEW

Solidity Error Handling Overview: What is require?

Explore the Uses and Differences Between Require, Revert, and Assert
Last Updated:
October 4, 2022
Last Updated:
March 14, 2023
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

Talk to an Expert

Learn how Alchemy's blockchain developer tools can help your business succeed in web3!
Valid number
Thank you! An Alchemy expert will be in touch with you shortly!
Oops! Something went wrong while submitting the form.

{{learn-solidity}}

‚ÄćHow does error handling work in Solidity?¬†

Solidity uses state-reverting exceptions to handle errors, and such an exception will undo all changes made to the state in the current call and simultaneously flag an error to the caller. ‚Äć

Solidity, an object-oriented programming language to implement smart contracts on blockchains such as Ethereum, has numerous functions to address underlying issues that can occur at compile time or runtime. Even though syntax error checks happen at compile time, runtime errors are difficult to catch and mainly happen during the contract execution process. Some runtime error examples include a divide-by-zero type error, array-out-of-index error, and so on. 

In effect, error handling in Solidity ensures atomicity as a property. When a smart contract call terminates with an error, all the state changes (i.e., alterations made to variables, balances, etc.) are reverted, all the way up the chain of contract calls.

It is important to note that developers can directly interact with other contracts by declaring an interface. On the Ethereum blockchain, transactions are atomic, implying that transactions are either fully complete or have no effect on state and are reverted entirely. 

What are the three main Solidity error handling functions?

Error handling in Solidity is managed in principle by three special functions: assert, require, and revert. Until version 0.4.10, a single throw statement was available in Solidity.

Solidity has been designed to target the Ethereum Virtual Machine (EVM) and is influenced by C++, Javascript, and Python. Using Solidity, developers can create contracts for uses such as voting, crowdfunding, multi-signature wallets, and even blind auctions.

In practice, this means that a developer had to write several test functions in order to check underlying values and throw errors, which is not optimized for gas. In the release of Solidity version 0.4.10, new error handling constructs, asset, require, and revert, were introduced and the throw was made obsolete.

What is the require function?

The require function is used to verify inputs and conditions before execution. For instance, if the condition is false, then the require function immediately stops execution. In other words, require acts as a gate check modifier, preventing logic from accessing further execution of function and thereby producing an error. Require is ideal for logic flow gating and validating user inputs on functions.  

Require statements declare prerequisites for running the function, which should be satisfied prior to code execution. The require function accepts a single argument and after evaluation, require returns a boolean value of true or false. In the event that the execution is terminated due to a false condition, the unused gas is returned to the caller and the state is reversed to the original state. Customer string messages can also be added.

Here is an example of a require statement in Solidity:

The basic example demonstrates how to use the require statement. 

Require Statement Use Cases

For pragmatic reasons, developers could use require for the following scenarios:

  1. Validating responses from an external contract 
  2. Verify state conditions before final execution
  3. Authenticate user inputs 

What is the revert statement? 

‚ÄćRevert does not evaluate any condition and does not depend on any state or statement. The revert statement is similar to the require statement in that the revert function can handle the same error types as the require function, but it is more appropriate for complex logic gates.

If a revert statement is called, the unused gas is returned and the state reverts to its original state. The ability to add a custom message is the same as the require function. 

Here is an example of a revert statement in Solidity:

This basic example demonstrates a revert statement's custom message. 

What is the assert function? 

Assert is a function that is used to check for code that should never be false, and plays an important role in preventing impossible scenarios. If the assert function returns a boolean value of true, then a terminal bug will be displayed and the programs will not execute.

In contrast to the require and revert functions, assert does not return any unused gas and instead, the assert function will consume the gas supply before proceeding to reverse the program to its original state. Interestingly, prior to the Byzantium fork, both the require and assert functions behaved in an identical manner, however, compiled to distinct opcodes.

Assert Type Exceptions

  1. A value is modulo or divided by zero
  2. A zero-initialized variable of a function is called 
  3. A negative or large value is converted to an enum 
  4. Accessing an array within an index that is negative or larger than expected 
Assert statement example.

Assert Statement Use Cases

In theory, assert should be used less frequently compared to the require function. Developers should consider using the assert function for the following use cases: 

  • Validating the contract state after making changes¬†
  • Avoiding conditions which should never be possible¬†
  • Checking for overflow and underflow parameters¬†
  • Examining invariants

Require vs. Revert vs. Assert

Here is a summary that provides a succinct description of all all three Solidity error handling functions: require, revert, and assert.

Require

  • Used at the beginning of a function¬†
  • Validates against illegal input¬†
  • Verifies state conditions prior to execution
  • Refunds leftover gas¬†

Revert

  • Identical to require¬†
  • Useful for more complex logic flow gates (i.e., complicated if-then blocks)¬†
  • Refunds leftover gas

Assert

  • Used at the end of a function
  • Validates something that is impossible¬†
  • Critical for static code analysis tools¬†
  • Does not refund leftover gas

How to Learn More About Require and Solidity Error Handling

Developers interested in learning more about Solidity error handling should sign up for Alchemy University's free Solidity developer crash course. This FREE, 7-week bootcamp helps web2 developers and brand new coders learn how to write Solidity smart contracts. 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.

‚ÄćHow does error handling work in Solidity?¬†

Solidity uses state-reverting exceptions to handle errors, and such an exception will undo all changes made to the state in the current call and simultaneously flag an error to the caller. ‚Äć

Solidity, an object-oriented programming language to implement smart contracts on blockchains such as Ethereum, has numerous functions to address underlying issues that can occur at compile time or runtime. Even though syntax error checks happen at compile time, runtime errors are difficult to catch and mainly happen during the contract execution process. Some runtime error examples include a divide-by-zero type error, array-out-of-index error, and so on. 

In effect, error handling in Solidity ensures atomicity as a property. When a smart contract call terminates with an error, all the state changes (i.e., alterations made to variables, balances, etc.) are reverted, all the way up the chain of contract calls.

It is important to note that developers can directly interact with other contracts by declaring an interface. On the Ethereum blockchain, transactions are atomic, implying that transactions are either fully complete or have no effect on state and are reverted entirely. 

What are the three main Solidity error handling functions?

Error handling in Solidity is managed in principle by three special functions: assert, require, and revert. Until version 0.4.10, a single throw statement was available in Solidity.

Solidity has been designed to target the Ethereum Virtual Machine (EVM) and is influenced by C++, Javascript, and Python. Using Solidity, developers can create contracts for uses such as voting, crowdfunding, multi-signature wallets, and even blind auctions.

In practice, this means that a developer had to write several test functions in order to check underlying values and throw errors, which is not optimized for gas. In the release of Solidity version 0.4.10, new error handling constructs, asset, require, and revert, were introduced and the throw was made obsolete.

What is the require function?

The require function is used to verify inputs and conditions before execution. For instance, if the condition is false, then the require function immediately stops execution. In other words, require acts as a gate check modifier, preventing logic from accessing further execution of function and thereby producing an error. Require is ideal for logic flow gating and validating user inputs on functions.  

Require statements declare prerequisites for running the function, which should be satisfied prior to code execution. The require function accepts a single argument and after evaluation, require returns a boolean value of true or false. In the event that the execution is terminated due to a false condition, the unused gas is returned to the caller and the state is reversed to the original state. Customer string messages can also be added.

Here is an example of a require statement in Solidity:

The basic example demonstrates how to use the require statement. 

Require Statement Use Cases

For pragmatic reasons, developers could use require for the following scenarios:

  1. Validating responses from an external contract 
  2. Verify state conditions before final execution
  3. Authenticate user inputs 

What is the revert statement? 

‚ÄćRevert does not evaluate any condition and does not depend on any state or statement. The revert statement is similar to the require statement in that the revert function can handle the same error types as the require function, but it is more appropriate for complex logic gates.

If a revert statement is called, the unused gas is returned and the state reverts to its original state. The ability to add a custom message is the same as the require function. 

Here is an example of a revert statement in Solidity:

This basic example demonstrates a revert statement's custom message. 

What is the assert function? 

Assert is a function that is used to check for code that should never be false, and plays an important role in preventing impossible scenarios. If the assert function returns a boolean value of true, then a terminal bug will be displayed and the programs will not execute.

In contrast to the require and revert functions, assert does not return any unused gas and instead, the assert function will consume the gas supply before proceeding to reverse the program to its original state. Interestingly, prior to the Byzantium fork, both the require and assert functions behaved in an identical manner, however, compiled to distinct opcodes.

Assert Type Exceptions

  1. A value is modulo or divided by zero
  2. A zero-initialized variable of a function is called 
  3. A negative or large value is converted to an enum 
  4. Accessing an array within an index that is negative or larger than expected 
Assert statement example.

Assert Statement Use Cases

In theory, assert should be used less frequently compared to the require function. Developers should consider using the assert function for the following use cases: 

  • Validating the contract state after making changes¬†
  • Avoiding conditions which should never be possible¬†
  • Checking for overflow and underflow parameters¬†
  • Examining invariants

Require vs. Revert vs. Assert

Here is a summary that provides a succinct description of all all three Solidity error handling functions: require, revert, and assert.

Require

  • Used at the beginning of a function¬†
  • Validates against illegal input¬†
  • Verifies state conditions prior to execution
  • Refunds leftover gas¬†

Revert

  • Identical to require¬†
  • Useful for more complex logic flow gates (i.e., complicated if-then blocks)¬†
  • Refunds leftover gas

Assert

  • Used at the end of a function
  • Validates something that is impossible¬†
  • Critical for static code analysis tools¬†
  • Does not refund leftover gas

How to Learn More About Require and Solidity Error Handling

Developers interested in learning more about Solidity error handling should sign up for Alchemy University's free Solidity developer crash course. This FREE, 7-week bootcamp helps web2 developers and brand new coders learn how to write Solidity smart contracts. 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.

{{learn-solidity}}

Contact Us

Talk to an expert at Alchemy to answer all of your product questions.
Valid number
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Build blockchain magic with Alchemy

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

Get started for free