assert in solidity

assert is used to check the contract's code for errors and make sure code runs like it's supposed to. Usually by testing certain invariants (an invariant is a condition that should always be true at a certain stage in the code). These are the cases when…

require in solidity

require will check if a condition is true and allow code to flow only if condition is true. If the condition is false, require will throw an error, the rest of the code will not be executed and the transaction will revert. The first param of require call is the…

View vs Pure in Solidity

pure function cannot read from state or write to state. In functional programming terminology, it is a function that does not have any side-effects. // pure function cannot read from state or write to state function alwaysOne() public pure returns(int) { return 1; } view function can read from state, but can…

Structs in Solidity

Struct is user-defined/custom data type where you can define some arbitrary object with some properties. You can't return the struct directly, but can return a tuple of its properties. // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.4; contract HelloWorld { // struct is user-defined/custom data type where you…

Using useReducer React Hook

The useReducer hook allows you to use a reducer for state management in your application. A reducer, of course, is simply a pure function that takes an action and state, and returns a copy of that state after applying the action on that state.…

Using useEffect Hook In React

The useEffect hook behaves similar to componentDidMount, componentDidUpdate, and componentWillUnmount lifecycle hooks combined. It allows you to perform any (side)effects, such as API calls, without blocking the UI render.…