Function Visibility in Solidity
There are four types of function visibility in Solidity: external, internal, private, and public.…
There are four types of function visibility in Solidity: external, internal, private, and public.…
Assigning storage to memory is by value, i.e., value is copied over.Assigning memory to storage is also by value, i.e., value is copied over.…
modifier is used to declare some code that will be re-used throughout the contract. Write once, use everywhere. For example, instead of doing the require check on owner, declare this modifier: modifier onlyOwner { require(msg.sender == owner, "Only contract owner can do this"); _; // run the function } and can…
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 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…
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…
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…