Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

Using assert(), require(), and revert() properly

In Solidity, three functions are provided by the language to check for the invariant, validations, and to fail the transaction. These functions are as follows:

  • assert(): The assert() function should be used when you want to check for invariants in the code. When any invariant is incorrect, the code execution stops, transaction fails, and contract state changes are reverted. This function should only be used for invariant checking. It should not be used for input validation or pre-condition checking.
  • require(): The require() function should be used when you want to validate the arguments provided to the function. It is also used to check for the valid conditions and variable values to be in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content